aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dom_utils.coffee37
-rw-r--r--lib/utils.coffee10
2 files changed, 45 insertions, 2 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index b3fc981b..ff5991dc 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,29 @@ 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 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}
+ else if element.target == "_blank"
+ chrome.runtime.sendMessage {handler: "openUrlInNewTab", url: element.href, active: true}
+
+ return
+
addFlashRect: (rect) ->
flashEl = @createElement "div"
flashEl.classList.add "vimiumReset"
@@ -381,5 +408,13 @@ DomUtils =
windowIsTooSmall: ->
return window.innerWidth < 3 or window.innerHeight < 3
+ # Inject user styles manually. This is only necessary for our chrome-extension:// pages and frames.
+ injectUserCss: ->
+ Settings.onLoaded ->
+ style = document.createElement "style"
+ style.type = "text/css"
+ style.textContent = Settings.get "userDefinedLinkHintCss"
+ document.head.appendChild style
+
root = exports ? window
root.DomUtils = DomUtils
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 03dab999..d0a82cf7 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -6,14 +6,22 @@ window.forTrusted ?= (handler) -> (event) ->
else
true
+browserInfo = browser?.runtime?.getBrowserInfo?()
+
Utils =
isFirefox: do ->
# NOTE(mrmr1993): This test only works in the background page, this is overwritten by isEnabledForUrl for
# content scripts.
isFirefox = false
- browser?.runtime?.getBrowserInfo?()?.then? (browserInfo) ->
+ browserInfo?.then? (browserInfo) ->
isFirefox = browserInfo?.name == "Firefox"
-> isFirefox
+ firefoxVersion: do ->
+ # NOTE(mrmr1993): This only works in the background page.
+ ffVersion = undefined
+ browserInfo?.then? (browserInfo) ->
+ ffVersion = browserInfo?.version
+ -> ffVersion
getCurrentVersion: ->
chrome.runtime.getManifest().version