From 10982f57bbbbe802ecc59173ce8a60582f8b34ff Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 14:12:46 +0100 Subject: Make showHelp not a background command. --- content_scripts/vimium_frontend.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 92145303..9f7d9d52 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -155,7 +155,6 @@ initializePreDomReady = -> checkIfEnabledForUrl document.hasFocus() requestHandlers = - toggleHelpDialog: (request) -> if frameId == request.frameId then HelpDialog.toggle request.dialogHtml focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame request getScrollPosition: (ignoredA, ignoredB, sendResponse) -> sendResponse scrollX: window.scrollX, scrollY: window.scrollY if frameId == 0 @@ -626,6 +625,9 @@ enterFindMode = -> Marks.setPreviousPosition() new FindMode() +window.showHelp = -> + chrome.runtime.sendMessage handler: "getHelpDialogHtml", HelpDialog.toggle.bind HelpDialog + # If we are in the help dialog iframe, HelpDialog is already defined with the necessary functions. window.HelpDialog ?= helpUI: null -- cgit v1.2.3 From 12350784fc45998819ef92d6b5badf03e99128ae Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 15:02:25 +0100 Subject: Make showHelp a top-frame command. Replaces #2037. --- content_scripts/vimium_frontend.coffee | 20 +++++++++++--------- content_scripts/vomnibar.coffee | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 9f7d9d52..f20bba7e 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -121,9 +121,8 @@ class NormalMode extends KeyHandlerMode Are you sure you want to continue?""" if registryEntry.topFrame - # The Vomnibar (a top-frame command) cannot coexist with the help dialog (it causes focus issues). + # We never return to a UI-component frame (e.g. the help dialog), it might have lost the focus. sourceFrameId = if window.isVimiumUIComponent then 0 else frameId - HelpDialog.toggle() if HelpDialog.isShowing() chrome.runtime.sendMessage handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId, registryEntry} else if registryEntry.background @@ -625,22 +624,25 @@ enterFindMode = -> Marks.setPreviousPosition() new FindMode() -window.showHelp = -> - chrome.runtime.sendMessage handler: "getHelpDialogHtml", HelpDialog.toggle.bind HelpDialog +window.showHelp = (sourceFrameId) -> + chrome.runtime.sendMessage handler: "getHelpDialogHtml", (response) -> + HelpDialog.toggle {sourceFrameId, html: response} -# If we are in the help dialog iframe, HelpDialog is already defined with the necessary functions. +# If we are in the help dialog iframe, then HelpDialog is already defined with the necessary functions. window.HelpDialog ?= helpUI: null isShowing: -> @helpUI?.showing + abort: -> @helpUI.hide false if @isShowing() - toggle: (html) -> + toggle: (request) -> @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} + # On the options page, we allow the help dialog to blur, elsewhere we do not. This allows users to view + # the help dialog while typing in the key-mappings input. + @helpUI.activate extend request, + name: "activate", focus: true, allowBlur: window.isVimiumOptionsPage ? false initializePreDomReady() DomUtils.documentReady initializeOnDomReady diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 02ce97c5..66494fc2 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -59,6 +59,8 @@ Vomnibar = open: (sourceFrameId, options) -> @init() if @vomnibarUI?.uiComponentIsReady + # The Vomnibar cannot coexist with the help dialog (it causes focus issues). + HelpDialog.abort() @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } root = exports ? window -- cgit v1.2.3 From 5327d51946fa86ed494c7b5cd2ba39fb79d8e9e9 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 16:11:57 +0100 Subject: Do not init() the HUD until it's needed. This avoids initializing around 15 (almost all unused) HUDs on sites like GMail and Google inbox. Because the HUD is small, there is not noticable flicker. --- content_scripts/hud.coffee | 8 +++----- content_scripts/mode.coffee | 3 +-- content_scripts/vimium_frontend.coffee | 3 +-- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 0bd1df3e..62bcf03f 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -23,13 +23,13 @@ HUD = @_showForDurationTimerId = setTimeout((=> @hide()), duration) show: (text) -> - return unless @isReady() + @init() clearTimeout(@_showForDurationTimerId) @hudUI.activate {name: "show", text} @tween.fade 1.0, 150 showFindMode: (@findMode = null) -> - return unless @isReady() + @init() @hudUI.activate name: "showFindMode" @tween.fade 1.0, 150 @@ -46,7 +46,7 @@ HUD = # If :updateIndicator is truthy, then we also refresh the mode indicator. The only time we don't update the # mode indicator, is when hide() is called for the mode indicator itself. hide: (immediate = false, updateIndicator = true) -> - return unless @tween? and @isReady() + return unless @hudUI?.uiComponentIsReady clearTimeout(@_showForDurationTimerId) @tween.stop() if immediate @@ -80,8 +80,6 @@ HUD = @findMode.exit() postExit?() - isReady: -> @hudUI?.uiComponentIsReady - class Tween opacity: 0 intervalId: -1 diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 37321660..6508627e 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -69,8 +69,7 @@ class Mode # undefined, then the request propagates to the next mode. # The active indicator can also be changed with @setIndicator(). if @options.indicator? - if HUD?.isReady() - if @options.indicator then HUD.show @options.indicator else HUD.hide true, false + if @options.indicator then HUD.show @options.indicator else HUD.hide true, false @passEventToPage else @continueBubbling diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f20bba7e..312c6bbe 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -142,7 +142,6 @@ initializeOnEnabledStateKnown = Utils.makeIdempotent -> installModes() initializeUIComponents = Utils.makeIdempotent -> DomUtils.documentReady -> - HUD.init() Vomnibar.init() if DomUtils.isTopFrame() # @@ -462,7 +461,7 @@ checkIfEnabledForUrl = do -> initializeUIComponents() if frameIsFocused else # Hide the HUD if we're not enabled. - HUD.hide() if HUD.isReady() + HUD.hide true, false # Immediate, do not update indicator. (frameIsFocused = windowIsFocused()) -> Frame.postMessage "isEnabledForUrl", {frameIsFocused, url: window.location.toString()} -- cgit v1.2.3 From 4b564e8517dd3415cb8e2209ce019fa024e88770 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 17 Apr 2016 16:17:38 +0100 Subject: Only Vomnibar.init() when the Vomnibar is needed. The Vomnibar isn't needed on most tabs, so don't init it. I cannot detect any sluggishness as a result of this. --- content_scripts/vimium_frontend.coffee | 12 ++---------- content_scripts/vomnibar.coffee | 10 ++++------ 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 312c6bbe..a80093f9 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -141,9 +141,6 @@ installModes = -> initializeOnEnabledStateKnown = Utils.makeIdempotent -> installModes() -initializeUIComponents = Utils.makeIdempotent -> DomUtils.documentReady -> - Vomnibar.init() if DomUtils.isTopFrame() - # # Complete initialization work that should be done prior to DOMReady. # @@ -455,13 +452,8 @@ checkIfEnabledForUrl = do -> {isEnabledForUrl, passKeys, frameIsFocused} = response initializeOnEnabledStateKnown() normalMode.setPassKeys passKeys - # Initialize UI components, if necessary. We only initialize these once we know that Vimium is enabled; - # see #1838. We need to check this every time so that we can change state from disabled to enabled. - if isEnabledForUrl - initializeUIComponents() if frameIsFocused - else - # Hide the HUD if we're not enabled. - HUD.hide true, false # Immediate, do not update indicator. + # Hide the HUD if we're not enabled. + HUD.hide true, false unless isEnabledForUrl (frameIsFocused = windowIsFocused()) -> Frame.postMessage "isEnabledForUrl", {frameIsFocused, url: window.location.toString()} diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 66494fc2..cbd2892c 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -48,8 +48,7 @@ Vomnibar = } init: -> - unless @vomnibarUI? - @vomnibarUI = new UIComponent "pages/vomnibar.html", "vomnibarFrame", -> + @vomnibarUI ?= new UIComponent "pages/vomnibar.html", "vomnibarFrame", -> # This function opens the vomnibar. It accepts options, a map with the values: # completer - The completer to fetch results from. @@ -58,10 +57,9 @@ Vomnibar = # newTab - Optional, boolean. Whether to open the result in a new tab. open: (sourceFrameId, options) -> @init() - if @vomnibarUI?.uiComponentIsReady - # The Vomnibar cannot coexist with the help dialog (it causes focus issues). - HelpDialog.abort() - @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } + # The Vomnibar cannot coexist with the help dialog (it causes focus issues). + HelpDialog.abort() + @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } root = exports ? window root.Vomnibar = Vomnibar -- cgit v1.2.3