pub enum Component<Impl: SelectorImpl> {
Show 30 variants
LocalName(LocalName<Impl>),
ID(Impl::Identifier),
Class(Impl::Identifier),
AttributeInNoNamespaceExists {
local_name: Impl::LocalName,
local_name_lower: Impl::LocalName,
},
AttributeInNoNamespace {
local_name: Impl::LocalName,
operator: AttrSelectorOperator,
value: Impl::AttrValue,
case_sensitivity: ParsedCaseSensitivity,
},
AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>),
ExplicitUniversalType,
ExplicitAnyNamespace,
ExplicitNoNamespace,
DefaultNamespace(Impl::NamespaceUrl),
Namespace(Impl::NamespacePrefix, Impl::NamespaceUrl),
Negation(SelectorList<Impl>),
Root,
Empty,
Scope,
ImplicitScope,
ParentSelector,
Nth(NthSelectorData),
NthOf(NthOfSelectorData<Impl>),
NonTSPseudoClass(Impl::NonTSPseudoClass),
Slotted(Selector<Impl>),
Part(Box<[Impl::Identifier]>),
Host(Option<Selector<Impl>>),
Where(SelectorList<Impl>),
Is(SelectorList<Impl>),
Has(Box<[RelativeSelector<Impl>]>),
Invalid(Arc<String>),
PseudoElement(Impl::PseudoElement),
Combinator(Combinator),
RelativeSelectorAnchor,
}
Expand description
A CSS simple selector or combinator. We store both in the same enum for optimal packing and cache performance, see [1].
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973
Variants§
LocalName(LocalName<Impl>)
ID(Impl::Identifier)
Class(Impl::Identifier)
AttributeInNoNamespaceExists
AttributeInNoNamespace
AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>)
ExplicitUniversalType
ExplicitAnyNamespace
ExplicitNoNamespace
DefaultNamespace(Impl::NamespaceUrl)
Namespace(Impl::NamespacePrefix, Impl::NamespaceUrl)
Negation(SelectorList<Impl>)
Pseudo-classes
Root
Empty
Scope
ImplicitScope
:scope added implicitly into scoped rules (i.e. In @scope
) not
explicitly using :scope
or &
selectors.
https://drafts.csswg.org/css-cascade-6/#scoped-rules
Unlike the normal :scope
selector, this does not add any specificity.
See https://github.com/w3c/csswg-drafts/issues/10196
ParentSelector
Nth(NthSelectorData)
NthOf(NthOfSelectorData<Impl>)
NonTSPseudoClass(Impl::NonTSPseudoClass)
Slotted(Selector<Impl>)
The ::slotted() pseudo-element:
https://drafts.csswg.org/css-scoping/#slotted-pseudo
The selector here is a compound selector, that is, no combinators.
NOTE(emilio): This should support a list of selectors, but as of this writing no other browser does, and that allows them to put ::slotted() in the rule hash, so we do that too.
See https://github.com/w3c/csswg-drafts/issues/2158
Part(Box<[Impl::Identifier]>)
The ::part
pseudo-element.
https://drafts.csswg.org/css-shadow-parts/#part
Host(Option<Selector<Impl>>)
The :host
pseudo-class:
https://drafts.csswg.org/css-scoping/#host-selector
NOTE(emilio): This should support a list of selectors, but as of this writing no other browser does, and that allows them to put :host() in the rule hash, so we do that too.
See https://github.com/w3c/csswg-drafts/issues/2158
Where(SelectorList<Impl>)
The :where
pseudo-class.
https://drafts.csswg.org/selectors/#zero-matches
The inner argument is conceptually a SelectorList, but we move the selectors to the heap to keep Component small.
Is(SelectorList<Impl>)
The :is
pseudo-class.
https://drafts.csswg.org/selectors/#matches-pseudo
Same comment as above re. the argument.
Has(Box<[RelativeSelector<Impl>]>)
The :has
pseudo-class.
https://drafts.csswg.org/selectors/#has-pseudo
Same comment as above re. the argument.
Invalid(Arc<String>)
An invalid selector inside :is() / :where().
PseudoElement(Impl::PseudoElement)
An implementation-dependent pseudo-element selector.
Combinator(Combinator)
RelativeSelectorAnchor
Used only for relative selectors, which starts with a combinator (With an implied descendant combinator if not specified).
https://drafts.csswg.org/selectors-4/#typedef-relative-selector
Implementations§
source§impl<Impl: SelectorImpl> Component<Impl>
impl<Impl: SelectorImpl> Component<Impl>
sourcepub fn is_combinator(&self) -> bool
pub fn is_combinator(&self) -> bool
Returns true if this is a combinator.
sourcepub fn matches_featureless_host(&self) -> FeaturelessHostMatches
pub fn matches_featureless_host(&self) -> FeaturelessHostMatches
Returns if this component can match a featureless shadow host, and if so, via which selector.
sourcepub fn as_combinator(&self) -> Option<Combinator>
pub fn as_combinator(&self) -> Option<Combinator>
Returns the value as a combinator if applicable, None otherwise.
sourcefn matches_for_stateless_pseudo_element(&self) -> bool
fn matches_for_stateless_pseudo_element(&self) -> bool
Whether a given selector (to the right of a pseudo-element) should match for stateless pseudo-elements. Note that generally nothing matches for those, but since we have :not(), we still need to traverse nested selector lists.