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 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.
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.
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.
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`.