Skip to content

Commit 61a0898

Browse files
committed
LibWeb/CSS: Stop inserting whitespace when serializing component values
Now that we don't remove whitespace when parsing, we don't need to artificially insert it back in again when serializing. We do now need to trim leading and trailing whitespace from UnresolvedStyleValues, as this previously was done as part of the whitespace insertion. This makes our serialization of UnresolvedStyleValues more correct and gets us a few WPT passes for each property in the Typed OM tests.
1 parent 427d7fa commit 61a0898

File tree

13 files changed

+45
-53
lines changed

13 files changed

+45
-53
lines changed

Libraries/LibWeb/CSS/Serialize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ String serialize_a_css_declaration(StringView property, StringView value, Import
199199
}
200200

201201
// https://drafts.csswg.org/css-syntax/#serialization
202-
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue> component_values, InsertWhitespace insert_whitespace)
202+
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue> component_values)
203203
{
204204
// FIXME: There are special rules here where we should insert a comment between certain tokens. Do that!
205-
if (insert_whitespace == InsertWhitespace::Yes)
206-
return MUST(Infra::strip_and_collapse_whitespace(MUST(String::join(' ', component_values))));
207205
return MUST(String::join(""sv, component_values));
208206
}
209207

Libraries/LibWeb/CSS/Serialize.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ void serialize_a_comma_separated_list(StringBuilder& builder, Vector<T> const& i
4747

4848
String serialize_a_css_declaration(StringView property, StringView value, Important = Important::No);
4949

50-
enum class InsertWhitespace : u8 {
51-
No,
52-
Yes,
53-
};
54-
// FIXME: Remove InsertWhitespace param once style value parsing stops discarding whitespace tokens.
55-
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue>, InsertWhitespace = InsertWhitespace::No);
50+
String serialize_a_series_of_component_values(ReadonlySpan<Parser::ComponentValue>);
5651

5752
}

Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ String UnresolvedStyleValue::to_string(SerializationMode) const
4545
if (m_original_source_text.has_value())
4646
return *m_original_source_text;
4747

48-
return serialize_a_series_of_component_values(m_values, InsertWhitespace::Yes);
48+
return MUST(serialize_a_series_of_component_values(m_values).trim_ascii_whitespace());
4949
}
5050

5151
bool UnresolvedStyleValue::equals(StyleValue const& other) const
@@ -145,8 +145,7 @@ class Reifier {
145145

146146
void serialize_unserialized_values()
147147
{
148-
// FIXME: Stop inserting whitespace once we stop removing it during parsing.
149-
m_reified_values.append(serialize_a_series_of_component_values(m_unserialized_values, InsertWhitespace::Yes));
148+
m_reified_values.append(serialize_a_series_of_component_values(m_unserialized_values));
150149
m_unserialized_values.clear_with_capacity();
151150
}
152151

Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/var-reference-registered-properties.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ Harness status: OK
22

33
Found 16 tests
44

5-
7 Pass
6-
9 Fail
5+
10 Pass
6+
6 Fail
77
Fail var() references work with registered properties
8-
Fail References to registered var()-properties work in registered lists
9-
Fail References to mixed registered and unregistered var()-properties work in registered lists
10-
Fail Registered lists may be concatenated
8+
Pass References to registered var()-properties work in registered lists
9+
Pass References to mixed registered and unregistered var()-properties work in registered lists
10+
Pass Registered lists may be concatenated
1111
Fail Font-relative units are absolutized when substituting
1212
Fail Calc expressions are resolved when substituting
1313
Fail Lists with relative units are absolutized when substituting

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/stylevalue-normalization/normalize-tokens.tentative.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ Harness status: OK
22

33
Found 16 tests
44

5-
16 Fail
5+
3 Pass
6+
13 Fail
67
Fail Normalizing "var(--A)" on a CSS property returns correct CSSUnparsedValue
78
Fail Normalizing "var(--A)" on a shorthand returns correct CSSUnparsedValue
89
Fail Normalizing "var(--A)" on a list-valued property returns correct CSSUnparsedValue
@@ -15,7 +16,7 @@ Fail Normalizing "var(--A, var(--B))" on a CSS property returns correct CSSUnpar
1516
Fail Normalizing "var(--A, var(--B))" on a shorthand returns correct CSSUnparsedValue
1617
Fail Normalizing "var(--A, var(--B))" on a list-valued property returns correct CSSUnparsedValue
1718
Fail Normalizing "var(--A, var(--B))" on a custom property returns correct CSSUnparsedValue
18-
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a CSS property returns correct CSSUnparsedValue
19+
Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a CSS property returns correct CSSUnparsedValue
1920
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a shorthand returns correct CSSUnparsedValue
20-
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a list-valued property returns correct CSSUnparsedValue
21-
Fail Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a custom property returns correct CSSUnparsedValue
21+
Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a list-valued property returns correct CSSUnparsedValue
22+
Pass Normalizing "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))" on a custom property returns correct CSSUnparsedValue

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/color.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Harness status: OK
22

33
Found 37 tests
44

5-
35 Pass
6-
2 Fail
5+
36 Pass
6+
1 Fail
77
Pass Can set 'color' to CSS-wide keywords: initial
88
Pass Can set 'color' to CSS-wide keywords: inherit
99
Pass Can set 'color' to CSS-wide keywords: unset
1010
Pass Can set 'color' to CSS-wide keywords: revert
11-
Fail Can set 'color' to var() references: var(--A)
11+
Pass Can set 'color' to var() references: var(--A)
1212
Fail Can set 'color' to the 'currentcolor' keyword: currentcolor
1313
Pass Setting 'color' to a length: 0px throws TypeError
1414
Pass Setting 'color' to a length: -3.14em throws TypeError

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/cursor.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Harness status: OK
22

33
Found 69 tests
44

5-
64 Pass
6-
5 Fail
5+
65 Pass
6+
4 Fail
77
Pass Can set 'cursor' to CSS-wide keywords: initial
88
Pass Can set 'cursor' to CSS-wide keywords: inherit
99
Pass Can set 'cursor' to CSS-wide keywords: unset
1010
Pass Can set 'cursor' to CSS-wide keywords: revert
11-
Fail Can set 'cursor' to var() references: var(--A)
11+
Pass Can set 'cursor' to var() references: var(--A)
1212
Pass Can set 'cursor' to the 'auto' keyword: auto
1313
Pass Can set 'cursor' to the 'default' keyword: default
1414
Pass Can set 'cursor' to the 'none' keyword: none

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/display.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ Harness status: OK
22

33
Found 56 tests
44

5-
55 Pass
6-
1 Fail
5+
56 Pass
76
Pass Can set 'display' to CSS-wide keywords: initial
87
Pass Can set 'display' to CSS-wide keywords: inherit
98
Pass Can set 'display' to CSS-wide keywords: unset
109
Pass Can set 'display' to CSS-wide keywords: revert
11-
Fail Can set 'display' to var() references: var(--A)
10+
Pass Can set 'display' to var() references: var(--A)
1211
Pass Can set 'display' to the 'none' keyword: none
1312
Pass Can set 'display' to the 'block' keyword: block
1413
Pass Can set 'display' to the 'inline' keyword: inline

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/line-height.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Harness status: OK
22

33
Found 32 tests
44

5-
29 Pass
6-
3 Fail
5+
30 Pass
6+
2 Fail
77
Pass Can set 'line-height' to CSS-wide keywords: initial
88
Pass Can set 'line-height' to CSS-wide keywords: inherit
99
Pass Can set 'line-height' to CSS-wide keywords: unset
1010
Pass Can set 'line-height' to CSS-wide keywords: revert
11-
Fail Can set 'line-height' to var() references: var(--A)
11+
Pass Can set 'line-height' to var() references: var(--A)
1212
Pass Can set 'line-height' to the 'normal' keyword: normal
1313
Pass Can set 'line-height' to a length: 0px
1414
Pass Can set 'line-height' to a length: -3.14em

Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/properties/margin.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ Harness status: OK
22

33
Found 161 tests
44

5-
152 Pass
6-
9 Fail
5+
156 Pass
6+
5 Fail
77
Pass Can set 'margin-top' to CSS-wide keywords: initial
88
Pass Can set 'margin-top' to CSS-wide keywords: inherit
99
Pass Can set 'margin-top' to CSS-wide keywords: unset
1010
Pass Can set 'margin-top' to CSS-wide keywords: revert
11-
Fail Can set 'margin-top' to var() references: var(--A)
11+
Pass Can set 'margin-top' to var() references: var(--A)
1212
Pass Can set 'margin-top' to the 'auto' keyword: auto
1313
Pass Can set 'margin-top' to a percent: 0%
1414
Pass Can set 'margin-top' to a percent: -3.14%
@@ -40,7 +40,7 @@ Pass Can set 'margin-left' to CSS-wide keywords: initial
4040
Pass Can set 'margin-left' to CSS-wide keywords: inherit
4141
Pass Can set 'margin-left' to CSS-wide keywords: unset
4242
Pass Can set 'margin-left' to CSS-wide keywords: revert
43-
Fail Can set 'margin-left' to var() references: var(--A)
43+
Pass Can set 'margin-left' to var() references: var(--A)
4444
Pass Can set 'margin-left' to the 'auto' keyword: auto
4545
Pass Can set 'margin-left' to a percent: 0%
4646
Pass Can set 'margin-left' to a percent: -3.14%
@@ -72,7 +72,7 @@ Pass Can set 'margin-right' to CSS-wide keywords: initial
7272
Pass Can set 'margin-right' to CSS-wide keywords: inherit
7373
Pass Can set 'margin-right' to CSS-wide keywords: unset
7474
Pass Can set 'margin-right' to CSS-wide keywords: revert
75-
Fail Can set 'margin-right' to var() references: var(--A)
75+
Pass Can set 'margin-right' to var() references: var(--A)
7676
Pass Can set 'margin-right' to the 'auto' keyword: auto
7777
Pass Can set 'margin-right' to a percent: 0%
7878
Pass Can set 'margin-right' to a percent: -3.14%
@@ -104,7 +104,7 @@ Pass Can set 'margin-bottom' to CSS-wide keywords: initial
104104
Pass Can set 'margin-bottom' to CSS-wide keywords: inherit
105105
Pass Can set 'margin-bottom' to CSS-wide keywords: unset
106106
Pass Can set 'margin-bottom' to CSS-wide keywords: revert
107-
Fail Can set 'margin-bottom' to var() references: var(--A)
107+
Pass Can set 'margin-bottom' to var() references: var(--A)
108108
Pass Can set 'margin-bottom' to the 'auto' keyword: auto
109109
Pass Can set 'margin-bottom' to a percent: 0%
110110
Pass Can set 'margin-bottom' to a percent: -3.14%

0 commit comments

Comments
 (0)