diff options
| author | Stephen Blott | 2016-04-17 11:54:28 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-17 11:54:28 +0100 |
| commit | 5c3e4bda2968486e23f8cc3410e776de67fec849 (patch) | |
| tree | 38743486ac59f76462d6d6da9c8c90038c467834 | |
| parent | d43f18bd5ce7c39e8e663a657027b233707e2926 (diff) | |
| download | vimium-5c3e4bda2968486e23f8cc3410e776de67fec849.tar.bz2 | |
Better window focus handling.
This fixes two issues:
- We cannot set windowHasFocus until the DOM is ready (because
document.hasFocus isn't set until then.
- We should use windowhasFocus in prefernce to document.hasFocus
because, for framesets, document.hasFocus is true for both the
frameset and a focused contained frame.
| -rw-r--r-- | content_scripts/link_hints.coffee | 6 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 3 |
2 files changed, 5 insertions, 4 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index f2b9cd0f..702ff69d 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -334,7 +334,7 @@ class LinkHintsMode flashEl = DomUtils.addFlashRect linkMatched.rect HintCoordinator.onExit.push -> DomUtils.removeElement flashEl - if document.hasFocus() + if windowIsFocused() startKeyboardBlocker (isSuccess) -> HintCoordinator.sendMessage "exit", {isSuccess} # If we're using a keyboard blocker, then the frame with the focus sends the "exit" message, otherwise the @@ -613,12 +613,12 @@ LocalHints = isClickable ||= element.control? and (@getVisibleClickable element.control).length == 0 when "body" isClickable ||= - if element == document.body and not document.hasFocus() and + if element == document.body and not windowIsFocused() and window.innerWidth > 3 and window.innerHeight > 3 and document.body?.tagName.toLowerCase() != "frameset" reason = "Frame." isClickable ||= - if element == document.body and document.hasFocus() and Scroller.isScrollableElement element + if element == document.body and windowIsFocused() and Scroller.isScrollableElement element reason = "Scroll." when "div", "ol", "ul" isClickable ||= diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 7d6fa9a0..39e8e5d8 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -8,7 +8,8 @@ normalMode = null # We track whther the current window has the focus or not. windowIsFocused = do -> - windowHasFocus = document.hasFocus() + windowHasFocus = null + DomUtils.documentReady -> windowHasFocus = document.hasFocus() window.addEventListener "focus", (event) -> windowHasFocus = true if event.target == window; true window.addEventListener "blur", (event) -> windowHasFocus = false if event.target == window; true -> windowHasFocus |
