diff options
author | Stephen Blott | 2015-01-02 15:01:32 +0000 |
---|---|---|
committer | Stephen Blott | 2015-01-02 15:01:32 +0000 |
commit | b7d5e25e353010505db7754e97d4387c8aa6b8fc (patch) | |
tree | 4208ecdda9f53ae22cb8e0d36aa8ffb2910dc9bb | |
parent | d4c43d8f9095325b41544ad7811cc131c1b186f1 (diff) | |
download | vimium-b7d5e25e353010505db7754e97d4387c8aa6b8fc.tar.bz2 |
Modes; simplify badge handling.
-rw-r--r-- | background_scripts/main.coffee | 2 | ||||
-rw-r--r-- | content_scripts/mode_insert.coffee | 28 | ||||
-rw-r--r-- | content_scripts/mode_passkeys.coffee | 7 | ||||
-rw-r--r-- | content_scripts/vimium_frontend.coffee | 32 |
4 files changed, 33 insertions, 36 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index fc0a792f..8d36de95 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -352,7 +352,7 @@ setBadge = (request) -> root.updateActiveState = updateActiveState = (tabId) -> enabledIcon = "icons/browser_action_enabled.png" disabledIcon = "icons/browser_action_disabled.png" - partialIcon = "icons/browser_action_partial.png" + partialIcon = enabledIcon # Let's try diabling that while we're playing with badges... "icons/browser_action_partial.png" chrome.tabs.get tabId, (tab) -> chrome.tabs.sendMessage tabId, { name: "getActiveState" }, (response) -> if response diff --git a/content_scripts/mode_insert.coffee b/content_scripts/mode_insert.coffee index f37cf1ad..9504edfd 100644 --- a/content_scripts/mode_insert.coffee +++ b/content_scripts/mode_insert.coffee @@ -31,6 +31,17 @@ class InsertMode extends Mode @activate() if document.activeElement?.isContentEditable @isInsertMode + activate: -> + unless @isInsertMode + @isInsertMode = true + @badge = "I" + Mode.updateBadge() + + deactivate: -> + @isInsertMode = false + @badge = "" + Mode.updateBadge() + generateKeyHandler: (type) -> (event) => return Mode.propagate unless @isActive() @@ -43,24 +54,12 @@ class InsertMode extends Mode # right thing to do for most common use cases. However, it could also cripple flash-based sites and # games. See discussion in #1211 and #1194. event.srcElement.blur() - @isInsertMode = false - Mode.updateBadge() + @deactivate() Mode.suppressPropagation - activate: -> - unless @isInsertMode - @isInsertMode = true - Mode.updateBadge() - - # Override updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - super badge if @isActive() - constructor: -> super name: "insert" - badge: "I" keydown: @generateKeyHandler "keydown" keypress: @generateKeyHandler "keypress" keyup: @generateKeyHandler "keyup" @@ -73,8 +72,7 @@ class InsertMode extends Mode blur: (event) => handlerStack.alwaysPropagate => if @isInsertMode and @isFocusable event.target - @isInsertMode = false - Mode.updateBadge() + @deactivate() # We may already have been dropped into insert mode. So check. Mode.updateBadge() diff --git a/content_scripts/mode_passkeys.coffee b/content_scripts/mode_passkeys.coffee index bb4518ae..a953deca 100644 --- a/content_scripts/mode_passkeys.coffee +++ b/content_scripts/mode_passkeys.coffee @@ -28,20 +28,15 @@ class PassKeysMode extends Mode @passKeys = (request.enabled and request.passKeys) or "" if request.keyQueue? @keyQueue = request.keyQueue + @badge = if @passKeys and not @keyQueue then "P" else "" Mode.updateBadge() constructor: -> super name: "passkeys" - badge: "P" keydown: (event) => @handlePassKeyEvent event keypress: (event) => @handlePassKeyEvent event keyup: -> Mode.propagate - # Overriding updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - super badge if @passKeys and not @keyQueue - root = exports ? window root.PassKeysMode = PassKeysMode diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index fb6199bf..2df2e226 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -106,6 +106,21 @@ frameId = Math.floor(Math.random()*999999999) hasModifiersRegex = /^<([amc]-)+.>/ +class NormalMode extends Mode + constructor: -> + super + name: "normal" + badge: "N" + keydown: onKeydown + keypress: onKeypress + keyup: onKeyup + + updateBadgeForMode: (badge) -> + handlerStack.alwaysPropagate => + # Idea... Instead of an icon, we could show the keyQueue here (if it's non-empty). + super badge + badge.badge = "" unless isEnabledForUrl + # # Complete initialization work that sould be done prior to DOMReady. # @@ -115,20 +130,9 @@ initializePreDomReady = -> # Install normal mode. This is at the bottom of both the mode stack and the handler stack, and is never # deactivated. - new Mode - name: "normal" - badge: "N" - keydown: onKeydown - keypress: onKeypress - keyup: onKeyup - - # Overriding updateBadgeForMode() from Mode.updateBadgeForMode(). - updateBadgeForMode: (badge) -> - handlerStack.alwaysPropagate => - badge.badge ||= if keyQueue then keyQueue else @badge - badge.badge = "" unless isEnabledForUrl - - # Initialize the scroller. The scroller install a key handler, and this is next on the handler stack, + new NormalMode() + + # Initialize the scroller. The scroller installs a key handler, and this is next on the handler stack, # immediately above normal mode. Scroller.init settings |