From 54351e7327b0f6d61b9a54a55d1567f5e3f13633 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 20 Mar 2025 10:58:38 +0000 Subject: [PATCH] LibWeb: Use shortest serialization for shorthands with repeated values For shorthands where all the values are repeated, we now only output the value once. --- .../CSS/StyleValues/ShorthandStyleValue.cpp | 11 +++++++ ...upported-properties-and-default-values.txt | 32 +++++++++---------- .../css/css-align/gaps/gap-animation-001.txt | 4 +-- .../css/css-align/gaps/gap-animation-002.txt | 4 +-- .../css/css-align/gaps/gap-animation-003.txt | 4 +-- .../css/css-align/gaps/gap-parsing-002.txt | 16 +++++----- .../css/css-align/parsing/gap-valid.txt | 14 ++++++++ .../css/css-align/parsing/gap-valid.html | 26 +++++++++++++++ 8 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/gap-valid.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/gap-valid.html diff --git a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp index 7404336b8c4..bb67cb2710b 100644 --- a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp @@ -396,6 +396,17 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const return builder.to_string_without_validation(); } default: + auto all_properties_same_value = true; + auto first_property_value = m_properties.values.first(); + for (auto i = 1u; i < m_properties.values.size(); ++i) { + if (m_properties.values[i] != first_property_value) { + all_properties_same_value = false; + break; + } + } + if (all_properties_same_value) + return first_property_value->to_string(mode); + StringBuilder builder; auto first = true; for (auto& value : m_properties.values) { diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt index 3245c3c0d4a..4618425ff68 100644 --- a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt +++ b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt @@ -364,7 +364,7 @@ All supported properties and their default values exposed from CSSStylePropertie 'font-weight': '400' 'fontWidth': 'normal' 'font-width': 'normal' -'gap': 'normal normal' +'gap': 'normal' 'grid': '' 'gridArea': '' 'grid-area': '' @@ -382,8 +382,8 @@ All supported properties and their default values exposed from CSSStylePropertie 'grid-column-gap': 'normal' 'gridColumnStart': 'auto' 'grid-column-start': 'auto' -'gridGap': 'normal normal' -'grid-gap': 'normal normal' +'gridGap': 'normal' +'grid-gap': 'normal' 'gridRow': 'auto' 'grid-row': 'auto' 'gridRowEnd': 'auto' @@ -405,15 +405,15 @@ All supported properties and their default values exposed from CSSStylePropertie 'image-rendering': 'auto' 'inlineSize': '284px' 'inline-size': '284px' -'inset': 'auto auto auto auto' -'insetBlock': 'auto auto auto auto' -'inset-block': 'auto auto auto auto' +'inset': 'auto' +'insetBlock': 'auto' +'inset-block': 'auto' 'insetBlockEnd': 'auto' 'inset-block-end': 'auto' 'insetBlockStart': 'auto' 'inset-block-start': 'auto' -'insetInline': 'auto auto auto auto' -'inset-inline': 'auto auto auto auto' +'insetInline': 'auto' +'inset-inline': 'auto' 'insetInlineEnd': 'auto' 'inset-inline-end': 'auto' 'insetInlineStart': 'auto' @@ -439,16 +439,16 @@ All supported properties and their default values exposed from CSSStylePropertie 'listStyleType': 'disc' 'list-style-type': 'disc' 'margin': '8px' -'marginBlock': '8px 8px 8px 8px' -'margin-block': '8px 8px 8px 8px' +'marginBlock': '8px' +'margin-block': '8px' 'marginBlockEnd': '8px' 'margin-block-end': '8px' 'marginBlockStart': '8px' 'margin-block-start': '8px' 'marginBottom': '8px' 'margin-bottom': '8px' -'marginInline': '8px 8px 8px 8px' -'margin-inline': '8px 8px 8px 8px' +'marginInline': '8px' +'margin-inline': '8px' 'marginInlineEnd': '8px' 'margin-inline-end': '8px' 'marginInlineStart': '8px' @@ -509,16 +509,16 @@ All supported properties and their default values exposed from CSSStylePropertie 'overflowY': 'visible' 'overflow-y': 'visible' 'padding': '0px' -'paddingBlock': '0px 0px 0px 0px' -'padding-block': '0px 0px 0px 0px' +'paddingBlock': '0px' +'padding-block': '0px' 'paddingBlockEnd': '0px' 'padding-block-end': '0px' 'paddingBlockStart': '0px' 'padding-block-start': '0px' 'paddingBottom': '0px' 'padding-bottom': '0px' -'paddingInline': '0px 0px 0px 0px' -'padding-inline': '0px 0px 0px 0px' +'paddingInline': '0px' +'padding-inline': '0px' 'paddingInlineEnd': '0px' 'padding-inline-end': '0px' 'paddingInlineStart': '0px' diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-001.txt index 4af8d62faae..67681483864 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-001.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-001.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail gap is interpolable \ No newline at end of file +1 Pass +Pass gap is interpolable \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-002.txt index 7f48b86ee8e..28841e5b3a1 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-002.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-002.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail gap: normal is not interpolable \ No newline at end of file +1 Pass +Pass gap: normal is not interpolable \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-003.txt index ca6424713bf..4691619ad11 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-003.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-animation-003.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Default gap is not interpolable \ No newline at end of file +1 Pass +Pass Default gap is not interpolable \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-002.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-002.txt index 1a390f332f6..06c51e32299 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-002.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/gaps/gap-parsing-002.txt @@ -2,20 +2,20 @@ Harness status: OK Found 16 tests -6 Pass -10 Fail -Fail e.style['gap'] = "normal" should set the property value -Fail e.style['gap'] = "10px" should set the property value -Fail e.style['gap'] = "normal normal" should set the property value -Fail e.style['gap'] = "10px 10px" should set the property value +12 Pass +4 Fail +Pass e.style['gap'] = "normal" should set the property value +Pass e.style['gap'] = "10px" should set the property value +Pass e.style['gap'] = "normal normal" should set the property value +Pass e.style['gap'] = "10px 10px" should set the property value Pass e.style['column-gap'] = "normal" should set the property value Pass e.style['column-gap'] = "10px" should set the property value Pass e.style['row-gap'] = "normal" should set the property value Pass e.style['row-gap'] = "10px" should set the property value Fail 'row-gap: normal; column-gap: normal;' is serialized to 'gap: normal;' -Fail getPropertyValue for 'row-gap: normal; column-gap: normal;' returns 'normal' +Pass getPropertyValue for 'row-gap: normal; column-gap: normal;' returns 'normal' Fail 'row-gap: 10px; column-gap: 10px;' is serialized to 'gap: 10px;' -Fail getPropertyValue for 'row-gap: 10px; column-gap: 10px;' returns '10px' +Pass getPropertyValue for 'row-gap: 10px; column-gap: 10px;' returns '10px' Fail 'row-gap: 10px; column-gap: normal;' is serialized to 'gap: 10px normal;' Pass getPropertyValue for 'row-gap: 10px; column-gap: normal;' returns '10px normal' Fail 'column-gap: normal; row-gap: 10px;' is serialized to 'gap: 10px normal;' diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/gap-valid.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/gap-valid.txt new file mode 100644 index 00000000000..19f8d09a982 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-align/parsing/gap-valid.txt @@ -0,0 +1,14 @@ +Harness status: OK + +Found 9 tests + +9 Pass +Pass e.style['gap'] = "normal normal" should set the property value +Pass e.style['gap'] = "10px 10px" should set the property value +Pass e.style['gap'] = "20% 20%" should set the property value +Pass e.style['gap'] = "calc(20% + 10px) calc(20% + 10px)" should set the property value +Pass e.style['gap'] = "normal 10px" should set the property value +Pass e.style['gap'] = "10px 20%" should set the property value +Pass e.style['gap'] = "20% calc(20% + 10px)" should set the property value +Pass e.style['gap'] = "calc(20% + 10px) 0px" should set the property value +Pass e.style['gap'] = "0px normal" should set the property value \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/gap-valid.html b/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/gap-valid.html new file mode 100644 index 00000000000..c269ba50d1c --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/css/css-align/parsing/gap-valid.html @@ -0,0 +1,26 @@ + + + + +CSS Box Alignment Level 3: parsing gap with valid values + + + + + + + + + +