mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb: Make CSS 'An+B' parsing spec-compliant
Parsing this pattern from CSS tokens turns out to be slightly crazy, but thankfully well documented in the spec. The spec lists the cases in order of simple -> complicated, but this would cause problems in code, since `<n-dimension> <signed-.integer>` would never by reached, as `<n-dimension>` comes before. Instead, I have grouped them by their first token. Also renamed the NthChildPattern class to ANPlusBPattern, to match spec terminology.
This commit is contained in:
committed by
Andreas Kling
parent
8d0ff98eff
commit
6034fc0ee6
@@ -33,11 +33,15 @@ public:
|
||||
};
|
||||
Type type { Type::Invalid };
|
||||
|
||||
struct NthChildPattern {
|
||||
int step_size { 0 };
|
||||
int offset = { 0 };
|
||||
struct ANPlusBPattern {
|
||||
int step_size { 0 }; // "A"
|
||||
int offset = { 0 }; // "B"
|
||||
|
||||
static NthChildPattern parse(StringView const& args);
|
||||
static ANPlusBPattern parse(StringView const& args);
|
||||
String to_string() const
|
||||
{
|
||||
return String::formatted("{}n{:+}", step_size, offset);
|
||||
}
|
||||
};
|
||||
|
||||
struct PseudoClass {
|
||||
@@ -66,7 +70,7 @@ public:
|
||||
|
||||
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
|
||||
// Only used when "pseudo_class" is "NthChild" or "NthLastChild".
|
||||
NthChildPattern nth_child_pattern;
|
||||
ANPlusBPattern nth_child_pattern;
|
||||
|
||||
SelectorList not_selector {};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user