LibWeb/CSS: Tweak in CSSRGB::to_color() to avoid floating point errors

Example of the difference:

    50 * 2.55      --> 127.4999 --> round towards +∞ --> 127
    50 * 255 / 100 --> 127.5000 --> round towards +∞ --> 128

Now, 9 failing WPT tests in /css/css-color/ pass.
This commit is contained in:
ronak69
2024-10-18 09:40:13 +00:00
committed by Sam Atkins
parent 3e8b2454fb
commit 6c3ecf6a34
Notes: github-actions[bot] 2024-10-22 13:19:12 +00:00
3 changed files with 5 additions and 2 deletions

View File

@@ -25,14 +25,14 @@ Color CSSRGB::to_color(Optional<Layout::NodeWithStyle const&>) const
return normalized(style_value.as_number().number());
if (style_value.is_percentage())
return normalized(style_value.as_percentage().value() * 2.55);
return normalized(style_value.as_percentage().value() * 255 / 100);
if (style_value.is_math()) {
auto const& calculated = style_value.as_math();
if (calculated.resolves_to_number())
return normalized(calculated.resolve_number().value());
if (calculated.resolves_to_percentage())
return normalized(calculated.resolve_percentage().value().value() * 2.55);
return normalized(calculated.resolve_percentage().value().value() * 255 / 100);
}
if (style_value.is_keyword() && style_value.to_keyword() == Keyword::None)