Commit Graph

6 Commits

Author SHA1 Message Date
Aliaksandr Kalenik
147c3b3d97 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.
2023-06-13 06:08:27 +02:00
Andreas Kling
655d9d1462 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.
2023-05-24 14:40:35 +02:00
Andreas Kling
134717ec8f LibWeb: VERIFY that nobody tries to hash a non-finite CSSPixels value
Non-finite CSSPixels quantities should never make their way into hash
tables. If this ever happens, let's catch it closer to the source
instead of letting things cascade into confusion.
2023-05-06 18:41:34 +02:00
Timothy Flynn
dbc04bbf1b LibWeb: Use type-correct hashing and formatting functions for pixels
1. Don't use double_hash. This is not for doubles, as its name implies.

2. Specialize traits and formatters using the underlying DistinctNumeric
   type of Web::DevicePixels and Web::CSSPixels.
2023-01-21 10:36:14 +01:00
Sam Atkins
a3298017d6 LibWeb: Only allow DevicePixels operators to work with integers
Allowing floats here was causing accidental truncations.

Co-authored-by: MacDue <macdue@dueutil.tech>
2022-12-14 16:47:57 +00:00
Sam Atkins
bd272e638c LibWeb: Introduce CSSPixels and DevicePixels classes
These are an attempt to separate the internal "pixel" used by CSS from
the actual "pixel" that exists on the display. Because of things like
2x display scaling, the ratio between these can vary, so having
distinct types will help prevent errors when converting from one unit
to the other.

`CSSPixels` refers to the `px` unit used on the web, which depending on
the device may or may not map to 1 pixel on the physical display. It's
a wrapper around `float`, and will be used by LibWeb for size and
position values up until we go to paint them to the screen.

`DevicePixels` on the other hand is a 1-to-1 pixel on the physical
display. It's a wrapper around `int`.
2022-12-08 12:46:03 +00:00