diff options
| author | mrmr1993 | 2015-05-10 00:51:05 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-05-10 00:51:05 +0100 |
| commit | d72b36bd54915c38c4cf370dd36cec54b82f7e62 (patch) | |
| tree | 9b31ad8887ca791063a5c17096347e3dcbba74f4 /content_scripts/vimium_frontend.coffee | |
| parent | 4c49931da03535eb73f29879122fa1926a5987da (diff) | |
| download | vimium-d72b36bd54915c38c4cf370dd36cec54b82f7e62.tar.bz2 | |
Use classes for border flashes, in a shadow DOM to avoid CSS collisions
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 47 |
1 files changed, 33 insertions, 14 deletions
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" |
