From bfa6c88b41acac4c98d06f324f25f8bb7b328614 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 23 Apr 2015 11:07:36 +0100 Subject: 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. --- content_scripts/ui_component.coffee | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'content_scripts/ui_component.coffee') 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 -- cgit v1.2.3