diff options
author | David Shin <dshin@mozilla.com> | 2023-03-07 18:04:27 +0000 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-11-21 15:36:35 +0100 |
commit | f7b29ac4329d697c3aedc79428a1230fb7f9ee6b (patch) | |
tree | f15982c4434c691a90e4d39b8127b73c00fed09f /components/selectors/context.rs | |
parent | b6db94bdf5fdb59550380a0b0b3f418afb01965f (diff) | |
download | servo-f7b29ac4329d697c3aedc79428a1230fb7f9ee6b.tar.gz servo-f7b29ac4329d697c3aedc79428a1230fb7f9ee6b.zip |
style: Parsing for relative selectors in `:has()`
Differential Revision: https://phabricator.services.mozilla.com/D171358
Diffstat (limited to 'components/selectors/context.rs')
-rw-r--r-- | components/selectors/context.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/components/selectors/context.rs b/components/selectors/context.rs index ffb97c94e8b..1bdad188e81 100644 --- a/components/selectors/context.rs +++ b/components/selectors/context.rs @@ -147,6 +147,9 @@ where /// Extra implementation-dependent matching data. pub extra_data: Impl::ExtraMatchingData<'a>, + /// The current element we're anchoring on for evaluating the relative selector. + current_relative_selector_anchor: Option<OpaqueElement>, + quirks_mode: QuirksMode, needs_selector_flags: NeedsSelectorFlags, classes_and_ids_case_sensitivity: CaseSensitivity, @@ -198,6 +201,7 @@ where in_negation: false, pseudo_element_matching_fn: None, extra_data: Default::default(), + current_relative_selector_anchor: None, _impl: ::std::marker::PhantomData, } } @@ -318,4 +322,25 @@ where pub fn shadow_host(&self) -> Option<OpaqueElement> { self.current_host } + + /// Runs F with a deeper nesting level, with the given element as the anchor, + /// for a :has(...) selector, for example. + #[inline] + pub fn nest_for_relative_selector<F, R>(&mut self, anchor: OpaqueElement, f: F) -> R + where + F: FnOnce(&mut Self) -> R, + { + // TODO(dshin): Nesting should be rejected at parse time. + let original_relative_selector_anchor = self.current_relative_selector_anchor.take(); + self.current_relative_selector_anchor = Some(anchor); + let result = self.nest(f); + self.current_relative_selector_anchor = original_relative_selector_anchor; + result + } + + /// Returns the current anchor element to evaluate the relative selector against. + #[inline] + pub fn relative_selector_anchor(&self) -> Option<OpaqueElement> { + self.current_relative_selector_anchor + } } |