diff options
Diffstat (limited to 'components/selectors/parser.rs')
-rw-r--r-- | components/selectors/parser.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 39024502b4d..b485cae36de 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -103,6 +103,10 @@ macro_rules! with_all_bounds { /// pseudo-elements type PseudoElement: $($CommonBounds)* + PseudoElement<Impl = Self>; + + /// Returns whether the given pseudo class is :active or :hover. + #[inline] + fn is_active_or_hover(pseudo_class: &Self::NonTSPseudoClass) -> bool; } } } @@ -427,7 +431,7 @@ impl<Impl: SelectorImpl> Selector<Impl> { pub fn iter_from(&self, offset: usize) -> SelectorIter<Impl> { // Note: selectors are stored left-to-right but logical order is right-to-left. - let iter = self.0.slice[..(self.0.slice.len() - offset)].iter().rev(); + let iter = self.0.slice[..(self.len() - offset)].iter().rev(); SelectorIter { iter: iter, next_combinator: None, @@ -451,6 +455,11 @@ impl<Impl: SelectorImpl> Selector<Impl> { let header = HeaderWithLength::new(SpecificityAndFlags(specificity_and_flags), vec.len()); Selector(Arc::into_thin(Arc::from_header_and_iter(header, vec.into_iter()))) } + + /// Returns count of simple selectors and combinators in the Selector. + pub fn len(&self) -> usize { + self.0.slice.len() + } } #[derive(Clone)] @@ -465,6 +474,11 @@ impl<'a, Impl: 'a + SelectorImpl> SelectorIter<'a, Impl> { pub fn next_sequence(&mut self) -> Option<Combinator> { self.next_combinator.take() } + + /// Returns remaining count of the simple selectors and combinators in the Selector. + pub fn selector_length(&self) -> usize { + self.iter.len() + } } impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> { @@ -1711,6 +1725,12 @@ pub mod tests { type BorrowedNamespaceUrl = DummyAtom; type NonTSPseudoClass = PseudoClass; type PseudoElement = PseudoElement; + + #[inline] + fn is_active_or_hover(pseudo_class: &Self::NonTSPseudoClass) -> bool { + matches!(*pseudo_class, PseudoClass::Active | + PseudoClass::Hover) + } } #[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] |