Skip to content

Commit

Permalink
Add has_attr method to TElement.
Browse files Browse the repository at this point in the history
If this is all the information the caller needs, we can get it from gecko without
worrying about atomization and string conversions.
  • Loading branch information
bholley committed Jul 6, 2016
1 parent 7947afc commit 96af00f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions components/script/layout_wrapper.rs
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions components/style/dom.rs
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions components/style/matching.rs
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions ports/geckolib/wrapper.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 96af00f

Please sign in to comment.