aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2017-09-25 10:53:33 +0100
committerGitHub2017-09-25 10:53:33 +0100
commitf0c90f39b463593b6f2d6c71a938f7dc9d93b345 (patch)
tree89b359d6dfb28c0f6484bfbb76cbe5109338d39b
parent4099067f7c03551bea20b6cf6504e4c15d6e7506 (diff)
parent92d2b4058a378c276d52ecc53409603679c3865c (diff)
downloadvimium-f0c90f39b463593b6f2d6c71a938f7dc9d93b345.tar.bz2
Merge pull request #2602 from mrmr1993/ff-link-hints-new-tabs
Firefox: Simulate default action for clicking links with link hints
-rw-r--r--background_scripts/main.coffee12
-rw-r--r--lib/dom_utils.coffee28
2 files changed, 39 insertions, 1 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 379239ae..8afecd4f 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -106,6 +106,7 @@ TabOperations =
index: request.tab.index + 1
active: true
windowId: request.tab.windowId
+ tabConfig.active = request.active if request.active?
# Firefox does not support "about:newtab" in chrome.tabs.create.
delete tabConfig["url"] if tabConfig["url"] == Settings.defaults.newTabUrl
chrome.tabs.create tabConfig, (tab) ->
@@ -116,6 +117,16 @@ TabOperations =
catch
callback.apply this, arguments
+ # Opens request.url in new window and switches to it.
+ openUrlInNewWindow: (request, callback = (->)) ->
+ winConfig =
+ url: Utils.convertToUrl request.url
+ active: true
+ winConfig.active = request.active if request.active?
+ # Firefox does not support "about:newtab" in chrome.tabs.create.
+ delete tabConfig["url"] if tabConfig["url"] == Settings.defaults.newTabUrl
+ chrome.windows.create winConfig, callback
+
toggleMuteTab = do ->
muteTab = (tab) -> chrome.tabs.update tab.id, {muted: !tab.mutedInfo.muted}
@@ -415,6 +426,7 @@ sendRequestHandlers =
# with Chrome-specific URLs like "view-source:http:..".
getCurrentTabUrl: ({tab}) -> tab.url
openUrlInNewTab: (request) -> TabOperations.openUrlInNewTab request
+ openUrlInNewWindow: (request) -> TabOperations.openUrlInNewWindow request
openUrlInIncognito: (request) -> chrome.windows.create incognito: true, url: Utils.convertToUrl request.url
openUrlInCurrentTab: TabOperations.openUrlInCurrentTab
openOptionsPageInNewTab: (request) ->
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index b3fc981b..65a14c34 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -249,7 +249,11 @@ DomUtils =
simulateClick: (element, modifiers) ->
eventSequence = ["mouseover", "mousedown", "mouseup", "click"]
for event in eventSequence
- @simulateMouseEvent event, element, modifiers
+ defaultActionShouldTrigger = @simulateMouseEvent event, element, modifiers
+ if event == "click" and defaultActionShouldTrigger and Utils.isFirefox()
+ # Firefox doesn't (currently) trigger the default action for modified keys.
+ DomUtils.simulateClickDefaultAction element, modifiers
+ defaultActionShouldTrigger # return the values returned by each @simulateMouseEvent call.
simulateMouseEvent: do ->
lastHoveredElement = undefined
@@ -272,6 +276,28 @@ DomUtils =
# but Webkit will. Dispatching a click on an input box does not seem to focus it; we do that separately
element.dispatchEvent(mouseEvent)
+ simulateClickDefaultAction: (element, modifiers) ->
+ return unless modifiers?
+ return unless element.tagName?.toLowerCase() == "a" and element.href?
+
+ {ctrlKey, shiftKey, metaKey, altKey} = modifiers
+
+ # Mac uses a different new tab modifier (meta vs. ctrl).
+ if KeyboardUtils.platform == "Mac"
+ newTabModifier = metaKey == true and ctrlKey == false
+ else
+ newTabModifier = metaKey == false and ctrlKey == true
+
+ if newTabModifier
+ # Open in new tab. Shift determines whether the tab is focused when created. Alt is ignored.
+ chrome.runtime.sendMessage {handler: "openUrlInNewTab", url: element.href, active:
+ shiftKey == true}
+ else if shiftKey == true and metaKey == false and ctrlKey == false and altKey == false
+ # Open in new window.
+ chrome.runtime.sendMessage {handler: "openUrlInNewWindow", url: element.href}
+
+ return
+
addFlashRect: (rect) ->
flashEl = @createElement "div"
flashEl.classList.add "vimiumReset"