From f60ea7637961c3525ae2dbb5bbcecfcc434a6fb7 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 19 Dec 2008 14:57:34 -0500 Subject: [PATCH] Make sure that the hint number is in the viewport --- common/content/events.js | 81 ++++++++++++++++++++-------------------- common/content/hints.js | 4 +- common/content/util.js | 9 +++++ 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/common/content/events.js b/common/content/events.js index 3009eee6..c1432bbe 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -1201,52 +1201,51 @@ function Events() //{{{ // global escape handler, is called in ALL modes onEscape: function () { - if (!modes.passNextKey) + if (modes.passNextKey) + return; + if (modes.passAllKeys) { - if (modes.passAllKeys) - { - modes.passAllKeys = false; - return; - } + modes.passAllKeys = false; + return; + } - switch (liberator.mode) - { - case modes.NORMAL: - // clear any selection made - let selection = window.content.getSelection(); - try - { // a simple if (selection) does not seem to work - selection.collapseToStart(); - } - catch (e) {} + switch (liberator.mode) + { + case modes.NORMAL: + // clear any selection made + let selection = window.content.getSelection(); + try + { // a simple if (selection) does not seem to work + selection.collapseToStart(); + } + catch (e) {} + modes.reset(); + break; + + case modes.VISUAL: + if (modes.extended & modes.TEXTAREA) + liberator.mode = modes.TEXTAREA; + else if (modes.extended & modes.CARET) + liberator.mode = modes.CARET; + break; + + case modes.CARET: + // setting this option will trigger an observer which will + // care about all other details like setting the NORMAL mode + options.setPref("accessibility.browsewithcaret", false); + break; + + case modes.INSERT: + if ((modes.extended & modes.TEXTAREA) && !options["insertmode"]) + liberator.mode = modes.TEXTAREA; + else modes.reset(); - break; + break; - case modes.VISUAL: - if (modes.extended & modes.TEXTAREA) - liberator.mode = modes.TEXTAREA; - else if (modes.extended & modes.CARET) - liberator.mode = modes.CARET; - break; - - case modes.CARET: - // setting this option will trigger an observer which will - // care about all other details like setting the NORMAL mode - options.setPref("accessibility.browsewithcaret", false); - break; - - case modes.INSERT: - if ((modes.extended & modes.TEXTAREA) && !options["insertmode"]) - liberator.mode = modes.TEXTAREA; - else - modes.reset(); - break; - - default: // HINTS, CUSTOM or COMMAND_LINE - modes.reset(); - break; - } + default: // HINTS, CUSTOM or COMMAND_LINE + modes.reset(); + break; } }, diff --git a/common/content/hints.js b/common/content/hints.js index 38f36436..511e1894 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -154,8 +154,8 @@ function Hints() //{{{ text = elem.textContent.toLowerCase(); span = baseNodeAbsolute.cloneNode(true); - span.style.left = (rect.left + scrollX) + "px"; - span.style.top = (rect.top + scrollY) + "px"; + span.style.left = Math.max((rect.left + scrollX), scrollX) + "px"; + span.style.top = Math.max((rect.top + scrollY), scrollY) + "px"; fragment.appendChild(span); pageHints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color]); diff --git a/common/content/util.js b/common/content/util.js index 3d3995f4..cf5bdcb3 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -311,6 +311,15 @@ const util = { //{{{ identity: function identity(k) k, + intersection: function (r1, r2) ({ + get width() this.right - this.left, + get height() this.bottom - this.top, + left: Math.max(r1.left, r2.left), + right: Math.min(r1.right, r2.right), + top: Math.max(r1.top, r2.top), + bottom: Math.min(r1.bottom, r2.bottom) + }), + map: function map(obj, fn) { let ary = [];