mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +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
|
@ -1081,9 +1081,9 @@ public:
|
|||
return simple_selector;
|
||||
}
|
||||
|
||||
Optional<CSS::Selector::ComplexSelector> parse_complex_selector()
|
||||
Optional<CSS::Selector::CompoundSelector> parse_complex_selector()
|
||||
{
|
||||
auto relation = CSS::Selector::ComplexSelector::Relation::Descendant;
|
||||
auto relation = CSS::Selector::Combinator::Descendant;
|
||||
|
||||
if (peek() == '{' || peek() == ',')
|
||||
return {};
|
||||
|
@ -1091,13 +1091,13 @@ public:
|
|||
if (is_combinator(peek())) {
|
||||
switch (peek()) {
|
||||
case '>':
|
||||
relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild;
|
||||
relation = CSS::Selector::Combinator::ImmediateChild;
|
||||
break;
|
||||
case '+':
|
||||
relation = CSS::Selector::ComplexSelector::Relation::AdjacentSibling;
|
||||
relation = CSS::Selector::Combinator::NextSibling;
|
||||
break;
|
||||
case '~':
|
||||
relation = CSS::Selector::ComplexSelector::Relation::GeneralSibling;
|
||||
relation = CSS::Selector::Combinator::SubsequentSibling;
|
||||
break;
|
||||
}
|
||||
consume_one();
|
||||
|
@ -1119,12 +1119,12 @@ public:
|
|||
if (simple_selectors.is_empty())
|
||||
return {};
|
||||
|
||||
return CSS::Selector::ComplexSelector { relation, move(simple_selectors) };
|
||||
return CSS::Selector::CompoundSelector { relation, move(simple_selectors) };
|
||||
}
|
||||
|
||||
void parse_selector()
|
||||
{
|
||||
Vector<CSS::Selector::ComplexSelector> complex_selectors;
|
||||
Vector<CSS::Selector::CompoundSelector> complex_selectors;
|
||||
|
||||
for (;;) {
|
||||
auto index_before = index;
|
||||
|
@ -1141,7 +1141,7 @@ public:
|
|||
|
||||
if (complex_selectors.is_empty())
|
||||
return;
|
||||
complex_selectors.first().relation = CSS::Selector::ComplexSelector::Relation::None;
|
||||
complex_selectors.first().combinator = CSS::Selector::Combinator::None;
|
||||
|
||||
current_rule.selectors.append(CSS::Selector::create(move(complex_selectors)));
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
|
||||
// FIXME: Bring this all in line with the spec. https://www.w3.org/TR/selectors-4/
|
||||
|
||||
Vector<Selector::ComplexSelector> selectors;
|
||||
Vector<Selector::CompoundSelector> selectors;
|
||||
|
||||
auto check_for_eof_or_whitespace = [&](T& current_value) -> bool {
|
||||
if (current_value.is(Token::Type::EndOfFile))
|
||||
|
@ -491,8 +491,8 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
return simple_selector;
|
||||
};
|
||||
|
||||
auto parse_complex_selector = [&]() -> Optional<Selector::ComplexSelector> {
|
||||
auto relation = Selector::ComplexSelector::Relation::Descendant;
|
||||
auto parse_complex_selector = [&]() -> Optional<Selector::CompoundSelector> {
|
||||
auto combinator = Selector::Combinator::Descendant;
|
||||
|
||||
tokens.skip_whitespace();
|
||||
|
||||
|
@ -500,13 +500,13 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
if (current_value.is(Token::Type::Delim)) {
|
||||
auto delim = ((Token)current_value).delim();
|
||||
if (delim == ">") {
|
||||
relation = Selector::ComplexSelector::Relation::ImmediateChild;
|
||||
combinator = Selector::Combinator::ImmediateChild;
|
||||
tokens.next_token();
|
||||
} else if (delim == "+") {
|
||||
relation = Selector::ComplexSelector::Relation::AdjacentSibling;
|
||||
combinator = Selector::Combinator::NextSibling;
|
||||
tokens.next_token();
|
||||
} else if (delim == "~") {
|
||||
relation = Selector::ComplexSelector::Relation::GeneralSibling;
|
||||
combinator = Selector::Combinator::SubsequentSibling;
|
||||
tokens.next_token();
|
||||
} else if (delim == "|") {
|
||||
tokens.next_token();
|
||||
|
@ -516,7 +516,7 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
return {};
|
||||
|
||||
if (next.is(Token::Type::Delim) && next.token().delim() == "|") {
|
||||
relation = Selector::ComplexSelector::Relation::Column;
|
||||
combinator = Selector::Combinator::Column;
|
||||
tokens.next_token();
|
||||
}
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
if (simple_selectors.is_empty())
|
||||
return {};
|
||||
|
||||
return Selector::ComplexSelector { relation, move(simple_selectors) };
|
||||
return Selector::CompoundSelector { combinator, move(simple_selectors) };
|
||||
};
|
||||
|
||||
for (;;) {
|
||||
|
@ -558,7 +558,7 @@ RefPtr<Selector> Parser::parse_single_selector(TokenStream<T>& tokens, bool is_r
|
|||
return {};
|
||||
|
||||
if (!is_relative)
|
||||
selectors.first().relation = Selector::ComplexSelector::Relation::None;
|
||||
selectors.first().combinator = Selector::Combinator::None;
|
||||
|
||||
return Selector::create(move(selectors));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue