mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-06 00:51:51 +00:00
LibWeb: Improve parsing for the CSS contain property
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This makes us actually respect the grammar and nets us a couple extra WPT passes in the parsing section.
This commit is contained in:
parent
1c075d6039
commit
7c36a82129
Notes:
github-actions[bot]
2025-05-04 21:25:27 +00:00
Author: https://github.com/Psychpsyo
Commit: 7c36a82129
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4579
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 86 additions and 11 deletions
|
@ -700,6 +700,10 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue const>> Parser::parse_css_value
|
|||
if (auto parsed_value = parse_scale_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
case PropertyID::Contain:
|
||||
if (auto parsed_value = parse_contain_value(tokens); parsed_value && !tokens.has_next_token())
|
||||
return parsed_value.release_nonnull();
|
||||
return ParseError::SyntaxError;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -4609,4 +4613,75 @@ RefPtr<CSSStyleValue const> Parser::parse_filter_value_list_value(TokenStream<Co
|
|||
return FilterValueListStyleValue::create(move(filter_value_list));
|
||||
}
|
||||
|
||||
RefPtr<CSSStyleValue const> Parser::parse_contain_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// none | strict | content | [ [size | inline-size] || layout || style || paint ]
|
||||
auto transaction = tokens.begin_transaction();
|
||||
tokens.discard_whitespace();
|
||||
|
||||
// none
|
||||
if (auto none = parse_all_as_single_keyword_value(tokens, Keyword::None)) {
|
||||
transaction.commit();
|
||||
return none;
|
||||
}
|
||||
|
||||
// strict
|
||||
if (auto strict = parse_all_as_single_keyword_value(tokens, Keyword::Strict)) {
|
||||
transaction.commit();
|
||||
return strict;
|
||||
}
|
||||
|
||||
// content
|
||||
if (auto content = parse_all_as_single_keyword_value(tokens, Keyword::Content)) {
|
||||
transaction.commit();
|
||||
return content;
|
||||
}
|
||||
|
||||
// [ [size | inline-size] || layout || style || paint ]
|
||||
if (!tokens.has_next_token())
|
||||
return {};
|
||||
|
||||
bool has_size = false;
|
||||
bool has_layout = false;
|
||||
bool has_style = false;
|
||||
bool has_paint = false;
|
||||
|
||||
StyleValueVector containments;
|
||||
while (tokens.has_next_token()) {
|
||||
tokens.discard_whitespace();
|
||||
auto keyword = parse_keyword_value(tokens);
|
||||
if (!keyword)
|
||||
return {};
|
||||
switch (keyword->to_keyword()) {
|
||||
case Keyword::Size:
|
||||
case Keyword::InlineSize:
|
||||
if (has_size)
|
||||
return {};
|
||||
has_size = true;
|
||||
break;
|
||||
case Keyword::Layout:
|
||||
if (has_layout)
|
||||
return {};
|
||||
has_layout = true;
|
||||
break;
|
||||
case Keyword::Style:
|
||||
if (has_style)
|
||||
return {};
|
||||
has_style = true;
|
||||
break;
|
||||
case Keyword::Paint:
|
||||
if (has_paint)
|
||||
return {};
|
||||
has_paint = true;
|
||||
break;
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
containments.append(*keyword);
|
||||
}
|
||||
transaction.commit();
|
||||
|
||||
return StyleValueList::create(move(containments), StyleValueList::Separator::Space);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue