From 17379d86faefdeb158b30ccdfb5c3814008bfea3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 10 Mar 2016 12:03:17 +0000 Subject: Move link activation to HintCoordinator. This moves the link activation logic out of LinkHintsMode and into the hint coordinator. At this point, there is (almost) no DOM-specific logic left in LinksHintMode. It only depends an a list of "elements", each of which has a rect property. The main exception to this is filtered hints. In the following commits, we're going to leave filtered hints behind - mainly to keep the diff shorter and cleaner. --- content_scripts/link_hints.coffee | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'content_scripts/link_hints.coffee') diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 57f7cc2b..b3c7412d 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -53,6 +53,21 @@ HintCoordinator = activateMode: (activateModeCallback) -> activateModeCallback ClickableElements.getVisibleClickableElements() + activateLink: (mode, linkMatched) -> + clickEl = linkMatched.clickableItem + + clickActivator = (modifiers) -> (link) -> DomUtils.simulateClick link, modifiers + linkActivator = mode.linkActivator ? clickActivator mode.clickModifiers + + if DomUtils.isSelectable clickEl + DomUtils.simulateSelect clickEl + else + # TODO: Are there any other input elements which should not receive focus? + if clickEl.nodeName.toLowerCase() == "input" and clickEl.type not in ["button", "submit"] + clickEl.focus() + linkActivator clickEl + LinkHints.activateModeWithQueue() if @mode is OPEN_WITH_QUEUE + LinkHints = activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> if 0 < count @@ -129,8 +144,6 @@ class LinkHintsModeBase id: "vimiumHintMarkerContainer", className: "vimiumReset" setOpenLinkMode: (@mode) -> - clickActivator = (modifiers) -> (link) -> DomUtils.simulateClick link, modifiers - @linkActivator = @mode.linkActivator ? clickActivator @mode.clickModifiers @hintMode.setIndicator @mode.indicator # @@ -383,18 +396,11 @@ class LinkHintsMode extends LinkHintsModeBase # activateLink: (linkMatched, userMightOverType=false) -> @removeHintMarkers() - clickEl = linkMatched.clickableItem + mode = @mode linkActivator = => @deactivateMode() - if DomUtils.isSelectable clickEl - DomUtils.simulateSelect clickEl - else - # TODO: Are there any other input elements which should not receive focus? - if clickEl.nodeName.toLowerCase() == "input" and clickEl.type not in ["button", "submit"] - clickEl.focus() - @linkActivator clickEl - LinkHints.activateModeWithQueue() if @mode is OPEN_WITH_QUEUE + HintCoordinator.activateLink mode, linkMatched if userMightOverType and Settings.get "waitForEnterForFilteredHints" new WaitForEnter linkMatched.rect, linkActivator -- cgit v1.2.3