diff options
| author | Stephen Blott | 2015-01-08 07:20:55 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-01-08 07:25:21 +0000 |
| commit | 7c886d32cca6c0540a9ec6247eb1617b8f1db86a (patch) | |
| tree | 089eb79c280765c61e9b01d297c470709555b2bc /content_scripts/mode.coffee | |
| parent | 8cbe2df33d8af3845801bfaacf3b58adab9916cb (diff) | |
| download | vimium-7c886d32cca6c0540a9ec6247eb1617b8f1db86a.tar.bz2 | |
Modes; refactor PostFindMode key handling.
In particular, this refactors the handling of non-vimium key events in
PostFindMode. This implements option 2 from #1415. However, #1415 is
not resolved, and option 3 remains a viable option.
Diffstat (limited to 'content_scripts/mode.coffee')
| -rw-r--r-- | content_scripts/mode.coffee | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 92285b8c..160debc4 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -102,12 +102,27 @@ class Mode @passKeys = passKeys @registerStateChange?() + # If options.trapAllKeyboardEvents is truthy, then it should be an element. All keyboard events on that + # element are suppressed *after* bubbling the event down the handler stack. This prevents such events + # from propagating to other extensions or the host page. + if options.trapAllKeyboardEvents + @unshift + keydown: (event) => @alwaysContinueBubbling -> + DomUtils.suppressPropagation event if event.srcElement == options.trapAllKeyboardEvents + keypress: (event) => @alwaysContinueBubbling -> + DomUtils.suppressEvent event if event.srcElement == options.trapAllKeyboardEvents + keyup: (event) => @alwaysContinueBubbling -> + DomUtils.suppressPropagation event if event.srcElement == options.trapAllKeyboardEvents + Mode.updateBadge() if @badge # End of Mode.constructor(). push: (handlers) -> @handlers.push handlerStack.push handlers + unshift: (handlers) -> + @handlers.unshift handlerStack.push handlers + onExit: (handler) -> @exitHandlers.push handler @@ -124,7 +139,8 @@ class Mode chooseBadge: (badge) -> badge.badge ||= @badge - # Shorthand for a long name. + # Shorthand for an otherwise long name. This allow us to write handlers which always yield the same value, + # without having to be concerned with the result of the handler itself. alwaysContinueBubbling: (func) -> handlerStack.alwaysContinueBubbling func # Static method. Used externally and internally to initiate bubbling of an updateBadge event and to send |
