From d6e04fc53a08e91685094f2027e71d0a647636b7 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 4 Apr 2025 11:04:35 +0100 Subject: [PATCH] LibWeb: Serialize drop-shadow filter properties in canonical order --- .../StyleValues/FilterValueListStyleValue.cpp | 12 +-- .../parsing/filter-computed.txt | 40 ++++++++++ .../parsing/filter-parsing-valid.txt | 45 ++++++++++++ .../parsing/filter-computed.html | 68 +++++++++++++++++ .../parsing/filter-parsing-valid.html | 73 +++++++++++++++++++ 5 files changed, 232 insertions(+), 6 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-computed.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-parsing-valid.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-computed.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-parsing-valid.html diff --git a/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp index 32fd2621d58..bc8d45e4829 100644 --- a/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/FilterValueListStyleValue.cpp @@ -68,14 +68,14 @@ String FilterValueListStyleValue::to_string(SerializationMode) const builder.append(blur.radius->to_string()); }, [&](FilterOperation::DropShadow const& drop_shadow) { - builder.appendff("drop-shadow({} {}"sv, - drop_shadow.offset_x, drop_shadow.offset_y); + builder.appendff("drop-shadow("sv); + if (drop_shadow.color.has_value()) { + serialize_a_srgb_value(builder, *drop_shadow.color); + builder.append(' '); + } + builder.appendff("{} {}", drop_shadow.offset_x, drop_shadow.offset_y); if (drop_shadow.radius.has_value()) builder.appendff(" {}", drop_shadow.radius->to_string()); - if (drop_shadow.color.has_value()) { - builder.append(' '); - serialize_a_srgb_value(builder, *drop_shadow.color); - } }, [&](FilterOperation::HueRotate const& hue_rotate) { builder.append("hue-rotate("sv); diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-computed.txt new file mode 100644 index 00000000000..45991f9854a --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-computed.txt @@ -0,0 +1,40 @@ +Harness status: OK + +Found 34 tests + +9 Pass +25 Fail +Pass Property filter value 'none' +Pass Property filter value 'blur(100px)' +Fail Property filter value 'blur()' +Pass Property filter value 'brightness(0)' +Fail Property filter value 'brightness(300%)' +Fail Property filter value 'brightness()' +Pass Property filter value 'contrast(0)' +Fail Property filter value 'contrast(300%)' +Fail Property filter value 'contrast()' +Fail Property filter value 'drop-shadow(1px 2px)' +Pass Property filter value 'drop-shadow(rgb(4, 5, 6) 1px 2px 0px)' +Fail Property filter value 'grayscale(50%)' +Fail Property filter value 'grayscale(calc(50%))' +Fail Property filter value 'grayscale(2)' +Fail Property filter value 'grayscale(calc(2))' +Fail Property filter value 'grayscale()' +Fail Property filter value 'hue-rotate(90deg)' +Fail Property filter value 'hue-rotate()' +Pass Property filter value 'invert(0)' +Fail Property filter value 'invert(100%)' +Fail Property filter value 'invert(2)' +Fail Property filter value 'invert()' +Pass Property filter value 'opacity(0)' +Fail Property filter value 'opacity(100%)' +Fail Property filter value 'opacity(2)' +Fail Property filter value 'opacity()' +Pass Property filter value 'saturate(0)' +Fail Property filter value 'saturate(300%)' +Fail Property filter value 'saturate()' +Pass Property filter value 'sepia(0)' +Fail Property filter value 'sepia(100%)' +Fail Property filter value 'sepia(2)' +Fail Property filter value 'sepia()' +Fail Property filter value 'blur(10px) url("https://www.example.com/picture.svg#f") contrast(20) brightness(30)' \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-parsing-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-parsing-valid.txt new file mode 100644 index 00000000000..0db8824f6bb --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/filter-effects/parsing/filter-parsing-valid.txt @@ -0,0 +1,45 @@ +Harness status: OK + +Found 39 tests + +30 Pass +9 Fail +Pass e.style['filter'] = "none" should set the property value +Pass e.style['filter'] = "blur(100px)" should set the property value +Pass e.style['filter'] = "blur(0)" should set the property value +Pass e.style['filter'] = "blur()" should set the property value +Pass e.style['filter'] = "brightness(0)" should set the property value +Pass e.style['filter'] = "brightness(300%)" should set the property value +Pass e.style['filter'] = "brightness()" should set the property value +Pass e.style['filter'] = "contrast(0)" should set the property value +Pass e.style['filter'] = "contrast(300%)" should set the property value +Pass e.style['filter'] = "contrast()" should set the property value +Pass e.style['filter'] = "drop-shadow(1px 2px)" should set the property value +Pass e.style['filter'] = "drop-shadow(1px 2px 3px)" should set the property value +Pass e.style['filter'] = "drop-shadow(0 0 0)" should set the property value +Pass e.style['filter'] = "drop-shadow(rgb(4, 5, 6) 1px 2px)" should set the property value +Pass e.style['filter'] = "drop-shadow(1px 2px rgb(4, 5, 6))" should set the property value +Pass e.style['filter'] = "drop-shadow(rgba(4, 5, 6, 0.75) 1px 2px 3px)" should set the property value +Pass e.style['filter'] = "grayscale(0)" should set the property value +Fail e.style['filter'] = "grayscale(300%)" should set the property value +Pass e.style['filter'] = "grayscale(calc(300%))" should set the property value +Pass e.style['filter'] = "grayscale(calc(101% * sign(1em - 1px)))" should set the property value +Pass e.style['filter'] = "grayscale()" should set the property value +Fail e.style['filter'] = "hue-rotate(90deg)" should set the property value +Fail e.style['filter'] = "hue-rotate(0)" should set the property value +Pass e.style['filter'] = "hue-rotate()" should set the property value +Pass e.style['filter'] = "invert(0)" should set the property value +Fail e.style['filter'] = "invert(300%)" should set the property value +Pass e.style['filter'] = "invert()" should set the property value +Pass e.style['filter'] = "opacity(0)" should set the property value +Fail e.style['filter'] = "opacity(300%)" should set the property value +Pass e.style['filter'] = "opacity()" should set the property value +Pass e.style['filter'] = "saturate(0)" should set the property value +Pass e.style['filter'] = "saturate(300%)" should set the property value +Pass e.style['filter'] = "saturate()" should set the property value +Pass e.style['filter'] = "sepia(0)" should set the property value +Fail e.style['filter'] = "sepia(300%)" should set the property value +Pass e.style['filter'] = "sepia()" should set the property value +Fail e.style['filter'] = "url(picture.svg#f)" should set the property value +Fail e.style['filter'] = "url(\"https://www.example.com/picture.svg#f\")" should set the property value +Fail e.style['filter'] = "blur(10px) url(\"picture.svg#f\") contrast(20) brightness(30)" should set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-computed.html new file mode 100644 index 00000000000..3670c95bd1d --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-computed.html @@ -0,0 +1,68 @@ + + + + +Filter Effects Module Level 1: getComputedStyle().filter + + + + + + + + + +
+ + + diff --git a/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-parsing-valid.html b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-parsing-valid.html new file mode 100644 index 00000000000..ed64d83db48 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/filter-effects/parsing/filter-parsing-valid.html @@ -0,0 +1,73 @@ + + + + +Filter Effects Module Level 1: parsing filter with valid values + + + + + + + + + + +