From db75405881a06b46906278841408d2ea3263fb99 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 17 Jul 2025 10:44:29 +0100 Subject: [PATCH] LibWeb/CSS: Support `overlay` keyword as alias to `auto` in `overflow` We don't yet have a system for "legacy value aliases", but until we have a lot of them we can handle them manually. We also have to do this in two places because parse_css_value_for_property() doesn't call any property-specific parsing code. --- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 28 +++++++++++++++++-- Libraries/LibWeb/CSS/Properties.json | 6 ++++ .../css-overflow/overflow-overlay-ref.html | 11 ++++++++ .../css/css-overflow/overflow-overlay.html | 13 +++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Ref/expected/wpt-import/css/css-overflow/overflow-overlay-ref.html create mode 100644 Tests/LibWeb/Ref/input/wpt-import/css/css-overflow/overflow-overlay.html diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index c70c3fda66e..0b824dbe434 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -673,6 +673,17 @@ Parser::ParseErrorOr> Parser::parse_css_value if (auto parsed_value = parse_overflow_value(tokens); parsed_value && !tokens.has_next_token()) return parsed_value.release_nonnull(); return ParseError::SyntaxError; + case PropertyID::OverflowX: + case PropertyID::OverflowY: + if (auto parsed_value = parse_css_value_for_property(property_id, tokens); parsed_value && !tokens.has_next_token()) { + // https://drafts.csswg.org/css-overflow-3/#valdef-overflow-overlay + // User agents must also support the overlay keyword as a legacy value alias of auto. + // FIXME: Figure out a generic way of supporting legacy value aliases. + if (parsed_value->to_keyword() == Keyword::Overlay) + return CSSKeywordValue::create(Keyword::Auto); + return parsed_value.release_nonnull(); + } + return ParseError::SyntaxError; case PropertyID::PlaceContent: if (auto parsed_value = parse_place_content_value(tokens); parsed_value && !tokens.has_next_token()) return parsed_value.release_nonnull(); @@ -3600,11 +3611,24 @@ RefPtr Parser::parse_opacity_value(PropertyID property_id, RefPtr Parser::parse_overflow_value(TokenStream& tokens) { + // https://drafts.csswg.org/css-overflow-3/#valdef-overflow-overlay + // User agents must also support the overlay keyword as a legacy value alias of auto. + // FIXME: Figure out a generic way of supporting legacy value aliases. + // FIXME: Even better, make parsing the longhands go through their proper parsing routine. + auto parse_an_overflow_longhand_value = [this](PropertyID property, auto& tokens) -> RefPtr { + auto maybe_value = parse_css_value_for_property(property, tokens); + if (!maybe_value) + return nullptr; + if (maybe_value->to_keyword() == Keyword::Overlay) + return CSSKeywordValue::create(Keyword::Auto); + return maybe_value.release_nonnull(); + }; + auto transaction = tokens.begin_transaction(); - auto maybe_x_value = parse_css_value_for_property(PropertyID::OverflowX, tokens); + auto maybe_x_value = parse_an_overflow_longhand_value(PropertyID::OverflowX, tokens); if (!maybe_x_value) return nullptr; - auto maybe_y_value = parse_css_value_for_property(PropertyID::OverflowY, tokens); + auto maybe_y_value = parse_an_overflow_longhand_value(PropertyID::OverflowY, tokens); transaction.commit(); if (maybe_y_value) { return ShorthandStyleValue::create(PropertyID::Overflow, diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json index 8159ef144ca..d3e5e5e5904 100644 --- a/Libraries/LibWeb/CSS/Properties.json +++ b/Libraries/LibWeb/CSS/Properties.json @@ -2644,6 +2644,9 @@ "initial": "visible", "valid-types": [ "overflow" + ], + "valid-identifiers": [ + "overlay" ] }, "overflow-y": { @@ -2652,6 +2655,9 @@ "initial": "visible", "valid-types": [ "overflow" + ], + "valid-identifiers": [ + "overlay" ] }, "padding": { diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-overflow/overflow-overlay-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-overflow/overflow-overlay-ref.html new file mode 100644 index 00000000000..3d88b75890c --- /dev/null +++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-overflow/overflow-overlay-ref.html @@ -0,0 +1,11 @@ + + +
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-overflow/overflow-overlay.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-overflow/overflow-overlay.html new file mode 100644 index 00000000000..caece274bc8 --- /dev/null +++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-overflow/overflow-overlay.html @@ -0,0 +1,13 @@ + + + + +
+

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

+