aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-03-30 13:07:05 +0100
committerStephen Blott2016-03-30 14:58:46 +0100
commit21da3fcafbb29540788037dbcdbdce79ad14e650 (patch)
tree0d4ff357c8cfd25226cb8dd6bf07d398ed3dfb03 /content_scripts/mode.coffee
parenta2fba970e089254adae2631a5b154e6bd92ec1e2 (diff)
downloadvimium-21da3fcafbb29540788037dbcdbdce79ad14e650.tar.bz2
Rename handlerStack constants.
Problems: - The meanings of some of the Mode/handlerStack constant names is far from obvious. - The same thing is named different things in different places. This changes various constant names such that: - the names used in the handler stack and in the modes are the same. - ditto vis-a-vis DomUtils. Also, break out the core of the handler stacks' `bubbleEvent` method into a switch statements. This makes it more obvious that the cases are mutually exclusive.
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee36
1 files changed, 14 insertions, 22 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 317fbc86..37321660 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -31,12 +31,15 @@ class Mode
@modes: []
# Constants; short, readable names for the return values expected by handlerStack.bubbleEvent.
- continueBubbling: true
- suppressEvent: false
- stopBubblingAndTrue: handlerStack.stopBubblingAndTrue
- stopBubblingAndFalse: handlerStack.stopBubblingAndFalse
+ continueBubbling: handlerStack.continueBubbling
+ suppressEvent: handlerStack.suppressEvent
+ passEventToPage: handlerStack.passEventToPage
+ suppressPropagation: handlerStack.suppressPropagation
restartBubbling: handlerStack.restartBubbling
+ alwaysContinueBubbling: handlerStack.alwaysContinueBubbling
+ alwaysSuppressPropagation: handlerStack.alwaysSuppressPropagation
+
constructor: (@options = {}) ->
@handlers = []
@exitHandlers = []
@@ -53,7 +56,8 @@ class Mode
# or 2) to worry about event suppression and event-handler return values.
if @options.suppressAllKeyboardEvents
for type in [ "keydown", "keypress", "keyup" ]
- @options[type] = @alwaysSuppressEvent @options[type]
+ do (handler = @options[type]) =>
+ @options[type] = (event) => @alwaysSuppressPropagation => handler? event
@push
keydown: @options.keydown || null
@@ -67,7 +71,7 @@ class Mode
if @options.indicator?
if HUD?.isReady()
if @options.indicator then HUD.show @options.indicator else HUD.hide true, false
- @stopBubblingAndTrue
+ @passEventToPage
else @continueBubbling
# If @options.exitOnEscape is truthy, then the mode will exit when the escape key is pressed.
@@ -126,7 +130,7 @@ class Mode
_name: "mode-#{@id}/passInitialKeyupEvents"
keydown: => @alwaysContinueBubbling -> handlerStack.remove()
keyup: (event) =>
- if KeyboardUtils.isPrintable event then @stopBubblingAndFalse else @stopBubblingAndTrue
+ if KeyboardUtils.isPrintable event then @suppressPropagation else @passEventToPage
# if @options.suppressTrailingKeyEvents is set, then -- on exit -- we suppress all key events until a
# subsquent (non-repeat) keydown or keypress. In particular, the intention is to catch keyup events for
@@ -136,16 +140,16 @@ class Mode
@onExit ->
handler = (event) ->
if event.repeat
- false # Suppress event.
+ handlerStack.suppressEvent
else
keyEventSuppressor.exit()
- true # Do not suppress event.
+ handlerStack.continueBubbling
keyEventSuppressor = new Mode
name: "suppress-trailing-key-events"
keydown: handler
keypress: handler
- keyup: -> handlerStack.stopBubblingAndFalse
+ keyup: -> handlerStack.suppressPropagation
Mode.modes.push this
@setIndicator()
@@ -181,18 +185,6 @@ class Mode
@modeIsActive = false
@setIndicator()
- # Shorthand for an otherwise long name. This wraps a handler with an arbitrary return value, and always
- # yields @continueBubbling instead. This simplifies handlers if they always continue bubbling (a common
- # case), because they do not need to be concerned with the value they yield.
- alwaysContinueBubbling: handlerStack.alwaysContinueBubbling
-
- # Shorthand for an event handler which always suppresses event propagation.
- alwaysSuppressEvent: (handler = null) ->
- (event) =>
- handler? event
- DomUtils.suppressPropagation event
- @stopBubblingAndFalse
-
# Debugging routines.
logModes: ->
if Mode.debug