From 5bcd9abc42a13012731185408797440419b0f994 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 28 Nov 2024 15:48:07 +0000 Subject: [PATCH] LibWeb/CSS: Serialize background-repeat correctly This gets us 4 WPT subtest passes. --- .../CSS/StyleValues/BackgroundRepeatStyleValue.cpp | 8 ++++++++ .../Text/expected/HTML/background-shorthand.txt | 2 +- ...n-all-supported-properties-and-default-values.txt | 6 +++--- .../Text/expected/css/getComputedStyle-print-all.txt | 2 +- .../expected/interpolation-longhand-properties.txt | 4 ++-- .../wpt-import/css/cssom/serialize-values.txt | 12 ++++++------ 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp index ca0bae7a417..87f46bd1b1b 100644 --- a/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.cpp @@ -22,6 +22,14 @@ BackgroundRepeatStyleValue::~BackgroundRepeatStyleValue() = default; String BackgroundRepeatStyleValue::to_string() const { + if (m_properties.repeat_x == m_properties.repeat_y) + return MUST(String::from_utf8(CSS::to_string(m_properties.repeat_x))); + + if (m_properties.repeat_x == Repeat::Repeat && m_properties.repeat_y == Repeat::NoRepeat) + return "repeat-x"_string; + if (m_properties.repeat_x == Repeat::NoRepeat && m_properties.repeat_y == Repeat::Repeat) + return "repeat-y"_string; + return MUST(String::formatted("{} {}", CSS::to_string(m_properties.repeat_x), CSS::to_string(m_properties.repeat_y))); } diff --git a/Tests/LibWeb/Text/expected/HTML/background-shorthand.txt b/Tests/LibWeb/Text/expected/HTML/background-shorthand.txt index f7eb47ea13e..5100c84795b 100644 --- a/Tests/LibWeb/Text/expected/HTML/background-shorthand.txt +++ b/Tests/LibWeb/Text/expected/HTML/background-shorthand.txt @@ -1,4 +1,4 @@ -style.cssText = background-color: yellow; background-image: none; background-position-x: left 0%; background-position-y: top 0%; background-size: auto auto; background-repeat: repeat repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; +style.cssText = background-color: yellow; background-image: none; background-position-x: left 0%; background-position-y: top 0%; background-size: auto auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; style.length = 9 style[] = 1. background-color diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-all-supported-properties-and-default-values.txt b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-all-supported-properties-and-default-values.txt index 41ac64ef835..5348cceeff5 100644 --- a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-all-supported-properties-and-default-values.txt +++ b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-all-supported-properties-and-default-values.txt @@ -159,7 +159,7 @@ All supported properties and their default values exposed from CSSStyleDeclarati 'aspect-ratio': 'auto' 'backdropFilter': 'none' 'backdrop-filter': 'none' -'background': 'scroll border-box rgba(0, 0, 0, 0) none padding-box left 0% top 0% repeat repeat auto auto' +'background': 'scroll border-box rgba(0, 0, 0, 0) none padding-box left 0% top 0% repeat auto auto' 'backgroundAttachment': 'scroll' 'background-attachment': 'scroll' 'backgroundClip': 'border-box' @@ -176,8 +176,8 @@ All supported properties and their default values exposed from CSSStyleDeclarati 'background-position-x': 'left 0%' 'backgroundPositionY': 'top 0%' 'background-position-y': 'top 0%' -'backgroundRepeat': 'repeat repeat' -'background-repeat': 'repeat repeat' +'backgroundRepeat': 'repeat' +'background-repeat': 'repeat' 'backgroundSize': 'auto auto' 'background-size': 'auto auto' 'border': 'medium none rgb(0, 0, 0)' diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt index dc729509efc..175a3646fcc 100644 --- a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt +++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt @@ -73,7 +73,7 @@ background-image: none background-origin: padding-box background-position-x: left 0% background-position-y: top 0% -background-repeat: repeat repeat +background-repeat: repeat background-size: auto auto border-bottom-color: rgb(0, 0, 0) border-bottom-left-radius: 0px diff --git a/Tests/LibWeb/Text/expected/interpolation-longhand-properties.txt b/Tests/LibWeb/Text/expected/interpolation-longhand-properties.txt index c08390f5fd9..29b960c1853 100644 --- a/Tests/LibWeb/Text/expected/interpolation-longhand-properties.txt +++ b/Tests/LibWeb/Text/expected/interpolation-longhand-properties.txt @@ -4,7 +4,7 @@ At time 400: animation-duration: auto aspect-ratio: 1.54415 / 1 background-color: rgb(78, 88, 99) - background-repeat: repeat no-repeat + background-repeat: repeat-x bottom: auto box-shadow: rgb(163, 82, 142) 40px 80px 126px 0px inset, rgba(0, 0, 72, 0.4) 20px 4px 8px 12px color: rgb(163, 82, 142) @@ -16,7 +16,7 @@ At time 750: animation-duration: auto aspect-ratio: 1.36506 / 1 background-color: rgb(147, 157, 168) - background-repeat: space space + background-repeat: space bottom: 100% box-shadow: rgb(81, 71, 210) 75px 150px 227.5px 0px, rgba(0, 0, 174, 0.749) 37.5px 7.5px 15px 22.5px color: rgb(81, 71, 210) diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/serialize-values.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/serialize-values.txt index db245584881..687f8e009ab 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/serialize-values.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/serialize-values.txt @@ -6,8 +6,8 @@ Rerun Found 687 tests -458 Pass -229 Fail +462 Pass +225 Fail Details Result Test Name MessagePass background-attachment: scroll Pass background-attachment: fixed @@ -192,10 +192,10 @@ Fail background-position: right top Fail background-position: right center Fail background-position: right bottom Fail background-position: inherit -Fail background-repeat: repeat -Fail background-repeat: repeat-x -Fail background-repeat: repeat-y -Fail background-repeat: no-repeat +Pass background-repeat: repeat +Pass background-repeat: repeat-x +Pass background-repeat: repeat-y +Pass background-repeat: no-repeat Pass background-repeat: inherit Pass border-collapse: collapse Pass border-collapse: separate