diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index 46f5f1f9e63..7c7c9cc3505 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -386,6 +386,11 @@ impl<'le> TElement for ServoLayoutElement<'le> { self.element.get_state_for_layout() } + #[inline] + fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool { + self.get_attr(namespace, attr).is_some() + } + #[inline] fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> { unsafe { diff --git a/components/style/dom.rs b/components/style/dom.rs index 76445e6f60b..436bf57aebd 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -207,6 +207,8 @@ pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynt fn get_state(&self) -> ElementState; + fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool; + fn get_attr<'a>(&'a self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>; /// Properly marks nodes as dirty in response to restyle hints. diff --git a/components/style/matching.rs b/components/style/matching.rs index 289410af3f6..aa7d751267d 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -34,7 +34,7 @@ fn create_common_style_affecting_attributes_from_element(element: & for attribute_info in &common_style_affecting_attributes() { match attribute_info.mode { CommonStyleAffectingAttributeMode::IsPresent(flag) => { - if element.get_attr(&ns!(), &attribute_info.atom).is_some() { + if element.has_attr(&ns!(), &attribute_info.atom) { flags.insert(flag) } } @@ -296,7 +296,7 @@ impl StyleSharingCandidate { match attribute_info.mode { CommonStyleAffectingAttributeMode::IsPresent(flag) => { if self.common_style_affecting_attributes.contains(flag) != - element.get_attr(&ns!(), &attribute_info.atom).is_some() { + element.has_attr(&ns!(), &attribute_info.atom) { return false } } @@ -320,7 +320,7 @@ impl StyleSharingCandidate { } for attribute_name in &rare_style_affecting_attributes() { - if element.get_attr(&ns!(), attribute_name).is_some() { + if element.has_attr(&ns!(), attribute_name) { return false } } @@ -606,7 +606,7 @@ pub trait ElementMatchMethods : TElement if self.style_attribute().is_some() { return StyleSharingResult::CannotShare } - if self.get_attr(&ns!(), &atom!("id")).is_some() { + if self.has_attr(&ns!(), &atom!("id")) { return StyleSharingResult::CannotShare } diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index 8ef5161cf97..7dc4545be2f 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -360,6 +360,15 @@ impl<'le> TElement for GeckoElement<'le> { } } + #[inline] + fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool { + unsafe { + bindings::Gecko_HasAttr(self.element, + namespace.0.as_ptr(), + attr.as_ptr()) + } + } + #[inline] fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { unsafe {