mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
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:
parent
7947afc699
commit
96af00fbb9
4 changed files with 20 additions and 4 deletions
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue