aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Crosby2009-11-28 18:24:40 -0800
committerPhil Crosby2009-11-29 01:16:23 -0800
commitf0ce5c20ea18f138fde0962cedd378fce939d0a6 (patch)
treec49526ca53bb652f58d081084c8676b00d7dd375
parent6f07ef6f3261ce362b68940489d5e18775034f87 (diff)
downloadvimium-f0ce5c20ea18f138fde0962cedd378fce939d0a6.tar.bz2
When shwoing hints, handle links which have nested elements, like <em> (google search results) and <img>
-rw-r--r--linkHints.js16
1 files changed, 15 insertions, 1 deletions
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);
@@ -85,6 +85,20 @@ function getVisibleClickableElements() {
}
/*
+ * Checks whether the clickable element or one of its descendents is at the given point. We must check
+ * descendents because some clickable elements like "<a>" 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.
*/