From d72b36bd54915c38c4cf370dd36cec54b82f7e62 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sun, 10 May 2015 00:51:05 +0100 Subject: Use classes for border flashes, in a shadow DOM to avoid CSS collisions --- content_scripts/vimium.css | 14 ++++++++++ content_scripts/vimium_frontend.coffee | 47 ++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 14 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium.css b/content_scripts/vimium.css index fb8824c2..5180fb22 100644 --- a/content_scripts/vimium.css +++ b/content_scripts/vimium.css @@ -109,6 +109,20 @@ div.internalVimiumSelectedInputHint span { color: white !important; } +/* Frame Highlight Marker CSS*/ +div.vimiumHighlightedFrame { + position: fixed; + top: 0px; + left: 0px; + width: 100%; + height: 100%; + padding: 0px; + margin: 0px; + border: 5px solid yellow; + box-sizing: border-box; + pointer-events: none; +} + /* Help Dialog CSS */ div#vimiumHelpDialog { diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index e1d7b581..9d95018c 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -327,20 +327,39 @@ setScrollPosition = (scrollX, scrollY) -> # # Called from the backend in order to change frame focus. # -window.focusThisFrame = (request) -> - if window.innerWidth < 3 or window.innerHeight < 3 - # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead. - # This affects sites like Google Inbox, which have many tiny iframes. See #1317. - # Here we're assuming that there is at least one frame large enough to focus. - chrome.runtime.sendMessage({ handler: "nextFrame", frameId: frameId }) - return - window.focus() - shouldHighlight = request.highlight - shouldHighlight ||= request.highlightOnlyIfNotTop and not DomUtils.isTopFrame() - if document.body and shouldHighlight - borderWas = document.body.style.border - document.body.style.border = '5px solid yellow' - setTimeout((-> document.body.style.border = borderWas), 200) +window.focusThisFrame = do -> + # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. + highlightedFrameElement = document.createElement "div" + _shadowDOM = highlightedFrameElement.createShadowRoot() + + # Inject stylesheet. + _styleSheet = document.createElement "style" + if _styleSheet.style? + _styleSheet.innerHTML = "" + _shadowDOM.appendChild _styleSheet + # Load stylesheet. + xhr = new XMLHttpRequest() + xhr.onload = (e) -> _styleSheet.innerHTML = xhr.responseText + xhr.open "GET", chrome.runtime.getURL("content_scripts/vimium.css"), true + xhr.send() + + _frameEl = document.createElement "div" + _frameEl.className = "vimiumReset vimiumHighlightedFrame" + _shadowDOM.appendChild _frameEl + + (request) -> + if window.innerWidth < 3 or window.innerHeight < 3 + # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead. + # This affects sites like Google Inbox, which have many tiny iframes. See #1317. + # Here we're assuming that there is at least one frame large enough to focus. + chrome.runtime.sendMessage({ handler: "nextFrame", frameId: frameId }) + return + window.focus() + shouldHighlight = request.highlight + shouldHighlight ||= request.highlightOnlyIfNotTop and not DomUtils.isTopFrame() + if shouldHighlight + document.documentElement.appendChild highlightedFrameElement + setTimeout (-> highlightedFrameElement.remove()), 200 extend window, scrollToBottom: -> Scroller.scrollTo "y", "max" -- cgit v1.2.3 From f54a273e97e5feeae2978845b4dfc2f154445e7f Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sun, 10 May 2015 22:21:40 +0100 Subject: Fallback to raw element instead of shadow DOM for PhantomJS --- content_scripts/vimium_frontend.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 9d95018c..9da99018 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -330,7 +330,8 @@ setScrollPosition = (scrollX, scrollY) -> window.focusThisFrame = do -> # Create a shadow DOM wrapping the frame so the page's styles don't interfere with ours. highlightedFrameElement = document.createElement "div" - _shadowDOM = highlightedFrameElement.createShadowRoot() + # PhantomJS doesn't support createShadowRoot, so guard against its non-existance. + _shadowDOM = highlightedFrameElement.createShadowRoot?() ? highlightedFrameElement # Inject stylesheet. _styleSheet = document.createElement "style" -- cgit v1.2.3