diff options
| author | Stephen Blott | 2015-03-17 11:42:58 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-03-17 11:42:58 +0000 | 
| commit | 8bc811aae1118e28faa7c17e67b039c67f637274 (patch) | |
| tree | 702f28f1d88fef438a717895ede5107409df54be | |
| parent | 9461d30b0d19fd65dc43e18bebec1fe0fd3ee818 (diff) | |
| download | vimium-8bc811aae1118e28faa7c17e67b039c67f637274.tar.bz2 | |
Activate vomnibar in window.top; hide on focus, fixed.
| -rw-r--r-- | background_scripts/main.coffee | 5 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 14 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 20 | 
3 files changed, 30 insertions, 9 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 0b19ce4a..07e89e08 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -666,6 +666,10 @@ handleFrameFocused = (request, sender) ->  sendMessageToFrames = (request, sender) ->    chrome.tabs.sendMessage sender.tab.id, request.message +# For debugging only. This allows content scripts to log messages to the background page's console. +bgLog = (request, sender) -> +  console.log "#{sender.tab.id}/#{request.frameId}", request.message +  # Port handler mapping  portHandlers =    keyDown: handleKeyDown, @@ -694,6 +698,7 @@ sendRequestHandlers =    gotoMark: Marks.goto.bind(Marks)    setBadge: setBadge    sendMessageToFrames: sendMessageToFrames +  log: bgLog  # We always remove chrome.storage.local/findModeRawQueryListIncognito on startup.  chrome.storage.local.remove "findModeRawQueryListIncognito" diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 64dddf67..3d8cef29 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -15,9 +15,9 @@ class UIComponent      # Hide the iframe, but don't interfere with the focus.      @hide false -    # If any frame in the current tab receives the focus, then we hide the vomnibar. +    # If any other frame in the current tab receives the focus, then we hide the vomnibar.      chrome.runtime.onMessage.addListener (request) => -      @hide false if @showing and request.name == "frameFocused" +      @hide false if @showing and request.name == "frameFocused" and request.frameId != frameId        false # Free up response handler.    # Open a port and pass it to the iframe via window.postMessage. @@ -42,11 +42,21 @@ class UIComponent      @postMessage message if message?      @iframeElement.classList.remove "vimiumUIComponentHidden"      @iframeElement.classList.add "vimiumUIComponentShowing" +    # The window may not have the focus.  We focus it now, to prevent the "focus" listener below from firing +    # immediately. +    window.focus() +    window.addEventListener "focus", @onFocus = (event) => +      if event.target == window +        window.removeEventListener "focus", @onFocus +        @onFocus = null +        @postMessage "hide"      @showing = true    hide: (focusWindow = true)->      @iframeElement.classList.remove "vimiumUIComponentShowing"      @iframeElement.classList.add "vimiumUIComponentHidden" +    window.removeEventListener "focus", @onFocus if @onFocus +    @onFocus = null      if focusWindow and @options?.frameId?        chrome.runtime.sendMessage          handler: "sendMessageToFrames" diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 941b2bc2..90b25a40 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -94,7 +94,12 @@ settings =  #  # Give this frame a unique id.  # -frameId = Math.floor(Math.random()*999999999) +window.frameId = Math.floor(Math.random()*999999999) + +# For debugging only. This logs to the console on the background page. +window.bgLog = (args...) -> +  args = (arg.toString() for arg in args) +  chrome.runtime.sendMessage handler: "log", frameId: frameId, message: args.join " "  # If an input grabs the focus before the user has interacted with the page, then grab it back (if the  # grabBackFocus option is set). @@ -230,12 +235,13 @@ getActiveState = ->  #  # The backend needs to know which frame has focus.  # -registerFocus = -> -  # settings may have changed since the frame last had focus -  settings.load() -  # Don't register frameset containers; focusing them is no use. -  unless document.body?.tagName.toLowerCase() == "frameset" -    chrome.runtime.sendMessage({ handler: "frameFocused", frameId: frameId }) +registerFocus = (event) -> +  if event.target == window +    # settings may have changed since the frame last had focus +    settings.load() +    # Don't register frameset containers; focusing them is no use. +    unless document.body?.tagName.toLowerCase() == "frameset" +      chrome.runtime.sendMessage({ handler: "frameFocused", frameId: frameId })  #  # Initialization tasks that must wait for the document to be ready. | 
