diff options
author | Martin Richard <martius@martiusweb.net> | 2014-06-21 18:17:19 +0200 |
---|---|---|
committer | Martin Richard <martius@martiusweb.net> | 2014-06-21 18:17:19 +0200 |
commit | c2345e930dd6575e2293fa77e32b1be95d07fd5f (patch) | |
tree | e9673de76b8de48e8882f11eda6262f7b8b908e7 /src/components/script/dom/htmlstyleelement.rs | |
parent | 1e263f9dece8cc1c50c8a5e653138580877de06d (diff) | |
download | servo-c2345e930dd6575e2293fa77e32b1be95d07fd5f.tar.gz servo-c2345e930dd6575e2293fa77e32b1be95d07fd5f.zip |
HTMLStyleElement only applies CSS in the document
HTMLStyleElement will not parse a style element created in Javascript until it
is attached to the DOM.
I added a reftest for the given cases:
* a style element is defined in the HTML code,
* a style element is created in Javascript, CSS content is added to the
element and the element is later attached to the document,
* a style element is created in Javascript, attached to the document and
later CSS content is added to the element,
* a style element is created in Javascript, CSS content is added to the
* element but the element is never attached to the document.
Diffstat (limited to 'src/components/script/dom/htmlstyleelement.rs')
-rw-r--r-- | src/components/script/dom/htmlstyleelement.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index 485a2990602..b2138b500ad 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -9,7 +9,7 @@ use dom::document::Document; use dom::element::HTMLStyleElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; -use dom::node::{Node, NodeMethods, ElementNodeTypeId, window_from_node}; +use dom::node::{Node, NodeMethods, NodeHelpers, ElementNodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; use html::cssparse::parse_inline_css; use layout_interface::{AddStylesheetMsg, LayoutChan}; @@ -49,6 +49,11 @@ pub trait StyleElementHelpers { impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { fn parse_own_css(&self) { let node: &JSRef<Node> = NodeCast::from_ref(self); + + if !node.is_in_doc() { + return; + } + let win = window_from_node(node).root(); let url = win.deref().page().get_url(); @@ -72,4 +77,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> { } self.parse_own_css(); } + + fn bind_to_tree(&self) { + match self.super_type() { + Some(ref s) => s.bind_to_tree(), + _ => () + } + self.parse_own_css(); + } } |