diff options
| author | Stephen Blott | 2015-04-23 11:07:36 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-04-23 11:07:36 +0100 |
| commit | bfa6c88b41acac4c98d06f324f25f8bb7b328614 (patch) | |
| tree | c624300290dfa3d9506e40e17a2b8fddf5f2c407 /content_scripts/ui_component.coffee | |
| parent | 9eaa7330b1e4952e171cf53db855cf447c8e1e49 (diff) | |
| download | vimium-bfa6c88b41acac4c98d06f324f25f8bb7b328614.tar.bz2 | |
Activate vomnibar in window.top; no flicker and tidy up.
1. Rework event handling to eliminate frame flicker (a la #1485).
2. Tidy up logic. Which should make this more robust.
Diffstat (limited to 'content_scripts/ui_component.coffee')
| -rw-r--r-- | content_scripts/ui_component.coffee | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index ee74c3a8..ea0bf776 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -55,7 +55,7 @@ class UIComponent @showing = true hide: (focusWindow = true)-> - @refocusSourceFrame @options?.sourceFrameId if focusWindow and @options?.sourceFrameId? + @refocusSourceFrame @options?.sourceFrameId if focusWindow window.removeEventListener "focus", @onFocus if @onFocus @onFocus = null @iframeElement.classList.remove "vimiumUIComponentShowing" @@ -63,14 +63,13 @@ class UIComponent @options = null @showing = false - # Refocus the frame from which the UI component was opened. + # Refocus the frame from which the UI component was opened. This may be different from the current frame. # After hiding the UI component, Chrome refocuses the containing frame. To avoid a race condition, we need - # to wait until that frame receives the focus, before then focusing the frame which should now have the - # focus. + # to wait until that frame first receives the focus, before then focusing the frame which should now have + # the focus. refocusSourceFrame: (sourceFrameId) -> - window.addEventListener "focus", handler = (event) -> - if event.target == window - window.removeEventListener "focus", handler + if @showing and sourceFrameId? and sourceFrameId != frameId + refocusSourceFrame = -> chrome.runtime.sendMessage handler: "sendMessageToFrames" message: @@ -79,5 +78,15 @@ class UIComponent highlight: false highlightOnlyIfNotTop: true + if windowIsFocused() and false + # We already have the focus. + refocusSourceFrame() + else + # We don't yet have the focus (but we'll be getting it soon). + window.addEventListener "focus", handler = (event) -> + if event.target == window + window.removeEventListener "focus", handler + refocusSourceFrame() + root = exports ? window root.UIComponent = UIComponent |
