diff options
| author | Stephen Blott | 2016-03-30 20:06:19 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-30 20:15:29 +0100 | 
| commit | 69a20856ae711d5d86fc6876f840c62dc4c47ef5 (patch) | |
| tree | 92518886a490124d08a768ceb3b6712a9645c14c /lib/handler_stack.coffee | |
| parent | dc6562ae1374272c61d9155a4cc50a4b5f5f12ab (diff) | |
| download | vimium-69a20856ae711d5d86fc6876f840c62dc4c47ef5.tar.bz2 | |
Rework handlerStack.bubbleEvent() for greater clarity.
Diffstat (limited to 'lib/handler_stack.coffee')
| -rw-r--r-- | lib/handler_stack.coffee | 41 | 
1 files changed, 17 insertions, 24 deletions
| diff --git a/lib/handler_stack.coffee b/lib/handler_stack.coffee index c97c5da0..ac48e725 100644 --- a/lib/handler_stack.coffee +++ b/lib/handler_stack.coffee @@ -45,37 +45,30 @@ class HandlerStack    bubbleEvent: (type, event) ->      @eventNumber += 1      eventNumber = @eventNumber -    # We take a copy of the array in order to avoid interference from concurrent removes (for example, to -    # avoid calling the same handler twice, because elements have been spliced out of the array by remove).      for handler in @stack[..].reverse() -      # A handler may have been removed (handler.id == null), so check. -      if handler?.id and handler[type] +      # A handler might have been removed (handler.id == null), so check; or there might just be no handler +      # for this type of event. +      unless handler?.id and handler[type] +        @logResult eventNumber, type, event, handler, "skip [#{handler[type]?}]" if @debug +      else          @currentId = handler.id          result = handler[type].call this, event          @logResult eventNumber, type, event, handler, result if @debug -        if result -          switch result -            when @passEventToPage -              return true -            when @suppressPropagation -              DomUtils.suppressPropagation event -              return false -            when @restartBubbling -              return @bubbleEvent type, event -            when @continueBubbling -              true # Do nothing, continue bubbling. -            else -              # Any other truthy value also means continue bubbling. -              if @debug -                console.log "Unknown truthy return value in handler stack: #{eventNumber}, #{type}, #{result}" +        if result == @passEventToPage +          return true +        else if result == @suppressPropagation +          DomUtils.suppressPropagation event +          return false +        else if result == @restartBubbling +          return @bubbleEvent type, event +        else if result == @continueBubbling or result +          true # Do nothing, but continue bubbling (for @continueBubbling and all truthy results).          else -          if @debug and result != false -            console.log "Unknown falsy return value in handler stack: #{eventNumber}, #{type}, #{result}" -          # Any falsy value means suppress event. +          # result is @suppressEvent or falsy.            DomUtils.suppressEvent event if @isChromeEvent event            return false -      else -        @logResult eventNumber, type, event, handler, "skip" if @debug + +    # None of our handlers want to suppress the event, so pass it to the page.      true    remove: (id = @currentId) -> | 
