1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

LibWeb: Make CSSPixels and Length use 64-bit (double) floating point

This fixes a plethora of rounding problems on many websites.
In the future, we may want to replace this with fixed-point arithmetic
(bug #18566) for performance (and consistency with other engines),
but in the meantime this makes the web look a bit better. :^)

There's a lot more things that could be converted to doubles, which
would reduce the amount of casting necessary in this patch.
We can do that incrementally, however.
This commit is contained in:
Andreas Kling 2023-05-24 10:50:57 +02:00
parent 30262d7023
commit 655d9d1462
80 changed files with 298 additions and 299 deletions

View file

@ -105,12 +105,11 @@ CSSPixelRect Page::device_to_css_rect(DevicePixelRect rect) const
DevicePixelRect Page::enclosing_device_rect(CSSPixelRect rect) const
{
auto scale = client().device_pixels_per_css_pixel();
return {
floorf(rect.x().value() * scale),
floorf(rect.y().value() * scale),
ceilf(rect.width().value() * scale),
ceilf(rect.height().value() * scale)
};
return DevicePixelRect(
floor(rect.x().value() * scale),
floor(rect.y().value() * scale),
ceil(rect.width().value() * scale),
ceil(rect.height().value() * scale));
}
DevicePixelRect Page::rounded_device_rect(CSSPixelRect rect) const

View file

@ -166,7 +166,7 @@ public:
virtual bool is_connection_open() const = 0;
virtual Gfx::Palette palette() const = 0;
virtual DevicePixelRect screen_rect() const = 0;
virtual float device_pixels_per_css_pixel() const = 0;
virtual double device_pixels_per_css_pixel() const = 0;
virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0;
virtual void paint(DevicePixelRect const&, Gfx::Bitmap&) = 0;
virtual void page_did_change_title(DeprecatedString const&) { }