Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::css::Selector Struct Reference

A top-level Selector, which is a list of ComplexSelector. More...

#include "donner/css/Selector.h"

Public Member Functions

 Selector ()
 Constructor.
 ~Selector () noexcept
 Destructor.
 Selector (Selector &&) noexcept
 Move constructor.
Selectoroperator= (Selector &&) noexcept
 Move assignment operator.
 Selector (const Selector &)
 Copy constructor.
Selectoroperator= (const Selector &)
 Copy assignment operator.
void collectAttributeSelectorNames (std::vector< RcString > &outNames, bool &outMatchesAnyName) const
 Collect the attribute names referenced by every attribute selector in this selector.
Specificity::ABC maxSpecificity () const
 Get the max specificity of all ComplexSelectors in the Selector.
template<ElementLike T>
SelectorMatchResult matches (const T &targetElement, const SelectorMatchOptions< T > &options=SelectorMatchOptions< T >()) const
 Match an element against a Selector.

Public Attributes

std::vector< ComplexSelectorentries
 The list of ComplexSelector entries that compose this selector.

Friends

std::ostream & operator<< (std::ostream &os, const Selector &obj)
 Ostream output operator for Selector, prints a debug representation of the selector, e.g. Selector(div, .class, #id).

Detailed Description

A top-level Selector, which is a list of ComplexSelector.

This represents the prelude in front of any CSS rule, e.g. div.foo > span#bar, which would be a single ComplexSelector. For a comma-separated list, such as div.foo > span#bar, span#bar, this would be a Selector with two ComplexSelector entries.

Member Function Documentation

◆ collectAttributeSelectorNames()

void donner::css::Selector::collectAttributeSelectorNames ( std::vector< RcString > & outNames,
bool & outMatchesAnyName ) const

Collect the attribute names referenced by every attribute selector in this selector.

Recurses into functional pseudo-classes that carry their own selector list, such as :is(), :not(), :has() and :nth-child(An+B of S), so a nested [attr] is not missed.

Namespaces are ignored: only the local name is collected, which over-approximates [ns|attr] to [attr]. Callers use this to decide whether writing an attribute can change selector matching, where over-approximating is the safe direction.

Parameters
outNamesReceives each distinct local name found, appended to any existing contents.
outMatchesAnyNameSet to true if a selector uses a wildcard local name, meaning any attribute write can change matching. No CSS syntax produces this today; it is a fail-safe.

◆ matches()

template<ElementLike T>
SelectorMatchResult donner::css::Selector::matches ( const T & targetElement,
const SelectorMatchOptions< T > & options = SelectorMatchOptions<T>() ) const
inline

Match an element against a Selector.

Template Parameters
TA type that fulfills the ElementLike concept, to enable traversing the tree to match the selector.
Parameters
targetElementElement to match against.
optionsOptions to control matching.
Returns
true if any ComplexSelector in the Selector matches the given element.

The documentation for this struct was generated from the following file: