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.
This commit is contained in:
Bobby Holley 2016-06-23 14:13:50 -07:00
parent 7947afc699
commit 96af00fbb9
4 changed files with 20 additions and 4 deletions

View file

@ -386,6 +386,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
self.element.get_state_for_layout() self.element.get_state_for_layout()
} }
#[inline]
fn has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool {
self.get_attr(namespace, attr).is_some()
}
#[inline] #[inline]
fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> { fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> {
unsafe { unsafe {

View file

@ -207,6 +207,8 @@ pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynt
fn get_state(&self) -> ElementState; 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>; fn get_attr<'a>(&'a self, namespace: &Namespace, attr: &Atom) -> Option<&'a str>;
/// Properly marks nodes as dirty in response to restyle hints. /// Properly marks nodes as dirty in response to restyle hints.

View file

@ -34,7 +34,7 @@ fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &
for attribute_info in &common_style_affecting_attributes() { for attribute_info in &common_style_affecting_attributes() {
match attribute_info.mode { match attribute_info.mode {
CommonStyleAffectingAttributeMode::IsPresent(flag) => { CommonStyleAffectingAttributeMode::IsPresent(flag) => {
if element.get_attr(&ns!(), &attribute_info.atom).is_some() { if element.has_attr(&ns!(), &attribute_info.atom) {
flags.insert(flag) flags.insert(flag)
} }
} }
@ -296,7 +296,7 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
match attribute_info.mode { match attribute_info.mode {
CommonStyleAffectingAttributeMode::IsPresent(flag) => { CommonStyleAffectingAttributeMode::IsPresent(flag) => {
if self.common_style_affecting_attributes.contains(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 return false
} }
} }
@ -320,7 +320,7 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
} }
for attribute_name in &rare_style_affecting_attributes() { 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 return false
} }
} }
@ -606,7 +606,7 @@ pub trait ElementMatchMethods : TElement
if self.style_attribute().is_some() { if self.style_attribute().is_some() {
return StyleSharingResult::CannotShare return StyleSharingResult::CannotShare
} }
if self.get_attr(&ns!(), &atom!("id")).is_some() { if self.has_attr(&ns!(), &atom!("id")) {
return StyleSharingResult::CannotShare return StyleSharingResult::CannotShare
} }

View file

@ -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] #[inline]
fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> { fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> {
unsafe { unsafe {