#[repr(transparent)]pub struct Selector<Impl: SelectorImpl>(ThinArc<SpecificityAndFlags, Component<Impl>>);
Expand description
A Selector stores a sequence of simple selectors and combinators. The iterator classes allow callers to iterate at either the raw sequence level or at the level of sequences of simple selectors separated by combinators. Most callers want the higher-level iterator.
We store compound selectors internally right-to-left (in matching order). Additionally, we invert the order of top-level compound selectors so that each one matches left-to-right. This is because matching namespace, local name, id, and class are all relatively cheap, whereas matching pseudo-classes might be expensive (depending on the pseudo-class). Since authors tend to put the pseudo-classes on the right, it’s faster to start matching on the left.
This reordering doesn’t change the semantics of selector matching, and we handle it in to_css to make it invisible to serialization.
Tuple Fields§
§0: ThinArc<SpecificityAndFlags, Component<Impl>>
Implementations§
source§impl<Impl: SelectorImpl> Selector<Impl>
impl<Impl: SelectorImpl> Selector<Impl>
sourcepub fn mark_as_intentionally_leaked(&self)
pub fn mark_as_intentionally_leaked(&self)
See Arc::mark_as_intentionally_leaked
fn ampersand() -> Self
fn scope() -> Self
pub fn specificity(&self) -> u32
pub(crate) fn flags(&self) -> SelectorFlags
pub fn has_pseudo_element(&self) -> bool
pub fn has_parent_selector(&self) -> bool
pub fn has_scope_selector(&self) -> bool
pub fn is_slotted(&self) -> bool
pub fn is_part(&self) -> bool
pub fn parts(&self) -> Option<&[Impl::Identifier]>
pub fn pseudo_element(&self) -> Option<&Impl::PseudoElement>
sourcepub fn is_universal(&self) -> bool
pub fn is_universal(&self) -> bool
Whether this selector (pseudo-element part excluded) matches every element.
Used for “pre-computed” pseudo-elements in components/style/stylist.rs
sourcepub fn iter(&self) -> SelectorIter<'_, Impl> ⓘ
pub fn iter(&self) -> SelectorIter<'_, Impl> ⓘ
Returns an iterator over this selector in matching order (right-to-left). When a combinator is reached, the iterator will return None, and next_sequence() may be called to continue to the next sequence.
sourcepub fn iter_skip_relative_selector_anchor(&self) -> SelectorIter<'_, Impl> ⓘ
pub fn iter_skip_relative_selector_anchor(&self) -> SelectorIter<'_, Impl> ⓘ
Same as iter()
, but skips RelativeSelectorAnchor
and its associated combinator.
sourcepub fn matches_featureless_host_selector_or_pseudo_element(
&self,
) -> FeaturelessHostMatches
pub fn matches_featureless_host_selector_or_pseudo_element( &self, ) -> FeaturelessHostMatches
Whether this selector matches a featureless shadow host, with no combinators to the left, and optionally has a pseudo-element to the right.
sourcepub fn iter_from(&self, offset: usize) -> SelectorIter<'_, Impl> ⓘ
pub fn iter_from(&self, offset: usize) -> SelectorIter<'_, Impl> ⓘ
Returns an iterator over this selector in matching order (right-to-left), skipping the rightmost |offset| Components.
sourcepub fn combinator_at_match_order(&self, index: usize) -> Combinator
pub fn combinator_at_match_order(&self, index: usize) -> Combinator
Returns the combinator at index index
(zero-indexed from the right),
or panics if the component is not a combinator.
sourcepub fn iter_raw_match_order(&self) -> Iter<'_, Component<Impl>>
pub fn iter_raw_match_order(&self) -> Iter<'_, Component<Impl>>
Returns an iterator over the entire sequence of simple selectors and combinators, in matching order (from right to left).
sourcepub fn combinator_at_parse_order(&self, index: usize) -> Combinator
pub fn combinator_at_parse_order(&self, index: usize) -> Combinator
Returns the combinator at index index
(zero-indexed from the left),
or panics if the component is not a combinator.
sourcepub fn iter_raw_parse_order_from(
&self,
offset: usize,
) -> Rev<Iter<'_, Component<Impl>>>
pub fn iter_raw_parse_order_from( &self, offset: usize, ) -> Rev<Iter<'_, Component<Impl>>>
Returns an iterator over the sequence of simple selectors and
combinators, in parse order (from left to right), starting from
offset
.
sourcepub(crate) fn from_vec(
vec: Vec<Component<Impl>>,
specificity: u32,
flags: SelectorFlags,
) -> Self
pub(crate) fn from_vec( vec: Vec<Component<Impl>>, specificity: u32, flags: SelectorFlags, ) -> Self
Creates a Selector from a vec of Components, specified in parse order. Used in tests.
fn into_data(self) -> ThinArc<SpecificityAndFlags, Component<Impl>>
pub fn replace_parent_selector(&self, parent: &SelectorList<Impl>) -> Self
sourcepub fn thin_arc_heap_ptr(&self) -> *const c_void
pub fn thin_arc_heap_ptr(&self) -> *const c_void
Returns the address on the heap of the ThinArc for memory reporting.
sourcepub fn visit<V>(&self, visitor: &mut V) -> boolwhere
V: SelectorVisitor<Impl = Impl>,
pub fn visit<V>(&self, visitor: &mut V) -> boolwhere
V: SelectorVisitor<Impl = Impl>,
Traverse selector components inside self
.
Implementations of this method should call SelectorVisitor
methods
or other impls of Visit
as appropriate based on the fields of Self
.
A return value of false
indicates terminating the traversal.
It should be propagated with an early return.
On the contrary, true
indicates that all fields of self
have been traversed:
if !visitor.visit_simple_selector(&self.some_simple_selector) {
return false;
}
if !self.some_component.visit(visitor) {
return false;
}
true
sourcepub fn parse<'i, 't, P>(
parser: &P,
input: &mut CssParser<'i, 't>,
) -> Result<Self, ParseError<'i, P::Error>>where
P: Parser<'i, Impl = Impl>,
pub fn parse<'i, 't, P>(
parser: &P,
input: &mut CssParser<'i, 't>,
) -> Result<Self, ParseError<'i, P::Error>>where
P: Parser<'i, Impl = Impl>,
Parse a selector, without any pseudo-element.
pub fn new_invalid(s: &str) -> Self
sourcepub fn is_rightmost(&self, offset: usize) -> bool
pub fn is_rightmost(&self, offset: usize) -> bool
Is the compound starting at the offset the subject compound, or referring to its pseudo-element?