LibWeb: Serialize RGB, HWB and HSL colors with unresolved components

Gains us 44 WPT passes.
This commit is contained in:
Callum Law 2025-07-04 12:37:09 +12:00 committed by Sam Atkins
commit 33cf3d7782
Notes: github-actions[bot] 2025-07-16 12:06:41 +00:00
6 changed files with 95 additions and 58 deletions

View file

@ -92,8 +92,20 @@ String CSSRGB::to_string(SerializationMode mode) const
if (auto color = to_color({}, {}); color.has_value())
return serialize_a_srgb_value(color.value());
// FIXME: Do this properly, taking unresolved calculated values into account.
return ""_string;
StringBuilder builder;
builder.append("rgb("sv);
serialize_color_component(builder, mode, m_properties.r, 255, 0, 255);
builder.append(" "sv);
serialize_color_component(builder, mode, m_properties.g, 255, 0, 255);
builder.append(" "sv);
serialize_color_component(builder, mode, m_properties.b, 255, 0, 255);
if ((!m_properties.alpha->is_number() || m_properties.alpha->as_number().number() < 1) && (!m_properties.alpha->is_percentage() || m_properties.alpha->as_percentage().percentage().as_fraction() < 1)) {
builder.append(" / "sv);
serialize_alpha_component(builder, mode, m_properties.alpha);
}
builder.append(")"sv);
return builder.to_string_without_validation();
}
}