Bug 1886141 - Simplify return type of relative_selector_search_direction(). r=emilio

Instead of Option<ElementSelectorFlags>, it can be ElementSelectorFlags,
representing None as ElementSelectorFlags::empty().

No change in behavior.

Differential Revision: https://phabricator.services.mozilla.com/D205051
This commit is contained in:
Oriol Brufau 2024-03-19 13:20:46 +00:00
Родитель 38685b833f
Коммит c973ce585b
4 изменённых файлов: 20 добавлений и 31 удалений

Просмотреть файл

@ -906,7 +906,7 @@ pub trait TElement:
fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool;
/// Returns the search direction for relative selector invalidation, if it is on the search path.
fn relative_selector_search_direction(&self) -> Option<ElementSelectorFlags>;
fn relative_selector_search_direction(&self) -> ElementSelectorFlags;
}
/// TNode and TElement aren't Send because we want to be careful and explicit

Просмотреть файл

@ -1794,17 +1794,17 @@ impl<'le> TElement for GeckoElement<'le> {
self.as_node().selector_flags() & node_flags == node_flags
}
fn relative_selector_search_direction(&self) -> Option<ElementSelectorFlags> {
fn relative_selector_search_direction(&self) -> ElementSelectorFlags {
use crate::gecko_bindings::structs::NodeSelectorFlags;
let flags = self.as_node().selector_flags();
if (flags & NodeSelectorFlags::RelativeSelectorSearchDirectionAncestorSibling.0) != 0 {
Some(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING)
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING
} else if (flags & NodeSelectorFlags::RelativeSelectorSearchDirectionAncestor.0) != 0 {
Some(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR)
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR
} else if (flags & NodeSelectorFlags::RelativeSelectorSearchDirectionSibling.0) != 0 {
Some(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_SIBLING)
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_SIBLING
} else {
None
ElementSelectorFlags::empty()
}
}
}

Просмотреть файл

@ -53,12 +53,12 @@ impl DomMutationOperation {
fn accept<E: TElement>(&self, d: &Dependency, e: E) -> bool {
match self {
Self::Insert | Self::Append | Self::Remove => {
e.relative_selector_search_direction().is_some()
!e.relative_selector_search_direction().is_empty()
},
// `:has(+ .a + .b)` with `.anchor + .a + .remove + .b` - `.a` would be present
// in the search path.
Self::SideEffectPrevSibling => {
e.relative_selector_search_direction().is_some() &&
!e.relative_selector_search_direction().is_empty() &&
d.right_combinator_is_next_sibling()
},
// If an element is being removed and would cause next-sibling match to happen,
@ -782,11 +782,7 @@ where
/// Is this element in the direction of the given relative selector search path?
fn in_search_direction(element: &E, desired: ElementSelectorFlags) -> bool {
if let Some(direction) = element.relative_selector_search_direction() {
direction.intersects(desired)
} else {
false
}
element.relative_selector_search_direction().intersects(desired)
}
/// Handle a potential relative selector anchor.
@ -1145,7 +1141,7 @@ where
dep: &'a Dependency,
) {
debug_assert!(dep.parent.is_some(), "Orphaned inners selector?");
if element.relative_selector_search_direction().is_none() {
if element.relative_selector_search_direction().is_empty() {
return;
}
self.invalidations.push((

Просмотреть файл

@ -6968,18 +6968,15 @@ fn inherit_relative_selector_search_direction(
) -> ElementSelectorFlags {
let mut inherited = ElementSelectorFlags::empty();
if let Some(parent) = parent {
if let Some(direction) = parent.relative_selector_search_direction() {
inherited |= direction
.intersection(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR);
}
inherited |= parent
.relative_selector_search_direction()
.intersection(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR);
}
if let Some(sibling) = prev_sibling {
if let Some(direction) = sibling.relative_selector_search_direction() {
// Inherit both, for e.g. a sibling with `:has(~.sibling .descendant)`
inherited |= direction.intersection(
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING,
);
}
// Inherit both, for e.g. a sibling with `:has(~.sibling .descendant)`
inherited |= sibling.relative_selector_search_direction().intersection(
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_ANCESTOR_SIBLING,
);
}
inherited
}
@ -7309,13 +7306,9 @@ pub extern "C" fn Servo_StyleSet_MaybeInvalidateRelativeSelectorForInsertion(
) {
(Some(prev_sibling), Some(next_sibling)) => 'sibling: {
// If the prev sibling is not on the sibling search path, skip.
if prev_sibling
if !prev_sibling
.relative_selector_search_direction()
.map_or(true, |direction| {
!direction.intersects(
ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_SIBLING,
)
})
.intersects(ElementSelectorFlags::RELATIVE_SELECTOR_SEARCH_DIRECTION_SIBLING)
{
break 'sibling;
}
@ -7434,7 +7427,7 @@ pub extern "C" fn Servo_StyleSet_MaybeInvalidateRelativeSelectorForRemoval(
// This element was in-tree, so we can safely say that if it was not on
// the relative selector search path, its removal will not invalidate any
// relative selector.
if element.relative_selector_search_direction().is_none() {
if element.relative_selector_search_direction().is_empty() {
return;
}
let following_node = following_node.map(GeckoNode);