Add attr_equals to TElement.

Same reasons as the previous patch.
This commit is contained in:
Bobby Holley 2016-06-23 15:36:25 -07:00
parent 96af00fbb9
commit 364c8e2976
4 changed files with 26 additions and 16 deletions

View file

@ -391,6 +391,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
self.get_attr(namespace, attr).is_some() self.get_attr(namespace, attr).is_some()
} }
#[inline]
fn attr_equals(&self, namespace: &Namespace, attr: &Atom, val: &Atom) -> bool {
self.get_attr(namespace, attr).map_or(false, |x| x == val)
}
#[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

@ -208,6 +208,7 @@ 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 has_attr(&self, namespace: &Namespace, attr: &Atom) -> bool;
fn attr_equals(&self, namespace: &Namespace, attr: &Atom, value: &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>;

View file

@ -39,11 +39,9 @@ fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &
} }
} }
CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => { CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => {
match element.get_attr(&ns!(), &attribute_info.atom) { let atom = Atom::from(target_value); // FIXME(bholley): This goes away in the next patch.
Some(element_value) if element_value == target_value => { if element.attr_equals(&ns!(), &attribute_info.atom, &atom) {
flags.insert(flag) flags.insert(flag)
}
_ => {}
} }
} }
} }
@ -301,19 +299,14 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
} }
} }
CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => { CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => {
match element.get_attr(&ns!(), &attribute_info.atom) { let atom = Atom::from(target_value); // FIXME(bholley): This goes away in the next patch.
Some(ref element_value) if self.common_style_affecting_attributes let contains = self.common_style_affecting_attributes.contains(flag);
.contains(flag) && if element.has_attr(&ns!(), &attribute_info.atom) {
*element_value != target_value => { if !contains || !element.attr_equals(&ns!(), &attribute_info.atom, &atom) {
return false return false
} }
Some(_) if !self.common_style_affecting_attributes.contains(flag) => { } else if contains {
return false return false
}
None if self.common_style_affecting_attributes.contains(flag) => {
return false
}
_ => {}
} }
} }
} }

View file

@ -369,6 +369,17 @@ impl<'le> TElement for GeckoElement<'le> {
} }
} }
#[inline]
fn attr_equals(&self, namespace: &Namespace, attr: &Atom, val: &Atom) -> bool {
unsafe {
bindings::Gecko_AttrEquals(self.element,
namespace.0.as_ptr(),
attr.as_ptr(),
val.as_ptr(),
/* ignoreCase = */ false)
}
}
#[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 {