mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:57:43 +00:00
LibWeb: Bring Selector terminology in line with the CSS spec
- CompoundSelector -> *deleted* - ComplexSelector -> CompoundSelector - Relation -> Combinator Our Selector is really a ComplexSelector, but only the Parser and SelectorEngine need to know that, so keeping it named Selector makes it more understandable for users. Our CompoundSelector is really a CompoundSelectorAndCombinator. Combining the two makes sense in our codebase, but the accurate name is so long that I think it makes the code less readable. Renamed some Combinators to also match the spec terminology: - AdjacentSibling -> NextSibling - GeneralSibling -> SubsequentSibling The previous names are somewhat ambiguous, so hopefully this is clearer.
This commit is contained in:
parent
ca436afeb5
commit
6ea5d03f43
6 changed files with 67 additions and 63 deletions
|
@ -15,6 +15,9 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
using SelectorList = NonnullRefPtrVector<class Selector>;
|
||||
|
||||
// This is a <complex-selector> in the spec. https://www.w3.org/TR/selectors-4/#complex
|
||||
class Selector : public RefCounted<Selector> {
|
||||
public:
|
||||
struct SimpleSelector {
|
||||
|
@ -65,7 +68,7 @@ public:
|
|||
// Only used when "pseudo_class" is "NthChild" or "NthLastChild".
|
||||
NthChildPattern nth_child_pattern;
|
||||
|
||||
NonnullRefPtrVector<Selector> not_selector {};
|
||||
SelectorList not_selector {};
|
||||
};
|
||||
PseudoClass pseudo_class;
|
||||
|
||||
|
@ -98,36 +101,37 @@ public:
|
|||
Attribute attribute;
|
||||
};
|
||||
|
||||
struct ComplexSelector {
|
||||
enum class Relation {
|
||||
None,
|
||||
ImmediateChild,
|
||||
Descendant,
|
||||
AdjacentSibling,
|
||||
GeneralSibling,
|
||||
Column,
|
||||
};
|
||||
Relation relation { Relation::None };
|
||||
|
||||
using CompoundSelector = Vector<SimpleSelector>;
|
||||
CompoundSelector compound_selector;
|
||||
enum class Combinator {
|
||||
None,
|
||||
ImmediateChild, // >
|
||||
Descendant, // <whitespace>
|
||||
NextSibling, // +
|
||||
SubsequentSibling, // ~
|
||||
Column, // ||
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Selector> create(Vector<ComplexSelector>&& complex_selectors)
|
||||
struct CompoundSelector {
|
||||
// Spec-wise, the <combinator> is not part of a <compound-selector>,
|
||||
// but it is more understandable to put them together.
|
||||
Combinator combinator { Combinator::None };
|
||||
Vector<SimpleSelector> simple_selectors;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Selector> create(Vector<CompoundSelector>&& compound_selectors)
|
||||
{
|
||||
return adopt_ref(*new Selector(move(complex_selectors)));
|
||||
return adopt_ref(*new Selector(move(compound_selectors)));
|
||||
}
|
||||
|
||||
~Selector();
|
||||
|
||||
Vector<ComplexSelector> const& complex_selectors() const { return m_complex_selectors; }
|
||||
Vector<CompoundSelector> const& compound_selectors() const { return m_compound_selectors; }
|
||||
|
||||
u32 specificity() const;
|
||||
|
||||
private:
|
||||
explicit Selector(Vector<ComplexSelector>&&);
|
||||
explicit Selector(Vector<CompoundSelector>&&);
|
||||
|
||||
Vector<ComplexSelector> m_complex_selectors;
|
||||
Vector<CompoundSelector> m_compound_selectors;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue