aboutsummaryrefslogtreecommitdiffstats
path: root/linkHints.js
diff options
context:
space:
mode:
authorJez Ng2012-01-14 04:38:50 +0800
committerJez Ng2012-01-15 14:48:11 +0800
commit4ca60a80f0e3d5c4818d05417c869bde6340d792 (patch)
tree00907902cdcade26e5dc7f422f3b21f9cd1f6fc7 /linkHints.js
parente84617a1512dbfdba685c3dccf5f82ae0ddc60e8 (diff)
downloadvimium-4ca60a80f0e3d5c4818d05417c869bde6340d792.tar.bz2
Scroll the body element if last activated node is not visible.
Diffstat (limited to 'linkHints.js')
-rw-r--r--linkHints.js48
1 files changed, 1 insertions, 47 deletions
diff --git a/linkHints.js b/linkHints.js
index fb59124a..0181436b 100644
--- a/linkHints.js
+++ b/linkHints.js
@@ -120,7 +120,7 @@ var linkHints = {
// Find all visible clickable elements.
for (var i = 0, count = resultSet.snapshotLength; i < count; i++) {
var element = resultSet.snapshotItem(i);
- var clientRect = this.getVisibleClientRect(element, clientRect);
+ var clientRect = utils.getVisibleClientRect(element, clientRect);
if (clientRect !== null)
visibleElements.push({element: element, rect: clientRect});
@@ -145,52 +145,6 @@ var linkHints = {
return visibleElements;
},
- /**
- * Returns the first visible clientRect of an element if it exists. Otherwise it returns null.
- */
- getVisibleClientRect: function(element) {
- // Note: this call will be expensive if we modify the DOM in between calls.
- var clientRects = element.getClientRects();
- var clientRectsLength = clientRects.length;
-
- for (var i = 0; i < clientRectsLength; i++) {
- // Exclude links which have just a few pixels on screen, because the link hints won't show for them
- // anyway.
- if (clientRects[i].top < 0 || clientRects[i].top >= window.innerHeight - 4 ||
- clientRects[i].left < 0 || clientRects[i].left >= window.innerWidth - 4)
- continue;
-
- if (clientRects[i].width < 3 || clientRects[i].height < 3)
- continue;
-
- // eliminate invisible elements (see test_harnesses/visibility_test.html)
- var computedStyle = window.getComputedStyle(element, null);
- if (computedStyle.getPropertyValue('visibility') != 'visible' ||
- computedStyle.getPropertyValue('display') == 'none')
- continue;
-
- return clientRects[i];
- }
-
- for (var i = 0; i < clientRectsLength; i++) {
- // If the link has zero dimensions, it may be wrapping visible
- // but floated elements. Check for this.
- if (clientRects[i].width == 0 || clientRects[i].height == 0) {
- for (var j = 0, childrenCount = element.children.length; j < childrenCount; j++) {
- var computedStyle = window.getComputedStyle(element.children[j], null);
- // Ignore child elements which are not floated and not absolutely positioned for parent elements with zero width/height
- if (computedStyle.getPropertyValue('float') == 'none' && computedStyle.getPropertyValue('position') != 'absolute')
- continue;
- var childClientRect = this.getVisibleClientRect(element.children[j]);
- if (childClientRect === null)
- continue;
- return childClientRect;
- }
- }
- };
- return null;
- },
-
/*
* Handles shift and esc keys. The other keys are passed to markerMatcher.matchHintsByKey.
*/