From ffc49d3057daee2354fb77d939fffc0cf77ff2e1 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 12 Feb 2015 10:52:56 +0000 Subject: Grab back focus... - add new option "GrabBackFocus" - use chrome.storage.sync.get() to get option value - avoid race conditions on load - fix tests --- content_scripts/vimium_frontend.coffee | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index ddc19d3a..3cbf2d53 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -98,28 +98,27 @@ frameId = Math.floor(Math.random()*999999999) # If an input grabs the focus before the user has interacted with the page, then grab it back. class GrabBackFocus extends Mode - constructor: (@insertMode) -> - return if @shouldBeDeactivated() - super name: "grab-focus", keydown: => @alwaysContinueBubbling => @exit() + constructor: -> + super + name: "grab-back-focus" + keydown: => @alwaysContinueBubbling => @exit() @push - _name: "grab-focus-handlers" + _name: "grab-back-focus-mousedown" mousedown: => @alwaysContinueBubbling => @exit() - focus: (event) => @grabBackFocus event.target - # An input may already be focused. If so, grab back the focus. - @grabBackFocus document.activeElement if document.activeElement + chrome.storage.sync.get "grabBackfocus", (items) => + return @exit() unless items.grabBackfocus and not chrome.runtime.lastError + @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 grabBackFocus: (element) -> - if DomUtils.isEditable(element) and not @shouldBeDeactivated() - element.blur() - @insertMode.exit null, element - return @suppressEvent - @exit() if @shouldBeDeactivated() - @continueBubbling - - shouldBeDeactivated: -> - false and settings.isLoaded and not settings.get "grabBackFocus" + return @continueBubbling unless DomUtils.isEditable element + element.blur() + @suppressEvent # Only exported for tests. window.initializeModes = -> @@ -139,7 +138,7 @@ window.initializeModes = -> new NormalMode new PassKeysMode new InsertMode permanent: true - new GrabBackFocus InsertMode.permanentInstance + new GrabBackFocus # # Complete initialization work that sould be done prior to DOMReady. -- cgit v1.2.3