From 4ee8110449bf6dec72c78bcdb4558a102b7f719d Mon Sep 17 00:00:00 2001 From: Callum Law Date: Fri, 18 Jul 2025 22:37:12 +1200 Subject: [PATCH] LibWeb: Handle `flood-opacity` in line with other opacity properties We now do the proper thing in terms of: - Allowing percentages - Returning the computed value in getComputedStyle - Handling values out of the [0,1] range Gains us 13 WPT passes in the imported tests. --- Libraries/LibWeb/CSS/CSSStyleProperties.cpp | 4 +++ .../LibWeb/CSS/Parser/PropertyParsing.cpp | 1 + Libraries/LibWeb/CSS/Properties.json | 3 ++- .../parsing/flood-opacity-computed.txt | 14 ++++++++++ .../parsing/flood-opacity-valid.txt | 12 +++++++++ .../parsing/flood-opacity-computed.svg | 26 +++++++++++++++++++ .../parsing/flood-opacity-valid.svg | 25 ++++++++++++++++++ 7 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-computed.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-valid.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-computed.svg create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-valid.svg diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp index 396e959f7d9..52861189765 100644 --- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp @@ -830,6 +830,10 @@ RefPtr CSSStyleProperties::style_value_for_computed_propert auto opacity = layout_node.computed_values().stroke_opacity(); return NumberStyleValue::create(opacity); } + case PropertyID::FloodOpacity: { + auto opacity = layout_node.computed_values().flood_opacity(); + return NumberStyleValue::create(opacity); + } case PropertyID::OutlineWidth: { auto outline_width = layout_node.computed_values().outline_width(); return LengthStyleValue::create(outline_width); diff --git a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp index 8ccbb7a6eee..c70c3fda66e 100644 --- a/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/PropertyParsing.cpp @@ -662,6 +662,7 @@ Parser::ParseErrorOr> Parser::parse_css_value return ParseError::SyntaxError; case PropertyID::Opacity: case PropertyID::FillOpacity: + case PropertyID::FloodOpacity: case PropertyID::StopOpacity: case PropertyID::StrokeOpacity: if (auto parsed_value = parse_opacity_value(property_id, tokens); parsed_value && !tokens.has_next_token()) diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json index 5d51608567c..8159ef144ca 100644 --- a/Libraries/LibWeb/CSS/Properties.json +++ b/Libraries/LibWeb/CSS/Properties.json @@ -1561,7 +1561,8 @@ "inherited": false, "initial": "1", "valid-types": [ - "number [0,1]" + "number [-∞,∞]", + "percentage [-∞,∞]" ] }, "font": { diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-computed.txt new file mode 100644 index 00000000000..60e2ca9bd49 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-computed.txt @@ -0,0 +1,14 @@ +Harness status: OK + +Found 8 tests + +6 Pass +2 Fail +Pass Property flood-opacity value '-1' +Pass Property flood-opacity value '0.5' +Pass Property flood-opacity value '3' +Pass Property flood-opacity value '-100%' +Pass Property flood-opacity value '50%' +Pass Property flood-opacity value '300%' +Fail Property flood-opacity value 'calc(0.5 * sign(10em - 1px))' +Fail Property flood-opacity value 'calc(50% * sign(10em - 1px))' \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-valid.txt new file mode 100644 index 00000000000..88dad957690 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/flood-opacity-valid.txt @@ -0,0 +1,12 @@ +Harness status: OK + +Found 7 tests + +7 Pass +Pass e.style['flood-opacity'] = "-1" should set the property value +Pass e.style['flood-opacity'] = "0.5" should set the property value +Pass e.style['flood-opacity'] = "3" should set the property value +Pass e.style['flood-opacity'] = "-100%" should set the property value +Pass e.style['flood-opacity'] = "50%" should set the property value +Pass e.style['flood-opacity'] = "300%" should set the property value +Pass e.style['flood-opacity'] = "calc(0.5 * sign(10em - 1px))" should set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-computed.svg b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-computed.svg new file mode 100644 index 00000000000..9597c6cbefe --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-computed.svg @@ -0,0 +1,26 @@ + + + Filter Effects Module Level 1: getComputedStyle().floodOpacity + + + + + + + + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-valid.svg b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-valid.svg new file mode 100644 index 00000000000..fe435112c22 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/flood-opacity-valid.svg @@ -0,0 +1,25 @@ + + + Filter Effects Module Level 1: parsing flood-opacity with valid values + + + + + + + + + +