diff --git a/servo/components/style/dom.rs b/servo/components/style/dom.rs index 358d78884508..606842b52df6 100644 --- a/servo/components/style/dom.rs +++ b/servo/components/style/dom.rs @@ -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; + fn relative_selector_search_direction(&self) -> ElementSelectorFlags; } /// TNode and TElement aren't Send because we want to be careful and explicit diff --git a/servo/components/style/gecko/wrapper.rs b/servo/components/style/gecko/wrapper.rs index d715ae97af5c..80349cdc80db 100644 --- a/servo/components/style/gecko/wrapper.rs +++ b/servo/components/style/gecko/wrapper.rs @@ -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 { + 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() } } } diff --git a/servo/components/style/invalidation/element/relative_selector.rs b/servo/components/style/invalidation/element/relative_selector.rs index ccb48e349f41..da1b29de256b 100644 --- a/servo/components/style/invalidation/element/relative_selector.rs +++ b/servo/components/style/invalidation/element/relative_selector.rs @@ -53,12 +53,12 @@ impl DomMutationOperation { fn accept(&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(( diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index 379893e7f899..6cb87c38bfc9 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -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);