aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/vimium_frontend.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-04-02 16:54:11 +0100
committerStephen Blott2016-04-02 17:02:41 +0100
commit96c74e4aa7e39a99bf5511440ba7a4155f1e2db8 (patch)
tree10ac55d9efa915c4f17522961554e4540e3607e2 /content_scripts/vimium_frontend.coffee
parent4f74307ed382ce942a1210007b99ed426f997a81 (diff)
downloadvimium-96c74e4aa7e39a99bf5511440ba7a4155f1e2db8.tar.bz2
Simplify UI component initialisation.
There's no need for the previous complicated approach to UI component initialialisation, in particular for the Vomnibar. We only initialise the Vomnibar in the top frame. However, if for some reason it hasn't been initialised by the time it's needed, then we can just initialise it then. We are only initialising it early to avoid flicker, so it's not a correctness issue. And the only reason it wouldn't be initialised is if Vimium is disabled in the top frame, but enabled in some other frame -- which is not a common case.
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
-rw-r--r--content_scripts/vimium_frontend.coffee46
1 files changed, 18 insertions, 28 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 77dbcc9d..b73bd2e3 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -138,6 +138,11 @@ installModes = ->
initializeOnEnabledStateKnown = Utils.makeIdempotent ->
installModes()
+initializeUIComponents = ->
+ # Both of these are idempotent.
+ HUD.init()
+ Vomnibar.init() if DomUtils.isTopFrame()
+
#
# Complete initialization work that should be done prior to DOMReady.
#
@@ -214,21 +219,19 @@ Frame =
linkHintsMessage: (request) -> HintCoordinator[request.messageType] request
registerFrameId: ({chromeFrameId}) ->
frameId = window.frameId = chromeFrameId
- unless frameId == 0
- # The background page registers the top frame automatically. We register any other frame immediately if
- # it is focused or its window isn't tiny. We register tiny frames later, when necessary. This affects
- # focusFrame() and link hints.
- if windowIsFocused() or not DomUtils.windowIsTooSmall()
+ # We register a frame immediately only if it is focused or its window isn't tiny. We register tiny
+ # frames later, when necessary. This affects focusFrame() and link hints.
+ if windowIsFocused() or not DomUtils.windowIsTooSmall()
+ Frame.postMessage "registerFrame"
+ else
+ postRegisterFrame = ->
+ window.removeEventListener "focus", focusHandler
+ window.removeEventListener "resize", resizeHandler
Frame.postMessage "registerFrame"
- else
- postRegisterFrame = ->
- window.removeEventListener "focus", focusHandler
- window.removeEventListener "resize", resizeHandler
- Frame.postMessage "registerFrame"
- window.addEventListener "focus", focusHandler = ->
- postRegisterFrame() if event.target == window
- window.addEventListener "resize", resizeHandler = ->
- postRegisterFrame() unless DomUtils.windowIsTooSmall()
+ window.addEventListener "focus", focusHandler = ->
+ postRegisterFrame() if event.target == window
+ window.addEventListener "resize", resizeHandler = ->
+ postRegisterFrame() unless DomUtils.windowIsTooSmall()
init: ->
@port = chrome.runtime.connect name: "frames"
@@ -434,18 +437,6 @@ extend window,
targetElement: document.activeElement
indicator: false
-# Initialize UI components which are only installed in the main/top frame.
-initializeTopFrameUIComponents = do ->
- Frame.addEventListener "initializeTopFrameUIComponents", Utils.makeIdempotent ->
- DomUtils.documentReady Vomnibar.init.bind Vomnibar
-
- Utils.makeIdempotent -> DomUtils.documentReady ->
- Frame.postMessage "initializeTopFrameUIComponents"
-
-# Initialize UI components which are only installed in all frames (i.e., the HUD).
-initializeAllFrameUIComponents = Utils.makeIdempotent ->
- DomUtils.documentReady HUD.init.bind HUD
-
# Checks if Vimium should be enabled or not in this frame. As a side effect, it also informs the background
# page whether this frame has the focus, allowing the background page to track the active frame's URL and set
# the page icon.
@@ -457,8 +448,7 @@ checkIfEnabledForUrl = do ->
# 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
- initializeTopFrameUIComponents()
- initializeAllFrameUIComponents() if frameIsFocused
+ initializeUIComponents() if frameIsFocused
else
# Hide the HUD if we're not enabled.
HUD.hide() if HUD.isReady()