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.
This commit is contained in:
Martin Richard 2014-06-21 18:17:19 +02:00
parent 1e263f9dec
commit c2345e930d
3 changed files with 60 additions and 1 deletions

View file

@ -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();
}
}