diff --git a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp index 16ede89b870..98718cf377b 100644 --- a/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.cpp @@ -8,6 +8,7 @@ #include "ShorthandStyleValue.h" #include #include +#include #include #include #include @@ -43,23 +44,25 @@ String ShorthandStyleValue::to_string(SerializationMode mode) const // If all the longhands are the same CSS-wide keyword, just return that once. Optional built_in_keyword; bool all_same_keyword = true; - for (auto& value : m_properties.values) { - if (!value->is_css_wide_keyword()) { + StyleComputer::for_each_property_expanding_shorthands(m_properties.shorthand_property, *this, [&](PropertyID name, CSSStyleValue const& value) { + (void)name; + if (!value.is_css_wide_keyword()) { all_same_keyword = false; - break; + return; } - auto keyword = value->to_keyword(); + auto keyword = value.to_keyword(); if (!built_in_keyword.has_value()) { built_in_keyword = keyword; - continue; + return; } if (built_in_keyword != keyword) { all_same_keyword = false; - break; + return; } - } + }); + if (all_same_keyword && built_in_keyword.has_value()) - return m_properties.values.first()->to_string(mode); + return MUST(String::from_utf8(string_from_keyword(built_in_keyword.value()))); auto default_to_string = [&]() { auto all_properties_same_value = true; diff --git a/Tests/LibWeb/Text/expected/css/nested-shorthand-css-wide-keyword-serialization.txt b/Tests/LibWeb/Text/expected/css/nested-shorthand-css-wide-keyword-serialization.txt new file mode 100644 index 00000000000..161886eb3b9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/nested-shorthand-css-wide-keyword-serialization.txt @@ -0,0 +1 @@ +#a { background: initial; } diff --git a/Tests/LibWeb/Text/input/css/nested-shorthand-css-wide-keyword-serialization.html b/Tests/LibWeb/Text/input/css/nested-shorthand-css-wide-keyword-serialization.html new file mode 100644 index 00000000000..73a75784ce8 --- /dev/null +++ b/Tests/LibWeb/Text/input/css/nested-shorthand-css-wide-keyword-serialization.html @@ -0,0 +1,14 @@ + + + + + +