From 8099d5d57f885517c4d5e04cdcc74c91980a75fb Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 5 Mar 2015 15:14:01 +0000 Subject: Hide vomnibar if host frame regains focus. Fixes #1506. This takes the opposite approach to #1511. Instead of hiding the vomnibar when it blurs, we hide it when it's host frame is focused. --- content_scripts/ui_component.coffee | 15 ++++++++------- pages/vomnibar.coffee | 5 ++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index c4ed3bf6..c6b59464 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -29,24 +29,25 @@ class UIComponent activate: (message) -> @postMessage message if message? - if @showing - # NOTE(smblott) Experimental. Not sure this is a great idea. If the iframe was already showing, then - # the user gets no visual feedback when it is re-focused. So flash its border. - @iframeElement.classList.add "vimiumUIComponentReactivated" - setTimeout((=> @iframeElement.classList.remove "vimiumUIComponentReactivated"), 200) - else - @show() + @show() unless @showing @iframeElement.focus() show: (message) -> @postMessage message if message? @iframeElement.classList.remove "vimiumUIComponentHidden" @iframeElement.classList.add "vimiumUIComponentShowing" + window.addEventListener "focus", @onFocus = (event) => + if event.target == window + window.removeEventListener @onFocus + @onFocus = null + @postMessage "hide" @showing = true hide: (focusWindow = true)-> @iframeElement.classList.remove "vimiumUIComponentShowing" @iframeElement.classList.add "vimiumUIComponentHidden" + window.removeEventListener @onFocus if @onFocus + @onFocus = null window.focus() if focusWindow @showing = false diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 18a72a37..255dd893 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -38,6 +38,8 @@ Vomnibar = @vomnibarUI.setQuery(options.query) @vomnibarUI.update() + hide: -> @vomnibarUI?.hide() + class VomnibarUI constructor: -> @refreshInterval = 0 @@ -225,7 +227,8 @@ extend BackgroundCompleter, switchToTab: (tabId) -> chrome.runtime.sendMessage({ handler: "selectSpecificTab", id: tabId }) -UIComponentServer.registerHandler (event) -> Vomnibar.activate event.data +UIComponentServer.registerHandler (event) -> + if event.data == "hide" then Vomnibar.hide() else Vomnibar.activate event.data root = exports ? window root.Vomnibar = Vomnibar -- cgit v1.2.3 From bc7a12dc74eaea06bcad23d89fb81643bd8b1625 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 5 Mar 2015 15:43:11 +0000 Subject: Fix various vomnibar clicks... Click: - in the vomnibar focuses the input - anywhere else (such as in the space below the vomnibar) hides the vomnibar. This makes clicks in the space below the vomnibar behave the same as clicks in the page itself... Which makes sense, because the difference is not apparent to the user. --- pages/vomnibar.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index 255dd893..d0b7a7dd 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -182,6 +182,12 @@ class VomnibarUI @completionList.style.display = "" window.addEventListener "focus", => @input.focus() + # A click in the vomnibar itself refocuses the input. + @box.addEventListener "click", (event) => + @input.focus() + event.stopImmediatePropagation() + # A click anywhere else hides the vomnibar. + document.body.addEventListener "click", => @hide() # # Sends filter and refresh requests to a Vomnibox completer on the background page. -- cgit v1.2.3