Commit Graph

6 Commits

Author SHA1 Message Date
Andreas Kling
0103940cee LibWeb: Resolve viewport-relative <img sizes> values
We still don't know how to resolve font-relative lengths in <img sizes>
since we don't always have font size information available at this stage
in the pipeline, but we can at least handle viewport-relative lengths.

This fixes an issue on many websites where low-resolution images were
loaded (appropriate for a small viewport) even when the viewport is big.
2023-08-21 13:56:18 +02:00
Andreas Kling
95097e47a7 LibWeb: Allow calc() values in image sizes attribute
Note that we currently can't resolve calc() values without a layout
node, so when normalizing an image's source set, we'll flush any pending
layout updates and hope that gives us an up-to-date layout node.

I've left a FIXME about implementing this in a more elegant and less
layout-thrashy way, as that will require more architectural work.
2023-07-29 11:58:51 +02:00
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
Andi Gallo
c411b5408e LibWeb: Improve support for selecting an image source
Apply media conditions before selecting a size and add an algorithm to
select an image source based on pixel density.
2023-05-28 12:11:10 +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
6fe4fcb74b LibWeb: Add a class to represent the "source set" concept from HTML
Also comes with a little extra CSS parser helper for parsing "sizes"
attributes in images.
2023-05-13 09:08:42 +02:00