From f0ce5c20ea18f138fde0962cedd378fce939d0a6 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sat, 28 Nov 2009 18:24:40 -0800 Subject: When shwoing hints, handle links which have nested elements, like (google search results) and --- linkHints.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'linkHints.js') diff --git a/linkHints.js b/linkHints.js index 82ffb1fd..3f261d36 100644 --- a/linkHints.js +++ b/linkHints.js @@ -76,7 +76,7 @@ function getVisibleClickableElements() { // Using getElementFromPoint will omit elements which have visibility=hidden or display=none, and // elements inside of containers that are also hidden. - if (element != getElementFromPoint(boundingRect.left, boundingRect.top)) + if (!elementOccupiesPoint(element, boundingRect.left, boundingRect.top)) continue; visibleElements.push(element); @@ -84,6 +84,20 @@ function getVisibleClickableElements() { return visibleElements; } +/* + * Checks whether the clickable element or one of its descendents is at the given point. We must check + * descendents because some clickable elements like "" can have many nested children. + */ +function elementOccupiesPoint(clickableElement, x, y) { + var elementAtPoint = getElementFromPoint(x, y); + // Recurse up to 5 parents. + for (var i = 0; i < 5 && elementAtPoint; i++) { + if (elementAtPoint == clickableElement) + return true; + elementAtPoint = elementAtPoint.parentNode; + } + return false; +} /* * Returns the element at the given point and factors in the page's CSS zoom level, which Webkit neglects * to do. This should become unnecessary when webkit fixes their bug. -- cgit v1.2.3