mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add attr_equals to TElement.
Same reasons as the previous patch.
This commit is contained in:
parent
96af00fbb9
commit
364c8e2976
4 changed files with 26 additions and 16 deletions
|
@ -391,6 +391,11 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
|||
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]
|
||||
fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str> {
|
||||
unsafe {
|
||||
|
|
|
@ -208,6 +208,7 @@ pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynt
|
|||
fn get_state(&self) -> ElementState;
|
||||
|
||||
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>;
|
||||
|
||||
|
|
|
@ -39,12 +39,10 @@ fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &
|
|||
}
|
||||
}
|
||||
CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => {
|
||||
match element.get_attr(&ns!(), &attribute_info.atom) {
|
||||
Some(element_value) if element_value == target_value => {
|
||||
let atom = Atom::from(target_value); // FIXME(bholley): This goes away in the next patch.
|
||||
if element.attr_equals(&ns!(), &attribute_info.atom, &atom) {
|
||||
flags.insert(flag)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,20 +299,15 @@ impl<C: ComputedValues> StyleSharingCandidate<C> {
|
|||
}
|
||||
}
|
||||
CommonStyleAffectingAttributeMode::IsEqual(target_value, flag) => {
|
||||
match element.get_attr(&ns!(), &attribute_info.atom) {
|
||||
Some(ref element_value) if self.common_style_affecting_attributes
|
||||
.contains(flag) &&
|
||||
*element_value != target_value => {
|
||||
let atom = Atom::from(target_value); // FIXME(bholley): This goes away in the next patch.
|
||||
let contains = self.common_style_affecting_attributes.contains(flag);
|
||||
if element.has_attr(&ns!(), &attribute_info.atom) {
|
||||
if !contains || !element.attr_equals(&ns!(), &attribute_info.atom, &atom) {
|
||||
return false
|
||||
}
|
||||
Some(_) if !self.common_style_affecting_attributes.contains(flag) => {
|
||||
} else if contains {
|
||||
return false
|
||||
}
|
||||
None if self.common_style_affecting_attributes.contains(flag) => {
|
||||
return false
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
fn get_attr<'a>(&'a self, namespace: &Namespace, name: &Atom) -> Option<&'a str> {
|
||||
unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue