aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/ui_component.coffee
diff options
context:
space:
mode:
authormrmr19932015-04-28 13:33:15 +0100
committermrmr19932015-04-28 14:18:24 +0100
commit350a54af51528440caaf4e16c8884f77b3097cd7 (patch)
tree28df86fa7b86f23657430eefb68264c29e52f289 /content_scripts/ui_component.coffee
parent833f6dc8d26b53be642c54d1e778bb3c526b10fc (diff)
downloadvimium-350a54af51528440caaf4e16c8884f77b3097cd7.tar.bz2
Load the Vomnibar (and all UIComponents) in a shadow DOM
This insulates them from page CSS, so we don't have to compete to style elements correctly.
Diffstat (limited to 'content_scripts/ui_component.coffee')
-rw-r--r--content_scripts/ui_component.coffee20
1 files changed, 16 insertions, 4 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee
index 77c52d3d..64831794 100644
--- a/content_scripts/ui_component.coffee
+++ b/content_scripts/ui_component.coffee
@@ -5,12 +5,24 @@ class UIComponent
options: null
constructor: (iframeUrl, className, @handleMessage) ->
+ styleSheet = document.createElement "link"
+ extend styleSheet,
+ rel: "stylesheet"
+ type: "text/css"
+ href: chrome.runtime.getURL "content_scripts/vimium.css"
@iframeElement = document.createElement "iframe"
- @iframeElement.className = className
- @iframeElement.seamless = "seamless"
- @iframeElement.src = chrome.runtime.getURL iframeUrl
+ extend @iframeElement,
+ className: className
+ seamless: "seamless"
+ src: chrome.runtime.getURL iframeUrl
@iframeElement.addEventListener "load", => @openPort()
- document.documentElement.appendChild @iframeElement
+ shadowWrapper = document.createElement "div"
+ # PhantomJS doesn't support createShadowRoot, so guard against its non-existance.
+ shadowDOM = shadowWrapper.createShadowRoot?() ? shadowWrapper
+ shadowDOM.appendChild styleSheet
+ shadowDOM.appendChild @iframeElement
+ document.documentElement.appendChild shadowWrapper
+
@showing = true # The iframe is visible now.
# Hide the iframe, but don't interfere with the focus.
@hide false