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.
This commit is contained in:
Andreas Kling 2024-12-07 01:11:35 +01:00 committed by Sam Atkins
parent b3c4b4fd97
commit 6d7bb074fc
Notes: github-actions[bot] 2024-12-07 08:31:53 +00:00
2 changed files with 2 additions and 13 deletions

View file

@ -2424,17 +2424,6 @@ Optional<StyleProperties> 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;
}

View file

@ -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({}));
}