diff options
| -rw-r--r-- | content_scripts/mode.coffee | 12 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 22 | ||||
| -rw-r--r-- | lib/handler_stack.coffee | 8 | ||||
| -rw-r--r-- | manifest.json | 1 |
4 files changed, 30 insertions, 13 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee new file mode 100644 index 00000000..f7bf9e69 --- /dev/null +++ b/content_scripts/mode.coffee @@ -0,0 +1,12 @@ +root = exports ? window + +class root.Mode + constructor: (onKeydown, onKeypress, onKeyup, @popModeCallback) -> + @handlerId = handlerStack.push + keydown: onKeydown + keypress: onKeypress + keyup: onKeyup + + popMode: -> + handlerStack.remove @handlerId + @popModeCallback() diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index ae275f0c..5f8b050f 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -4,7 +4,6 @@ # background page that we're in domReady and ready to accept normal commands by connectiong to a port named # "domReady". # -window.handlerStack = new HandlerStack insertModeLock = null findMode = false @@ -110,6 +109,8 @@ initializePreDomReady = -> settings.addEventListener("load", LinkHints.init.bind(LinkHints)) settings.load() + nf = -> true + new Mode(onKeydown, onKeypress, onKeyup, nf) Scroller.init settings checkIfEnabledForUrl() @@ -169,9 +170,11 @@ initializeWhenEnabled = (newPassKeys) -> if (!installedListeners) # Key event handlers fire on window before they do on document. Prefer window for key events so the page # can't set handlers to grab the keys before us. - installListener window, "keydown", onKeydown - installListener window, "keypress", onKeypress - installListener window, "keyup", onKeyup + for type in ["keydown", "keypress", "keyup"] + do (type) -> + installListener window, type, (event) -> + console.log type + handlerStack.bubbleEvent type, event installListener document, "focus", onFocusCapturePhase installListener document, "blur", onBlurCapturePhase installListener document, "DOMActivate", onDOMActivate @@ -398,8 +401,6 @@ KeydownEvents = # Note that some keys will only register keydown events and not keystroke events, e.g. ESC. # onKeypress = (event) -> - return unless handlerStack.bubbleEvent('keypress', event) - keyChar = "" # Ignore modifier keys by themselves. @@ -424,8 +425,7 @@ onKeypress = (event) -> keyPort.postMessage({ keyChar:keyChar, frameId:frameId }) onKeydown = (event) -> - return unless handlerStack.bubbleEvent('keydown', event) - + console.log "onKeydown" keyChar = "" # handle special keys, and normal input keys with modifiers being pressed. don't handle shiftKey alone (to @@ -518,11 +518,7 @@ onKeydown = (event) -> KeydownEvents.push event onKeyup = (event) -> - handledKeydown = KeydownEvents.pop event - return unless handlerStack.bubbleEvent("keyup", event) - - # Don't propagate the keyup to the underlying page if Vimium has handled it. See #733. - DomUtils.suppressPropagation(event) if handledKeydown + DomUtils.suppressPropagation(event) if KeydownEvents.pop event checkIfEnabledForUrl = -> url = window.location.toString() diff --git a/lib/handler_stack.coffee b/lib/handler_stack.coffee index 858f2ec9..728ea4bc 100644 --- a/lib/handler_stack.coffee +++ b/lib/handler_stack.coffee @@ -5,6 +5,7 @@ class root.HandlerStack constructor: -> @stack = [] @counter = 0 + @passThrough = {} genId: -> @counter = ++@counter & 0xffff @@ -18,6 +19,7 @@ class root.HandlerStack # propagation by returning a falsy value. bubbleEvent: (type, event) -> for i in [(@stack.length - 1)..0] by -1 + console.log i, type handler = @stack[i] # We need to check for existence of handler because the last function call may have caused the release # of more than one handler. @@ -27,6 +29,10 @@ class root.HandlerStack if not passThrough DomUtils.suppressEvent(event) return false + # If @passThrough is returned, then discontinue further bubbling and pass the event through to the + # underlying page. The event is not suppresssed. + if passThrough == @passThrough + return false true remove: (id = @currentId) -> @@ -35,3 +41,5 @@ class root.HandlerStack if handler.id == id @stack.splice(i, 1) break + +root.handlerStack = new HandlerStack diff --git a/manifest.json b/manifest.json index a365f390..dca01b49 100644 --- a/manifest.json +++ b/manifest.json @@ -43,6 +43,7 @@ "content_scripts/vomnibar.js", "content_scripts/scroller.js", "content_scripts/marks.js", + "content_scripts/mode.js", "content_scripts/vimium_frontend.js" ], "css": ["content_scripts/vimium.css"], |
