LibWeb: Handle nested shorthands in all-same-CSS-wide-keyword to_string

Previously we only checked direct sub-properties, not accounting for the
nested case.
This commit is contained in:
Callum Law 2025-06-10 17:38:55 +12:00 committed by Sam Atkins
commit 335190e925
Notes: github-actions[bot] 2025-06-16 11:39:18 +00:00
3 changed files with 26 additions and 8 deletions

View file

@ -8,6 +8,7 @@
#include "ShorthandStyleValue.h"
#include <LibGfx/Font/FontWeight.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
@ -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<Keyword> 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;