mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
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:
parent
b3c4b4fd97
commit
6d7bb074fc
Notes:
github-actions[bot]
2024-12-07 08:31:53 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/6d7bb074fc0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2820 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 2 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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({}));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue