diff options
| author | Stephen Blott | 2016-04-15 16:51:18 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-04-16 14:15:33 +0100 | 
| commit | 5bfe6dc5d1e0aeb1ab3e372821997d83ba5c9164 (patch) | |
| tree | 174c58b552cc0b869764d2dd28f14bb3f010ef2c /content_scripts/vimium_frontend.coffee | |
| parent | 014f53fb091ac8672d3efbeca13a494c15d8afcb (diff) | |
| download | vimium-5bfe6dc5d1e0aeb1ab3e372821997d83ba5c9164.tar.bz2 | |
Rework UI component focus handling.
The code to handle the focus for UI components has been tweaked and
adapted over time, and has become quite complicated (and brittle).  This
reworks it from scratch, and co-locates similar code which does related
things.
Fixes #2099.
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 36 | 
1 files changed, 13 insertions, 23 deletions
| diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 4dcdfe7d..537dbaa9 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -119,7 +119,10 @@ class NormalMode extends KeyHandlerMode          You have asked Vimium to perform #{count} repetitions of the command: #{registryEntry.description}.\n          Are you sure you want to continue?""" -    if registryEntry.topFrame +    if registryEntry.topFrame and window.isVimiumUIComponent? and window.isVimiumUIComponent +      # We cannot use "topFrame" commands, most notably the Vomnibar, from within a UI component. +      HUD.showForDuration "#{registryEntry.command} cannot be used here.", 2000 +    else if registryEntry.topFrame        chrome.runtime.sendMessage          handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId: frameId, registryEntry}      else if registryEntry.background @@ -156,7 +159,7 @@ initializePreDomReady = ->      getScrollPosition: (ignoredA, ignoredB, sendResponse) ->        sendResponse scrollX: window.scrollX, scrollY: window.scrollY if frameId == 0      setScrollPosition: setScrollPosition -    # A frame has received the focus.  We don't care here (the Vomnibar/UI-component handles this). +    # A frame has received the focus.  We don't care here (UI components handle this).      frameFocused: ->      checkEnabledAfterURLChange: checkEnabledAfterURLChange      runInTopFrame: ({sourceFrameId, registryEntry}) -> @@ -626,29 +629,16 @@ enterFindMode = ->  # If we are in the help dialog iframe, HelpDialog is already defined with the necessary functions.  window.HelpDialog ?=    helpUI: null -  container: null -  showing: false - -  init: -> -    return if @helpUI? - -    @helpUI = new UIComponent "pages/help_dialog.html", "vimiumHelpDialogFrame", (event) => -      @hide() if event.data == "hide" - -  isReady: -> @helpUI - -  show: (html) -> -    @init() -    return if @showing or !@isReady() -    @showing = true -    @helpUI.activate html - -  hide: -> -    @showing = false -    @helpUI.hide() +  isShowing: -> @helpUI?.showing    toggle: (html) -> -    if @showing then @hide() else @show html +    @helpUI ?= new UIComponent "pages/help_dialog.html", "vimiumHelpDialogFrame", -> +    if @isShowing() +      @helpUI.hide() +    else +      # On the options page, we allow the help dialog to lose the focus, elsewhere we do not.  This allows +      # users to view the help dialog while typing in the key-mappings input. +      @helpUI.activate {name: "activate", html, focus: true, allowBlur: window.isVimiumOptionsPage ? false}  initializePreDomReady()  DomUtils.documentReady initializeOnDomReady | 
