aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/ui_component.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-04-23 11:07:36 +0100
committerStephen Blott2015-04-23 11:07:36 +0100
commitbfa6c88b41acac4c98d06f324f25f8bb7b328614 (patch)
treec624300290dfa3d9506e40e17a2b8fddf5f2c407 /content_scripts/ui_component.coffee
parent9eaa7330b1e4952e171cf53db855cf447c8e1e49 (diff)
downloadvimium-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.coffee23
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