From 6d7bb074fc00298d6a11d70cfabdc9f146f2c32d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 7 Dec 2024 01:11:35 +0100 Subject: [PATCH] LibWeb: Don't serialize resolved CSS color values as named colors With all the plumbing in place, we can handle this quirk at the serialization layer. This allows us to remove the pass where StyleComputer would loop over all computed values and replace any color values with new values stripped of their original name strings. --- Libraries/LibWeb/CSS/StyleComputer.cpp | 11 ----------- Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 1b14606c152..f00126e38f8 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -2424,17 +2424,6 @@ Optional StyleComputer::compute_style_impl(DOM::Element& elemen start_needed_transitions(*previous_style, style, element, pseudo_element); } - // Remove color names from CSS color values. This is needed because computed values cannot be named colors. - for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) { - auto property_id = (CSS::PropertyID)i; - auto* property = style.maybe_null_property(property_id); - if (property && property->is_color()) { - auto& color_value = property->as_color(); - if (color_value.color_type() == CSSColorValue::ColorType::RGB) - style.set_property(property_id, CSSColorValue::create_from_color(color_value.to_color({}))); - } - } - return style; } diff --git a/Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp b/Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp index 9425b29cf75..a03d34603ac 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/CSSRGB.cpp @@ -70,10 +70,10 @@ bool CSSRGB::equals(CSSStyleValue const& other) const } // https://www.w3.org/TR/css-color-4/#serializing-sRGB-values -String CSSRGB::to_string(SerializationMode) const +String CSSRGB::to_string(SerializationMode mode) const { // FIXME: Do this properly, taking unresolved calculated values into account. - if (m_properties.name.has_value()) + if (mode != SerializationMode::ResolvedValue && m_properties.name.has_value()) return m_properties.name.value().to_string().to_ascii_lowercase(); return serialize_a_srgb_value(to_color({})); }