LibWeb/CSS: Don't repeat CSS-wide keywords when serializing shorthands

Regardless of what the shorthand property is, if all its longhands are
the same CSS-wide keyword such as "initial" or "inherit", then it's the
same as the shorthand being that value.

This gets us 2 WPT subtest passes.
This commit is contained in:
Sam Atkins 2024-11-29 13:46:37 +00:00 committed by Andreas Kling
parent 0c39d07b4d
commit 9453c25925
Notes: github-actions[bot] 2024-11-30 10:02:48 +00:00
2 changed files with 26 additions and 5 deletions

View file

@ -38,7 +38,28 @@ ValueComparingRefPtr<CSSStyleValue const> ShorthandStyleValue::longhand(Property
String ShorthandStyleValue::to_string() const
{
// Special-cases first
// If all the longhands are the same CSS-wide keyword, just return that once.
Optional<Keyword> built_in_keyword;
bool all_same_keyword = true;
for (auto& value : m_properties.values) {
if (!value->is_css_wide_keyword()) {
all_same_keyword = false;
break;
}
auto keyword = value->to_keyword();
if (!built_in_keyword.has_value()) {
built_in_keyword = keyword;
continue;
}
if (built_in_keyword != keyword) {
all_same_keyword = false;
break;
}
}
if (all_same_keyword && built_in_keyword.has_value())
return m_properties.values.first()->to_string();
// Then special cases
switch (m_properties.shorthand_property) {
case PropertyID::Background: {
auto color = longhand(PropertyID::BackgroundColor);

View file

@ -6,8 +6,8 @@ Rerun
Found 687 tests
471 Pass
216 Fail
473 Pass
214 Fail
Details
Result Test Name MessagePass background-attachment: scroll
Pass background-attachment: fixed
@ -191,7 +191,7 @@ Fail background-position: right -.1em
Fail background-position: right top
Fail background-position: right center
Fail background-position: right bottom
Fail background-position: inherit
Pass background-position: inherit
Pass background-repeat: repeat
Pass background-repeat: repeat-x
Pass background-repeat: repeat-y
@ -630,7 +630,7 @@ Fail text-decoration: underline
Fail text-decoration: overline
Fail text-decoration: line-through
Fail text-decoration: blink
Fail text-decoration: inherit
Pass text-decoration: inherit
Pass text-indent: 0px
Pass text-indent: 1px
Pass text-indent: .1em