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

@ -14,7 +14,7 @@ use crate::values::AtomIdent;
use selectors::attr::CaseSensitivity;
use selectors::matching::{self, MatchingContext, MatchingMode, NeedsSelectorFlags};
use selectors::parser::{Combinator, Component, LocalName, SelectorImpl};
use selectors::{Element, NthIndexCache, SelectorList};
use selectors::{Element, SelectorList};
use smallvec::SmallVec;
/// <https://dom.spec.whatwg.org/#dom-element-matches>
@ -26,10 +26,12 @@ pub fn element_matches<E>(
where
E: Element,
{
let mut nth_index_cache = Default::default();
let mut context = MatchingContext::new(
MatchingMode::Normal,
None,
None,
&mut nth_index_cache,
quirks_mode,
NeedsSelectorFlags::No,
);
@ -47,12 +49,12 @@ pub fn element_closest<E>(
where
E: Element,
{
let mut nth_index_cache = NthIndexCache::default();
let mut nth_index_cache = Default::default();
let mut context = MatchingContext::new(
MatchingMode::Normal,
None,
Some(&mut nth_index_cache),
&mut nth_index_cache,
quirks_mode,
NeedsSelectorFlags::No,
);
@ -621,13 +623,13 @@ pub fn query_selector<E, Q>(
{
use crate::invalidation::element::invalidator::TreeStyleInvalidator;
let mut nth_index_cache = Default::default();
let quirks_mode = root.owner_doc().quirks_mode();
let mut nth_index_cache = NthIndexCache::default();
let mut matching_context = MatchingContext::new(
MatchingMode::Normal,
None,
Some(&mut nth_index_cache),
&mut nth_index_cache,
quirks_mode,
NeedsSelectorFlags::No,
);