style: Make a wrapper struct for extra matching data

No behavior change but we're about to add some extra field to it.

Differential Revision: https://phabricator.services.mozilla.com/D159850
This commit is contained in:
Emilio Cobos Álvarez 2022-10-20 14:24:35 +00:00 committed by Martin Robinson
parent b89c2be4bd
commit a62f6c78b2
3 changed files with 13 additions and 6 deletions

View file

@ -230,8 +230,16 @@ impl ::selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct SelectorImpl; pub struct SelectorImpl;
/// A set of extra data to carry along with the matching context, either for
/// selector-matching or invalidation.
#[derive(Debug, Default)]
pub struct ExtraMatchingData {
/// The invalidation data to invalidate doc-state pseudo-classes correctly.
pub invalidation_data: InvalidationMatchingData,
}
impl ::selectors::SelectorImpl for SelectorImpl { impl ::selectors::SelectorImpl for SelectorImpl {
type ExtraMatchingData = InvalidationMatchingData; type ExtraMatchingData = ExtraMatchingData;
type AttrValue = AtomString; type AttrValue = AtomString;
type Identifier = AtomIdent; type Identifier = AtomIdent;
type LocalName = AtomIdent; type LocalName = AtomIdent;

View file

@ -2109,7 +2109,7 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
); );
return false; return false;
} }
if context.extra_data.document_state.intersects(state_bit) { if context.extra_data.invalidation_data.document_state.intersects(state_bit) {
return !context.in_negation(); return !context.in_negation();
} }
self.document_state().contains(state_bit) self.document_state().contains(state_bit)

View file

@ -17,6 +17,7 @@ use style_traits::dom::DocumentState;
/// A struct holding the members necessary to invalidate document state /// A struct holding the members necessary to invalidate document state
/// selectors. /// selectors.
#[derive(Debug)]
pub struct InvalidationMatchingData { pub struct InvalidationMatchingData {
/// The document state that has changed, which makes it always match. /// The document state that has changed, which makes it always match.
pub document_state: DocumentState, pub document_state: DocumentState,
@ -43,7 +44,7 @@ impl<'a, E: TElement, I> DocumentStateInvalidationProcessor<'a, E, I> {
/// Creates a new DocumentStateInvalidationProcessor. /// Creates a new DocumentStateInvalidationProcessor.
#[inline] #[inline]
pub fn new(rules: I, document_states_changed: DocumentState, quirks_mode: QuirksMode) -> Self { pub fn new(rules: I, document_states_changed: DocumentState, quirks_mode: QuirksMode) -> Self {
let mut matching_context = MatchingContext::new_for_visited( let mut matching_context = MatchingContext::<'a, E::Impl>::new_for_visited(
MatchingMode::Normal, MatchingMode::Normal,
None, None,
None, None,
@ -52,9 +53,7 @@ impl<'a, E: TElement, I> DocumentStateInvalidationProcessor<'a, E, I> {
NeedsSelectorFlags::No, NeedsSelectorFlags::No,
); );
matching_context.extra_data = InvalidationMatchingData { matching_context.extra_data.invalidation_data.document_state = document_states_changed;
document_state: document_states_changed,
};
Self { Self {
rules, rules,