aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-03-27 12:20:39 +0100
committerStephen Blott2016-03-27 12:20:43 +0100
commit9c96f750f7c2d22eb0098dcb05b34c51c802e8ac (patch)
tree712e74a7d92ff94d9b5bbb8a309c1dd1ee60e647
parentf0911e52f0e71c6d2539bdc74a09ff2dbd5ab125 (diff)
downloadvimium-9c96f750f7c2d22eb0098dcb05b34c51c802e8ac.tar.bz2
Handle focus events for UI components.
The help-dialog UI component was ignoring requests to "hide" when other frames are focused (because previously it covered the whole screen, and no other frame could get the focus). With f0911e52f0e71c6d2539bdc74a09ff2dbd5ab125, the help dialog no longer covers the whole screen, so it must listen for and react to "frameFocused" events. However, the help dialog should not "hide" when the frame that is focused is itself! This required a little extra plumbing. That plumbing is helpful, though, because it allows individual UI components to decide what to do when another frame receives the focus (as opposed to the previious version, which simply unilaterally sent a "hide" message).
-rw-r--r--content_scripts/ui_component.coffee6
-rw-r--r--pages/help_dialog.coffee11
-rw-r--r--pages/vomnibar.coffee3
3 files changed, 12 insertions, 8 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee
index d381cb0f..ac0bea71 100644
--- a/content_scripts/ui_component.coffee
+++ b/content_scripts/ui_component.coffee
@@ -48,11 +48,9 @@ class UIComponent
@iframeElement.contentWindow.postMessage vimiumSecret, chrome.runtime.getURL(""), [ port2 ]
setIframePort port1
- # If any other frame in the current tab receives the focus, then we hide the UI component.
- # NOTE(smblott) This is correct for the vomnibar, but might be incorrect (and need to be revisited) for
- # other UI components.
chrome.runtime.onMessage.addListener (request) =>
- @postMessage "hide" if @showing and request.name == "frameFocused" and request.focusFrameId != frameId
+ if @showing and request.name == "frameFocused" and request.focusFrameId != frameId
+ @postMessage name: "frameFocused", focusFrameId: request.focusFrameId
false # Free up the sendResponse handler.
# Posts a message (if one is provided), then calls continuation (if provided). The continuation is only
diff --git a/pages/help_dialog.coffee b/pages/help_dialog.coffee
index 997ea915..f12b19a3 100644
--- a/pages/help_dialog.coffee
+++ b/pages/help_dialog.coffee
@@ -84,9 +84,14 @@ HelpDialog =
HelpDialog.dialogElement.classList[addOrRemove] "showAdvanced"
UIComponentServer.registerHandler (event) ->
- return if event.data == "hide"
- HelpDialog.init()
- HelpDialog.show event.data
+ switch event.data.name ? event.data
+ when "frameFocused"
+ HelpDialog.hide() unless event.data.focusFrameId == frameId
+ when "hide"
+ HelpDialog.hide()
+ else
+ HelpDialog.init()
+ HelpDialog.show event.data
root = exports ? window
root.HelpDialog = HelpDialog
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 67fca64c..0332b12f 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -330,7 +330,8 @@ class BackgroundCompleter
chrome.runtime.sendMessage handler: "selectSpecificTab", id: tabId
UIComponentServer.registerHandler (event) ->
- switch event.data
+ switch event.data.name ? event.data
+ when "frameFocused" then Vomnibar.hide()
when "hide" then Vomnibar.hide()
when "hidden" then Vomnibar.onHidden()
else Vomnibar.activate event.data