diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2016-06-23 14:13:50 -0700 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2016-07-05 18:03:36 -0700 |
commit | 96af00fbb9270f1704b36bebbbc47493d3a8f813 (patch) | |
tree | 85f8c4fe28b6f79132a99d62173ebed17c9acff2 | |
parent | 7947afc6991f0ba8db73d23014e8264534d801a8 (diff) | |
download | servo-96af00fbb9270f1704b36bebbbc47493d3a8f813.tar.gz servo-96af00fbb9270f1704b36bebbbc47493d3a8f813.zip |
Add has_attr method to TElement.
If this is all the information the caller needs, we can get it from gecko without
worrying about atomization and string conversions.
-rw-r--r-- | components/script/layout_wrapper.rs | 5 | ||||
-rw-r--r-- | components/style/dom.rs | 2 | ||||
-rw-r--r-- | components/style/matching.rs | 8 | ||||
-rw-r--r-- | ports/geckolib/wrapper.rs | 9 |
4 files changed, 20 insertions, 4 deletions
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 @@ -387,6 +387,11 @@ impl<'le> TElement for ServoLayoutElement<'le> { } #[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 { (*self.element.unsafe_get()).get_attr_val_for_layout(namespace, name) 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<E: TElement>(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<C: ComputedValues> StyleSharingCandidate<C> { 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<C: ComputedValues> StyleSharingCandidate<C> { } 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 @@ -361,6 +361,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 { let mut length: u32 = 0; |