style: Implement selector matching for :nth-child(An+B of selector list) and :nth-last-child(An+B of selector list)

Since we have been using a single hash map to cache all :nth-child
indices (with no selector list), each different selector will need its
own cache.

As a side note, this patch does not address invalidation.

Differential Revision: https://phabricator.services.mozilla.com/D166266
This commit is contained in:
Zach Hoffman 2023-01-16 11:26:41 +00:00 committed by Martin Robinson
parent a973371cf2
commit 3076481c52
8 changed files with 223 additions and 71 deletions

View file

@ -13,6 +13,7 @@ use crate::stylist::CascadeData;
use selectors::matching::{
MatchingContext, MatchingMode, NeedsSelectorFlags, QuirksMode, VisitedHandlingMode,
};
use selectors::NthIndexCache;
use style_traits::dom::DocumentState;
/// A struct holding the members necessary to invalidate document state
@ -43,11 +44,16 @@ pub struct DocumentStateInvalidationProcessor<'a, E: TElement, I> {
impl<'a, E: TElement, I> DocumentStateInvalidationProcessor<'a, E, I> {
/// Creates a new DocumentStateInvalidationProcessor.
#[inline]
pub fn new(rules: I, document_states_changed: DocumentState, quirks_mode: QuirksMode) -> Self {
pub fn new(
rules: I,
document_states_changed: DocumentState,
nth_index_cache: &'a mut NthIndexCache,
quirks_mode: QuirksMode,
) -> Self {
let mut matching_context = MatchingContext::<'a, E::Impl>::new_for_visited(
MatchingMode::Normal,
None,
None,
nth_index_cache,
VisitedHandlingMode::AllLinksVisitedAndUnvisited,
quirks_mode,
NeedsSelectorFlags::No,