mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Serialize RGB, HWB and HSL colors with unresolved components
Gains us 44 WPT passes.
This commit is contained in:
parent
6a9c8d7767
commit
33cf3d7782
Notes:
github-actions[bot]
2025-07-16 12:06:41 +00:00
Author: https://github.com/Calme1709
Commit: 33cf3d7782
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5305
Reviewed-by: https://github.com/AtkinsSJ ✅
6 changed files with 95 additions and 58 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <AK/TypeCasts.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
@ -36,13 +37,27 @@ bool CSSHSL::equals(CSSStyleValue const& other) const
|
|||
}
|
||||
|
||||
// https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
|
||||
String CSSHSL::to_string(SerializationMode) const
|
||||
String CSSHSL::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("hsl("sv);
|
||||
serialize_hue_component(builder, mode, m_properties.h);
|
||||
builder.append(" "sv);
|
||||
serialize_color_component(builder, mode, m_properties.s, 100, 0);
|
||||
builder.append(" "sv);
|
||||
serialize_color_component(builder, mode, m_properties.l, 100, 0);
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue