1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

LibWeb+WebContent: Forbid access to underlying type of CSSPixels

Although DistinctNumeric, which is supposed to abstract the underlying
type, was used to represent CSSPixels, we have a whole bunch of places
in the layout code that assume CSSPixels::value() returns a
floating-point type. This assumption makes it difficult to replace the
underlying type in CSSPixels with a non-floating type.

To make it easier to transition CSSPixels to fixed-point math, one step
we can take is to prevent access to the underlying type using value()
and instead use explicit conversions with the to_float(), to_double(),
and to_int() methods.
This commit is contained in:
Aliaksandr Kalenik 2023-06-12 21:37:35 +03:00 committed by Andreas Kling
parent 5a54c686a7
commit 147c3b3d97
43 changed files with 340 additions and 220 deletions

View file

@ -91,8 +91,8 @@ CSSPixelPoint Page::device_to_css_point(DevicePixelPoint point) const
DevicePixelPoint Page::css_to_device_point(CSSPixelPoint point) const
{
return {
point.x().value() * client().device_pixels_per_css_pixel(),
point.y().value() * client().device_pixels_per_css_pixel(),
(point.x() * client().device_pixels_per_css_pixel()).to_int(),
(point.y() * client().device_pixels_per_css_pixel()).to_int(),
};
}
@ -111,20 +111,20 @@ DevicePixelRect Page::enclosing_device_rect(CSSPixelRect rect) const
{
auto scale = client().device_pixels_per_css_pixel();
return DevicePixelRect(
floor(rect.x().value() * scale),
floor(rect.y().value() * scale),
ceil(rect.width().value() * scale),
ceil(rect.height().value() * scale));
floor(rect.x().to_double() * scale),
floor(rect.y().to_double() * scale),
ceil(rect.width().to_double() * scale),
ceil(rect.height().to_double() * scale));
}
DevicePixelRect Page::rounded_device_rect(CSSPixelRect rect) const
{
auto scale = client().device_pixels_per_css_pixel();
return {
roundf(rect.x().value() * scale),
roundf(rect.y().value() * scale),
roundf(rect.width().value() * scale),
roundf(rect.height().value() * scale)
roundf(rect.x().to_double() * scale),
roundf(rect.y().to_double() * scale),
roundf(rect.width().to_double() * scale),
roundf(rect.height().to_double() * scale)
};
}