diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index e52c5373cae..65ed14361a8 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -40,7 +40,7 @@ use string_cache::Atom; use style::computed_values::content::ContentItem; use style::computed_values::{border_collapse, clear, mix_blend_mode, overflow_wrap, position}; use style::computed_values::{text_align, text_decoration, white_space, word_break}; -use style::node::{TElement, TNode}; +use style::node::TNode; use style::properties::{self, ComputedValues, cascade_anonymous}; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::computed::{LengthOrPercentageOrNone}; diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index b647284c2ed..0e8aa88e6bc 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -536,18 +536,6 @@ impl<'le> TElement<'le> for LayoutElement<'le> { self.element.namespace() } - #[inline] - fn get_attr(self, namespace: &Namespace, name: &Atom) -> Option<&'le str> { - unsafe { self.element.get_attr_val_for_layout(namespace, name) } - } - - #[inline] - fn get_attrs(self, name: &Atom) -> Vec<&'le str> { - unsafe { - self.element.get_attr_vals_for_layout(name) - } - } - fn get_link(self) -> Option<&'le str> { // FIXME: This is HTML only. let node: &Node = NodeCast::from_actual(self.element); @@ -650,7 +638,7 @@ impl<'le> TElement<'le> for LayoutElement<'le> { } } -impl<'le> TElementAttributes for LayoutElement<'le> { +impl<'le> TElementAttributes<'le> for LayoutElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes(self, hints: &mut V) where V: VecLike>> { @@ -676,6 +664,18 @@ impl<'le> TElementAttributes for LayoutElement<'le> { self.element.get_unsigned_integer_attribute_for_layout(attribute) } } + + #[inline] + fn get_attr(self, namespace: &Namespace, name: &Atom) -> Option<&'le str> { + unsafe { self.element.get_attr_val_for_layout(namespace, name) } + } + + #[inline] + fn get_attrs(self, name: &Atom) -> Vec<&'le str> { + unsafe { + self.element.get_attr_vals_for_layout(name) + } + } } fn get_content(content_list: &content::T) -> Vec { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 9468cc28033..3b4eaebd2b7 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1495,27 +1495,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { #[allow(unsafe_code)] - fn get_attr(self, namespace: &Namespace, local_name: &Atom) -> Option<&'a str> { - self.get_attribute(namespace, local_name).root().map(|attr| { - // This transmute is used to cheat the lifetime restriction. - // FIXME(https://github.com/rust-lang/rust/issues/23338) - let attr = attr.r(); - let value: &str = &**attr.value(); - unsafe { mem::transmute(value) } - }) - } - #[allow(unsafe_code)] - fn get_attrs(self, local_name: &Atom) -> Vec<&'a str> { - let mut attributes = RootedVec::new(); - self.get_attributes(local_name, &mut attributes); - attributes.iter().map(|attr| attr.root()).map(|attr| { - // FIXME(https://github.com/rust-lang/rust/issues/23338) - let attr = attr.r(); - let value: &str = &**attr.value(); - // This transmute is used to cheat the lifetime restriction. - unsafe { mem::transmute(value) } - }).collect() - } fn get_link(self) -> Option<&'a str> { // FIXME: This is HTML only. let node: JSRef = NodeCast::from_ref(self); @@ -1523,7 +1502,15 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { // https://html.spec.whatwg.org/multipage/#selector-link NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | - NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => self.get_attr(&ns!(""), &atom!("href")), + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => { + self.get_attribute(&ns!(""), &atom!("href")).root().map(|attr| { + // This transmute is used to cheat the lifetime restriction. + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value: &str = &**attr.value(); + unsafe { mem::transmute(value) } + }) + }, _ => None, } } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 1189b21af46..7d944a46016 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -22,7 +22,6 @@ use dom::window::WindowHelpers; use layout_interface::{LayoutChan, Msg}; use util::str::{DOMString, HTML_SPACE_CHARACTERS}; use style::media_queries::parse_media_query_list; -use style::node::TElement; use cssparser::Parser as CssParser; use std::ascii::AsciiExt; @@ -145,7 +144,12 @@ impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> { Ok(url) => { let element: JSRef = ElementCast::from_ref(self); - let mq_str = element.get_attr(&ns!(""), &atom!("media")).unwrap_or(""); + let mq_attribute = element.get_attribute(&ns!(""), &atom!("media")).root(); + let value = mq_attribute.r().map(|a| a.value()); + let mq_str = match value { + Some(ref value) => &***value, + None => "", + }; let mut css_parser = CssParser::new(&mq_str); let media = parse_media_query_list(&mut css_parser); diff --git a/components/script/dom/htmlstyleelement.rs b/components/script/dom/htmlstyleelement.rs index 93886218a62..572c7df38eb 100644 --- a/components/script/dom/htmlstyleelement.rs +++ b/components/script/dom/htmlstyleelement.rs @@ -2,13 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLStyleElementBinding; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLStyleElementDerived, NodeCast}; -use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary}; +use dom::bindings::js::{JSRef, OptionalRootable, Rootable, Temporary, RootedReference}; use dom::document::Document; use dom::eventtarget::{EventTarget, EventTargetTypeId}; -use dom::element::{Element, ElementTypeId}; +use dom::element::{Element, ElementTypeId, AttributeHandlers}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; @@ -17,7 +18,6 @@ use layout_interface::{LayoutChan, Msg}; use util::str::DOMString; use style::stylesheets::{Origin, Stylesheet}; use style::media_queries::parse_media_query_list; -use style::node::TElement; use cssparser::Parser as CssParser; #[dom_struct] @@ -59,7 +59,12 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { let win = win.r(); let url = win.get_url(); - let mq_str = element.get_attr(&ns!(""), &atom!("media")).unwrap_or(""); + let mq_attribute = element.get_attribute(&ns!(""), &atom!("media")).root(); + let value = mq_attribute.r().map(|a| a.value()); + let mq_str = match value { + Some(ref value) => &***value, + None => "", + }; let mut css_parser = CssParser::new(&mq_str); let media = parse_media_query_list(&mut css_parser); diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index e2d46c3cb25..d657551b583 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1055,7 +1055,7 @@ dependencies = [ [[package]] name = "selectors" version = "0.1.0" -source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a" +source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/style/legacy.rs b/components/style/legacy.rs index 1b3cac694c0..2c7caa16998 100644 --- a/components/style/legacy.rs +++ b/components/style/legacy.rs @@ -63,7 +63,7 @@ pub trait PresentationalHintSynthesis { matching_rules_list: &mut V, shareable: &mut bool) where N: TNode<'a>, - N::Element: TElementAttributes, + N::Element: TElementAttributes<'a>, V: VecLike>>; /// Synthesizes rules for the legacy `border` attribute. fn synthesize_presentational_hint_for_legacy_border_attribute<'a,E,V>( @@ -73,7 +73,7 @@ pub trait PresentationalHintSynthesis { shareable: &mut bool) where E: TElement<'a> + - TElementAttributes, + TElementAttributes<'a>, V: VecLike>>; } @@ -84,7 +84,7 @@ impl PresentationalHintSynthesis for Stylist { matching_rules_list: &mut V, shareable: &mut bool) where N: TNode<'a>, - N::Element: TElementAttributes, + N::Element: TElementAttributes<'a>, V: VecLike>> { let element = node.as_element(); @@ -199,7 +199,7 @@ impl PresentationalHintSynthesis for Stylist { shareable: &mut bool) where E: TElement<'a> + - TElementAttributes, + TElementAttributes<'a>, V: VecLike>> { match element.get_unsigned_integer_attribute(UnsignedIntegerAttribute::Border) { None => {} diff --git a/components/style/node.rs b/components/style/node.rs index 011066951c3..ebfcf7d9068 100644 --- a/components/style/node.rs +++ b/components/style/node.rs @@ -12,11 +12,15 @@ use util::str::LengthOrPercentageOrAuto; use selectors::matching::DeclarationBlock; pub use selectors::tree::{TNode, TElement}; +use string_cache::{Atom, Namespace}; -pub trait TElementAttributes : Copy { +pub trait TElementAttributes<'a> : Copy { fn synthesize_presentational_hints_for_legacy_attributes(self, &mut V) where V: VecLike>>; fn get_length_attribute(self, attribute: LengthAttribute) -> LengthOrPercentageOrAuto; fn get_integer_attribute(self, attribute: IntegerAttribute) -> Option; fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute) -> Option; + + fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>; + fn get_attrs(self, attr: &Atom) -> Vec<&'a str>; } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 796eac4817b..bbb2d0201f6 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -182,7 +182,7 @@ impl Stylist { applicable_declarations: &mut V) -> bool where N: TNode<'a>, - N::Element: TElementAttributes, + N::Element: TElementAttributes<'a>, V: VecLike { assert!(!self.is_dirty); assert!(element.is_element()); diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index b3137f2535e..bb52195765e 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1037,7 +1037,7 @@ dependencies = [ [[package]] name = "selectors" version = "0.1.0" -source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a" +source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index b5053706d5d..70617896eef 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -908,7 +908,7 @@ dependencies = [ [[package]] name = "selectors" version = "0.1.0" -source = "git+https://github.com/servo/rust-selectors#1fda09bf0c59acfcb697f71b38dad22108b3d27a" +source = "git+https://github.com/servo/rust-selectors#31e13ceb0e4128e0782490cf683443f93a2289be" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",