diff options
| author | Stephen Blott | 2016-02-28 10:35:11 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-02-28 10:35:11 +0000 |
| commit | bfe91c609ef9886cfeb5d45bfa1557a9d00faeb2 (patch) | |
| tree | 62dba27504c0084071b239142b225a63193c1231 | |
| parent | 8adfa7c4ef8357b6cb945354d6da1b7b92615119 (diff) | |
| download | vimium-bfe91c609ef9886cfeb5d45bfa1557a9d00faeb2.tar.bz2 | |
Refactor focusFrame.
Only the `flashFrame` part needs to be guarded against the DOM being
ready. So we can take the `flashFrame` part out as a regular function.
Fixes #2023 (although I don't fully understand why that's happening).
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 4cebf4e4..c45e6c4e 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -269,9 +269,7 @@ setScrollPosition = ({ scrollX, scrollY }) -> Marks.setPreviousPosition() window.scrollTo scrollX, scrollY -# -# Called from the backend in order to change frame focus. -# +flashFrame = -> DomUtils.documentReady -> # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. highlightedFrameElement = DomUtils.createElement "div" @@ -287,21 +285,24 @@ DomUtils.documentReady -> _frameEl.className = "vimiumReset vimiumHighlightedFrame" _shadowDOM.appendChild _frameEl - window.focusThisFrame = (request) -> - if window.innerWidth < 3 or window.innerHeight < 3 - # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead. - # This affects sites like Google Inbox, which have many tiny iframes. See #1317. - # Here we're assuming that there is at least one frame large enough to focus. - chrome.runtime.sendMessage({ handler: "nextFrame", frameId: frameId }) - return - window.focus() - shouldHighlight = request.highlight - shouldHighlight ||= request.highlightOnlyIfNotTop and not DomUtils.isTopFrame() - if shouldHighlight - document.documentElement.appendChild highlightedFrameElement - setTimeout (-> highlightedFrameElement.remove()), 200 - -window.focusThisFrame = -> + flashFrame = -> + document.documentElement.appendChild highlightedFrameElement + setTimeout (-> highlightedFrameElement.remove()), 200 + +# +# Called from the backend in order to change frame focus. +# +focusThisFrame = (request) -> + if window.innerWidth < 3 or window.innerHeight < 3 + # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead. + # This affects sites like Google Inbox, which have many tiny iframes. See #1317. + # Here we're assuming that there is at least one frame large enough to focus. + chrome.runtime.sendMessage({ handler: "nextFrame", frameId: frameId }) + return + window.focus() + shouldHighlight = request.highlight + shouldHighlight ||= request.highlightOnlyIfNotTop and not DomUtils.isTopFrame() + flashFrame() if shouldHighlight extend window, scrollToBottom: -> |
