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

This makes us actually respect the grammar and nets us a couple
extra WPT passes in the parsing section.
This commit is contained in:
Psychpsyo 2025-05-03 21:05:11 +02:00 committed by Tim Ledbetter
commit 7c36a82129
Notes: github-actions[bot] 2025-05-04 21:25:27 +00:00
5 changed files with 86 additions and 11 deletions

View file

@ -345,6 +345,7 @@ private:
};
RefPtr<PositionStyleValue const> parse_position_value(TokenStream<ComponentValue>&, PositionParsingMode = PositionParsingMode::Normal);
RefPtr<CSSStyleValue const> parse_filter_value_list_value(TokenStream<ComponentValue>&);
RefPtr<CSSStyleValue const> parse_contain_value(TokenStream<ComponentValue>&);
RefPtr<StringStyleValue const> parse_opentype_tag_value(TokenStream<ComponentValue>&);
RefPtr<FontSourceStyleValue const> parse_font_source_value(TokenStream<ComponentValue>&);

View file

@ -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);
}
}

View file

@ -1110,7 +1110,6 @@
]
},
"contain": {
"__comment": "FIXME: Some values of contain need to be mutually exclusive. The grammar this should adhere to is 'none | strict | content | [ [size | inline-size] || layout || style || paint ]'.",
"affects-stacking-context": true,
"animation-type": "none",
"inherited": false,

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 15 tests
8 Pass
7 Fail
13 Pass
2 Fail
Pass Property contain value 'none'
Pass Property contain value 'strict'
Pass Property contain value 'content'
@ -11,11 +11,11 @@ Pass Property contain value 'size'
Pass Property contain value 'layout'
Pass Property contain value 'style'
Pass Property contain value 'paint'
Fail Property contain value 'size layout'
Fail Property contain value 'style paint'
Pass Property contain value 'size layout'
Pass Property contain value 'style paint'
Fail Property contain value 'style layout paint'
Fail Property contain value 'size style layout paint'
Fail Property contain value 'size layout paint'
Fail Property contain value 'layout paint'
Pass Property contain value 'size layout paint'
Pass Property contain value 'layout paint'
Pass Property contain value 'inline-size'
Fail Property contain value 'inline-size layout style paint'
Pass Property contain value 'inline-size layout style paint'

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 13 tests
8 Pass
5 Fail
9 Pass
4 Fail
Pass e.style['contain'] = "none" should set the property value
Pass e.style['contain'] = "strict" should set the property value
Pass e.style['contain'] = "content" should set the property value
@ -13,7 +13,7 @@ Pass e.style['contain'] = "style" should set the property value
Pass e.style['contain'] = "paint" should set the property value
Fail e.style['contain'] = "layout size" should set the property value
Fail e.style['contain'] = "paint style" should set the property value
Fail e.style['contain'] = "layout style paint" should set the property value
Pass e.style['contain'] = "layout style paint" should set the property value
Fail e.style['contain'] = "layout paint style size" should set the property value
Pass e.style['contain'] = "inline-size" should set the property value
Fail e.style['contain'] = "layout inline-size" should set the property value