From 96d8bed35bf7ae09a7538120ad1785449ba6dda0 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 17 Jun 2025 06:19:30 +0100 Subject: [PATCH] LibWeb/CSS: Serialize `contain` values in canonical order --- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 45 +++++++++++-------- .../css/css-contain/parsing/contain-valid.txt | 11 +++-- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index fcc0502b22b..7cce668cc9b 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -4839,47 +4839,56 @@ RefPtr Parser::parse_contain_value(TokenStream size_value; + RefPtr layout_value; + RefPtr style_value; + RefPtr paint_value; - StyleValueVector containments; while (tokens.has_next_token()) { tokens.discard_whitespace(); - auto keyword = parse_keyword_value(tokens); - if (!keyword) + auto keyword_value = parse_keyword_value(tokens); + if (!keyword_value) return {}; - switch (keyword->to_keyword()) { + switch (keyword_value->to_keyword()) { case Keyword::Size: case Keyword::InlineSize: - if (has_size) + if (size_value) return {}; - has_size = true; + size_value = move(keyword_value); break; case Keyword::Layout: - if (has_layout) + if (layout_value) return {}; - has_layout = true; + layout_value = move(keyword_value); break; case Keyword::Style: - if (has_style) + if (style_value) return {}; - has_style = true; + style_value = move(keyword_value); break; case Keyword::Paint: - if (has_paint) + if (paint_value) return {}; - has_paint = true; + paint_value = move(keyword_value); break; default: return {}; } - containments.append(*keyword); } + + StyleValueVector containment_values; + if (size_value) + containment_values.append(size_value.release_nonnull()); + if (layout_value) + containment_values.append(layout_value.release_nonnull()); + if (style_value) + containment_values.append(style_value.release_nonnull()); + if (paint_value) + containment_values.append(paint_value.release_nonnull()); + transaction.commit(); - return StyleValueList::create(move(containments), StyleValueList::Separator::Space); + return StyleValueList::create(move(containment_values), StyleValueList::Separator::Space); } // https://www.w3.org/TR/css-text-4/#white-space-trim diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/parsing/contain-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/parsing/contain-valid.txt index 6729db0e42e..26f8bdb706f 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/parsing/contain-valid.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-contain/parsing/contain-valid.txt @@ -2,8 +2,7 @@ Harness status: OK Found 13 tests -9 Pass -4 Fail +13 Pass 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 @@ -11,9 +10,9 @@ Pass e.style['contain'] = "size" should set the property value Pass e.style['contain'] = "layout" should set the property value 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 +Pass e.style['contain'] = "layout size" should set the property value +Pass e.style['contain'] = "paint style" 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'] = "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 \ No newline at end of file +Pass e.style['contain'] = "layout inline-size" should set the property value \ No newline at end of file