diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 94a0b7ace0f..58dcf5fea82 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -48,6 +48,21 @@ impl HTMLLinkElement { } } +fn get_attr(element: JSRef, name: &str) -> Option { + let elem = element.get_attribute(Null, name).root(); + elem.map(|e| e.deref().value().as_slice().to_string()) +} + +fn is_stylesheet(value: &Option) -> bool { + match *value { + Some(ref value) => { + value.as_slice().split(HTML_SPACE_CHARACTERS.as_slice()) + .any(|s| s.as_slice().eq_ignore_ascii_case("stylesheet")) + }, + None => false, + } +} + impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> { fn super_type<'a>(&'a self) -> Option<&'a VirtualMethods> { let htmlelement: &JSRef = HTMLElementCast::from_borrowed_ref(self); @@ -60,10 +75,19 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> { _ => (), } - let node: JSRef = NodeCast::from_ref(*self); - match name.as_slice() { - "href" => node.set_enabled_state(true), - _ => () + let element: JSRef = ElementCast::from_ref(*self); + let rel = get_attr(element, "rel"); + + match (rel, name.as_slice()) { + (ref rel, "href") => { + if is_stylesheet(rel) { + self.handle_stylesheet_url(value.as_slice()); + } + + let node: JSRef = NodeCast::from_ref(*self); + node.set_enabled_state(true) + } + (_, _) => () } } @@ -89,23 +113,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> { if tree_in_doc { let element: JSRef = ElementCast::from_ref(*self); - // FIXME: workaround for https://github.com/mozilla/rust/issues/13246; - // we get unrooting order failures if these are inside the match. - let rel = { - let rel = element.get_attribute(Null, "rel").root(); - rel.map(|rel| rel.deref().value().as_slice().to_string()) - }; - let href = { - let href = element.get_attribute(Null, "href").root(); - href.map(|href| href.deref().value().as_slice().to_string()) - }; + let rel = get_attr(element, "rel"); + let href = get_attr(element, "href"); match (rel, href) { - (Some(ref rel), Some(ref href)) => { - if rel.as_slice().split(HTML_SPACE_CHARACTERS.as_slice()) - .any(|s| s.as_slice().eq_ignore_ascii_case("stylesheet")) { - self.handle_stylesheet_url(href.as_slice()); - } + (ref rel, Some(ref href)) if is_stylesheet(rel) => { + self.handle_stylesheet_url(href.as_slice()); } _ => {} } @@ -135,3 +148,4 @@ impl Reflectable for HTMLLinkElement { self.htmlelement.reflector() } } + diff --git a/tests/ref/basic.list b/tests/ref/basic.list index 9ed06cd99d7..0c7fcb06257 100644 --- a/tests/ref/basic.list +++ b/tests/ref/basic.list @@ -129,6 +129,7 @@ flaky_gpu,flaky_linux == acid2_noscroll.html acid2_ref_broken.html == float_table_a.html float_table_ref.html == table_containing_block_a.html table_containing_block_ref.html == link_style_order.html link_style_order_ref.html +== link_style_dynamic_addition.html link_style_dynamic_addition_ref.html == percent_height.html percent_height_ref.html == inline_block_with_margin_a.html inline_block_with_margin_ref.html == table_padding_a.html table_padding_ref.html diff --git a/tests/ref/link_style_dynamic_addition.html b/tests/ref/link_style_dynamic_addition.html new file mode 100644 index 00000000000..791ceb07861 --- /dev/null +++ b/tests/ref/link_style_dynamic_addition.html @@ -0,0 +1,11 @@ + + + + + + diff --git a/tests/ref/link_style_dynamic_addition_ref.html b/tests/ref/link_style_dynamic_addition_ref.html new file mode 100644 index 00000000000..a95bd75770c --- /dev/null +++ b/tests/ref/link_style_dynamic_addition_ref.html @@ -0,0 +1,7 @@ + + + + + + +