diff options
| author | Stephen Blott | 2015-02-14 12:23:28 +0000 |
|---|---|---|
| committer | Stephen Blott | 2015-02-14 12:23:28 +0000 |
| commit | 39545307beea82cae85030ecea936a248a6d1544 (patch) | |
| tree | 13690e6ea9123a25a17ccc8104dc1721bb813b55 /content_scripts | |
| parent | 9bd6b7814fbee5508a4a746789d10c687a2c0c9b (diff) | |
| parent | 05f229201a05101ab4947bd436ec02d8864392f9 (diff) | |
| download | vimium-39545307beea82cae85030ecea936a248a6d1544.tar.bz2 | |
Merge branch 'grab-back-focus'
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 315e64cd..5bad1148 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -44,7 +44,7 @@ settings = loadedValues: 0 valuesToLoad: [ "scrollStepSize", "linkHintCharacters", "linkHintNumbers", "filterLinkHints", "hideHud", "previousPatterns", "nextPatterns", "regexFindMode", "userDefinedLinkHintCss", - "helpDialog_showAdvancedCommands", "smoothScroll" ] + "helpDialog_showAdvancedCommands", "smoothScroll", "grabBackFocus" ] isLoaded: false eventListeners: {} @@ -96,6 +96,33 @@ settings = # frameId = Math.floor(Math.random()*999999999) +# If an input grabs the focus before the user has interacted with the page, then grab it back (if the +# grabBackFocus option is set). +class GrabBackFocus extends Mode + constructor: -> + super + name: "grab-back-focus" + keydown: => @alwaysContinueBubbling => @exit() + + @push + _name: "grab-back-focus-mousedown" + mousedown: => @alwaysContinueBubbling => @exit() + + activate = => + return @exit() unless settings.get "grabBackFocus" + @push + _name: "grab-back-focus-focus" + focus: (event) => @grabBackFocus event.target + # An input may already be focused. If so, grab back the focus. + @grabBackFocus document.activeElement if document.activeElement + + if settings.isLoaded then activate() else settings.addEventListener "load", activate + + grabBackFocus: (element) -> + return @continueBubbling unless DomUtils.isEditable element + element.blur() + @suppressEvent + # Only exported for tests. window.initializeModes = -> class NormalMode extends Mode @@ -114,6 +141,7 @@ window.initializeModes = -> new NormalMode new PassKeysMode new InsertMode permanent: true + new GrabBackFocus # # Complete initialization work that sould be done prior to DOMReady. @@ -179,7 +207,7 @@ window.initializeWhenEnabled = -> unless 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. - for type in ["keydown", "keypress", "keyup", "click", "focus", "blur"] + for type in [ "keydown", "keypress", "keyup", "click", "focus", "blur", "mousedown" ] do (type) -> installListener window, type, (event) -> handlerStack.bubbleEvent type, event installListener document, "DOMActivate", (event) -> handlerStack.bubbleEvent 'DOMActivate', event installedListeners = true |
