mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
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:
Notes:
github-actions[bot]
2024-10-22 13:19:12 +00:00
Author: https://github.com/ronak69 Commit: https://github.com/LadybirdBrowser/ladybird/commit/6c3ecf6a342 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1857 Reviewed-by: https://github.com/nico
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user