mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-18 08:20:44 +00:00
LibWeb: Don't resolve color components when serializing color functions
Previously, we were incorrectly replacing color components with `None` values with 0.
This commit is contained in:
parent
a97fe3123d
commit
55769be9c6
Notes:
github-actions[bot]
2025-04-09 11:12:32 +00:00
Author: https://github.com/tcl3
Commit: 55769be9c6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4245
Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 164 additions and 182 deletions
|
@ -93,55 +93,37 @@ ColorFunctionStyleValue::Resolved ColorFunctionStyleValue::resolve_properties()
|
|||
// https://www.w3.org/TR/css-color-4/#serializing-color-function-values
|
||||
String ColorFunctionStyleValue::to_string(SerializationMode mode) const
|
||||
{
|
||||
if (mode == SerializationMode::Normal) {
|
||||
auto convert_percentage = [](ValueComparingNonnullRefPtr<CSSStyleValue> const& value) -> RemoveReference<decltype(value)> {
|
||||
if (value->is_percentage())
|
||||
return NumberStyleValue::create(value->as_percentage().value() / 100);
|
||||
return value;
|
||||
};
|
||||
auto convert_percentage = [](ValueComparingNonnullRefPtr<CSSStyleValue> const& value) -> RemoveReference<decltype(value)> {
|
||||
if (value->is_percentage())
|
||||
return NumberStyleValue::create(value->as_percentage().value() / 100);
|
||||
return value;
|
||||
};
|
||||
|
||||
auto alpha = convert_percentage(m_properties.alpha);
|
||||
auto alpha = convert_percentage(m_properties.alpha);
|
||||
|
||||
bool const is_alpha_required = [&]() {
|
||||
if (alpha->is_number())
|
||||
return alpha->as_number().value() < 1;
|
||||
return true;
|
||||
}();
|
||||
bool const is_alpha_required = [&]() {
|
||||
if (alpha->is_number())
|
||||
return alpha->as_number().value() < 1;
|
||||
return true;
|
||||
}();
|
||||
|
||||
if (alpha->is_number() && alpha->as_number().value() < 0)
|
||||
alpha = NumberStyleValue::create(0);
|
||||
if (alpha->is_number() && alpha->as_number().value() < 0)
|
||||
alpha = NumberStyleValue::create(0);
|
||||
|
||||
if (is_alpha_required) {
|
||||
return MUST(String::formatted("color({} {} {} {} / {})",
|
||||
string_view_from_color_type(m_color_type),
|
||||
convert_percentage(m_properties.channels[0])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[1])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[2])->to_string(mode),
|
||||
alpha->to_string(mode)));
|
||||
}
|
||||
|
||||
return MUST(String::formatted("color({} {} {} {})",
|
||||
if (is_alpha_required) {
|
||||
return MUST(String::formatted("color({} {} {} {} / {})",
|
||||
string_view_from_color_type(m_color_type),
|
||||
convert_percentage(m_properties.channels[0])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[1])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[2])->to_string(mode)));
|
||||
convert_percentage(m_properties.channels[2])->to_string(mode),
|
||||
alpha->to_string(mode)));
|
||||
}
|
||||
|
||||
auto resolved = resolve_properties();
|
||||
if (resolved.alpha == 1) {
|
||||
return MUST(String::formatted("color({} {} {} {})",
|
||||
string_view_from_color_type(m_color_type),
|
||||
resolved.channels[0],
|
||||
resolved.channels[1],
|
||||
resolved.channels[2]));
|
||||
}
|
||||
|
||||
return MUST(String::formatted("color({} {} {} {} / {})",
|
||||
return MUST(String::formatted("color({} {} {} {})",
|
||||
string_view_from_color_type(m_color_type),
|
||||
resolved.channels[0],
|
||||
resolved.channels[1],
|
||||
resolved.channels[2],
|
||||
resolved.alpha));
|
||||
convert_percentage(m_properties.channels[0])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[1])->to_string(mode),
|
||||
convert_percentage(m_properties.channels[2])->to_string(mode)));
|
||||
}
|
||||
|
||||
Color ColorFunctionStyleValue::to_color(Optional<Layout::NodeWithStyle const&>) const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue