Commit graph

129 commits

Author SHA1 Message Date
Andreas Kling
cf704cfbfc LibWeb: Implement interpolation for CSS scale values
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
And let's handle the 3rd (Z) scale parameter as well, while we're here.

At least 242 new passes on WPT.
2025-04-25 14:08:12 +02:00
Andreas Kling
1772adb600 LibWeb: Don't crash on non-finite values in CSS clamp() function
Stops a WPT test from crashing, giving us 29 new subtest passes. :^)
2025-04-24 18:26:54 +02:00
Tim Ledbetter
0beb22f19e LibWeb: Implement interpolation of edge values 2025-04-23 09:13:45 +01:00
Tim Ledbetter
6f5b107fcc LibWeb: Resolve absolute calc() values in color functions
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Currently, `calc()` values with relative units are not handled
correctly and will output an error to the console.
2025-04-22 12:20:26 +02:00
Tim Ledbetter
9cf04f40f6 LibWeb: Implement the color-mix() function
This takes 2 color values and returns the result of mixing them by a
given amount.
2025-04-22 12:19:51 +02:00
Tim Ledbetter
e860dd4f65 LibWeb: Implement serialization of lch-like color values 2025-04-20 16:51:20 +02:00
Tim Ledbetter
5074d90888 LibWeb: Implement serialization of lab-like color values 2025-04-20 16:51:20 +02:00
Andreas Kling
57809b1100 LibWeb: Skip dynamic_cast in CSSRGB after we already did a type check 2025-04-18 14:45:56 +02:00
Andrew Kaster
d1f6f5649e LibWeb: Make storage of CSS::CalculationNodes const-correct
Now we consistently use `RefPtr<CalculationNode const>` for all
CalculationNodes.
2025-04-16 10:41:44 -06:00
Andrew Kaster
6d11414957 LibWeb: Make storage of CSS::StyleValues const-correct
Now we consistently use `RefPtr<StyleValue const>` for all StyleValues.
2025-04-16 10:41:44 -06:00
Sam Atkins
c224644bed LibWeb/CSS: Fetch ImageStyleValue images closer to spec
We now don't absolutize the URL during parsing, keeping it as a CSS::URL
object which we then pass to the "fetch an external image for a
stylesheet" algorithm. Our version of this algorithm is a bit ad-hoc,
in order to make use of SharedResourceRequest. To try and reduce
duplication, I've pulled all of fetch_a_style_resource() into a static
function, apart from the "actually do the fetch" step.
2025-04-15 09:54:35 +01:00
Sam Atkins
9f00425dad LibWeb/CSS: Let CSSStyleValue know its CSSStyleSheet
The CSS `fetch_foo()` functions resolve the URL relative to the
CSSStyleSheet if one is provided. So, style values that do so need to
know what CSSStyleSheet they are part of so that, for example, `url
(foo.png)` is loaded relative to the style sheet's URL instead of the
document's one.

That all works without this change because we currently absolutize URLs
during parsing, but we're in the process of stopping that.

This commit adds the infrastructure for telling style values what their
CSSStyleSheet is.
2025-04-15 09:54:35 +01:00
Sam Atkins
f1af4bcc58 LibWeb: Include SharedResourceRequest.h where it's used
ImageStyleValue.h can rely on the forward-declaration.
2025-04-15 09:54:35 +01:00
Aliaksandr Kalenik
6507d23e29 LibWeb: Save ScrollState snapshot in DisplayList to avoid race condition
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
With this change we save a copy of of scroll state at the time of
recording a display list, instead of actual ScrollState pointer that
could be modifed by the main thread while display list is beings
rasterized on the rendering thread, which leads to a frame painted with
inconsistent scroll state.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/4288
2025-04-12 02:55:18 +02:00
Sam Atkins
c82f4b46a2 LibWeb/CSS: Qualify uses of LibURL
To prepare for introducing a CSS::URL type, we need to qualify any use
of LibURL as `::URL::foo` instead of `URL::foo` so the compiler doesn't
get confused.

Many of these uses will be replaced, but I don't want to mix this in
with what will likely already be a large change.
2025-04-09 18:45:57 +01:00
Tim Ledbetter
55769be9c6 LibWeb: Don't resolve color components when serializing color functions
Previously, we were incorrectly replacing color components with `None`
values with 0.
2025-04-09 12:11:33 +01:00
Tim Ledbetter
a97fe3123d LibWeb: Don't convert color functions to RGB when resolving color values 2025-04-09 12:11:33 +01:00
Tim Ledbetter
02d34dd021 LibWeb: Rename CSSColor to ColorFunctionStyleValue
This gives a better idea of what the class represents.
2025-04-09 12:11:33 +01:00
Timothy Flynn
f070264800 Everywhere: Remove sv suffix from format string literals
This prevents the compile-time checks that would catch errors in the
format invocation (which would usually lead to a runtime crash).
2025-04-08 20:00:18 -04:00
Tim Ledbetter
263cb3f8ca LibWeb/CSS: Remove unnecessary shorthand serialization special cases
The serialization of these properties is improved by using the new
default behavior.
2025-04-07 11:38:56 +01:00
Tim Ledbetter
3186adeaa1 LibWeb/CSS: Don't serialize longhands which match their initial values
Shorthand subproperties that match their initial values are now
excluded from serialization, by default.

Properties where this behavior is not desired, like `gap`, are
special-cased.
2025-04-07 11:38:56 +01:00
Sam Atkins
ee647616b2 LibWeb/CSS: Serialize @font-face closer to spec
Read the descriptor style values instead of producing a ParsedFontFace
first, as this means we know if a descriptor is actually present, or
has been defaulted to an initial value. This lets us correctly skip the
unicode-range if it was not explicitly set.

Firefox and Chromium both serialize using the "font-stretch" name,
(which is an alias for font-width) which follows the outdated cssom
spec, so I've done so too to match them.

The one thing that we still do differently in this test is that those
browsers check explicitly if `font-stretch` was set, and ignore when
`font-width` is.

I've also inlined the `serialize_a_local()` function to the one place
it's used. The style value to_string() method was already wrapping the
string in quotes, so calling serialize_a_string() on it was producing
`local("\this mess\"")`. It's clearer what's happening when the code
isn't split up.
2025-04-07 10:00:21 +01:00
Sam Atkins
a7f7c2a821 LibWeb/CSS: Teach OpenTypeTaggedStyleValue to serialize without "1" 2025-04-07 10:00:21 +01:00
Tim Ledbetter
e5f21b2f9c LibWeb: Set blur filter radius to 0px if omitted 2025-04-04 17:12:47 +01:00
Tim Ledbetter
2ee86d1e18 LibWeb: Set hue-rotate angle to 0 degrees if omitted 2025-04-04 17:12:47 +01:00
Tim Ledbetter
61f76c7ec5 LibWeb: Set color filter value to 1 if omitted 2025-04-04 17:12:47 +01:00
Tim Ledbetter
46411295d6 LibWeb: Serialize drop-shadow filter properties in canonical order 2025-04-04 17:12:47 +01:00
Sam Atkins
1bc73ed4a8 LibWeb/CSS: Add missing include to StringStyleValue.h 2025-04-04 10:40:32 +01:00
Sam Atkins
60c536bdd5 LibWeb/CSS: Add FontSourceStyleValue
This will be used by the `@font { src: ... }` descriptor once we parse
descriptors as style values.
2025-04-04 10:40:32 +01:00
Aliaksandr Kalenik
24527b6ae3 LibWeb: Pass PaintingSurface into DisplayListPlayer::execute()
Deleteing set_surface() makes DisplayListPlayer API a bit more intuitive
because now caller doesn't have to think whether it's necessary to
restore previous surface after execution, instead DisplayListPlayer
takes care of it by maintaining a stack of surfaces.
2025-04-01 23:39:05 +02:00
Sam Atkins
09b8f73e11 LibWeb/CSS: Implement UnicodeRangeStyleValue
This is preparation for storing at-rule descriptors as style values.
2025-03-28 09:15:02 +00:00
Sam Atkins
a2c89f585f LibWeb/CSS: Give all style values a visit_edges() method
Having this hidden away in ImageStyleValue meant that
CSSStyleProperties (and anyone else who holds style values) had to know
exactly which types need visiting. This is a footgun waiting to happen,
so make this a virtual method on CSSStyleValue instead.
2025-03-27 11:53:09 +00:00
Jelle Raaijmakers
6a3c3ee291 LibWeb: Coerce NaNs to 0 when escaping top-level calculations 2025-03-25 19:53:36 +00:00
Jelle Raaijmakers
545d151948 LibWeb: Make transform: scale(calc(..)) work
The `transform` property supports transform functions that sometimes
need their `calc(percentage)` values to be converted to a number instead
of a length. Currently this only applies to the `scale*` family of
functions, which are marked as such in `TransformFunctions.json`.

We were not consistently applying the `NumberPercentage` type to these
functions though, and in addition, any `NumberPercentage` value would
not consider calculated values.
2025-03-25 19:53:36 +00:00
Tim Ledbetter
9ce5bbe059 LibWeb: Remove CubicBezier cached sample inline cache
This reduces the size of CubicBezier objects from 1592 bytes to 56
bytes.
2025-03-25 07:51:27 +00:00
Tim Ledbetter
5bfbb7abe6 LibWeb: Preserve unit when serializing angle values
Previously, when serializing an angle value, we would always convert it
to degrees. We now canonicalize the angle value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
d0be5a0cdf LibWeb: Preserve unit when serializing time values
Previously, when serializing a time value, we would always convert it
to seconds. We now canonicalize the time value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
c029a9c98c LibWeb: Serialize grid-area as auto if all sub-properties are auto 2025-03-20 16:59:27 +00:00
Tim Ledbetter
54351e7327 LibWeb: Use shortest serialization for shorthands with repeated values
For shorthands where all the values are repeated, we now only output
the value once.
2025-03-20 14:30:55 +01:00
Tim Ledbetter
f0917ea150 LibWeb: Ensure shortest serialization is used for grid-column values 2025-03-19 02:08:05 +01:00
Tim Ledbetter
6811264b11 LibWeb: Ensure shortest serialization is used for grid-row values 2025-03-19 02:08:05 +01:00
Tim Ledbetter
f6a8e5aa68 LibWeb: Use correct canonical serialization for BorderRadiusStyleValue 2025-03-18 21:55:06 +01:00
Tim Ledbetter
85728b297f LibWeb: Ensure the shortest serialization is used for border-radius
This implementation also fixes an issue where the individual components
of the `border-radius` shorthand were always assumed to be of type
`BorderRadiusStyleValue`, which could lead to a crash when CSS-wide
keywords were used.
2025-03-18 21:55:06 +01:00
InvalidUsernameException
d76f841994 LibWeb: Do not deform bitmaps partially outside the img-box
Instead of trying to manually determine which parts of a bitmap fall
within the box of the `<img>` element, just draw the whole bitmap and
let Skia clip the draw-area to the correct rectangle.

This fixes a bug where the entire bitmap was squashed into the rectangle
of the image box instead of being clipped.

With this change, image rendering is now correct enough to import some
of the WPT tests for object-fit and object-position. To get some good
coverage I have imported all tests for the `<img>` tag. I also wanted to
import a subset of the tests for the `<object>` tag, since those are
passing as well now. Unfortunately, they are flaky for unknown reasons.

This is the second attempt at this bugfix. The prior one was e055927ead
and broke image rendering whenever the page was scrolled. It has
subsequently been reverted in 16b14273d1. Hopefully this time it is not
horribly broken.
2025-03-10 17:14:13 +01:00
Gingeh
31853c13d3 LibWeb: Implement css gradient-interpolation-method 2025-03-06 11:33:12 +00:00
Aliaksandr Kalenik
16b14273d1 Revert "LibWeb: Do not deform bitmaps partially outside the img-box"
This change broken image rendering.

This reverts commit e055927ead.
2025-03-05 19:44:49 +01:00
InvalidUsernameException
e055927ead LibWeb: Do not deform bitmaps partially outside the img-box
Instead of trying to manually determine which parts of a bitmap fall
within the box of the `<img>` element, just draw the whole bitmap and
let Skia clip the draw-area to the correct rectangle.

This fixes a bug where the entire bitmap was squashed into the rectangle
of the image box instead of being clipped.

With this change, image rendering is now correct enough to import some
of the WPT tests for object-fit and object-position. To get some good
coverage I have imported all tests for the `<img>` tag. I also wanted to
import a subset of the tests for the `<object>` tag, since those are
passing as well now. Unfortunately, they are flaky for unknown reasons.
2025-03-05 16:32:47 +01:00
Sam Atkins
d127d412c8 LibWeb/CSS: Implement CursorStyleValue
A cursor is an image, with an optional x,y hotspot.

We know that a CursorStyleValue's bitmap never needs to change size, so
we create the ShareableBitmap once and then cache it, so that we don't
have to repeatedly create an FD for it or do the work of painting.

To avoid repainting that bitmap, we cache the values that were used to
create it - what currentColor is and its length resolution context -
and only repaint when those change.
2025-02-28 13:50:13 +01:00
Sam Atkins
9cbd8a82c7 LibWeb: Only require NodeWithStyle for gradient size resolution
None of the code here actually needs a NodeWithStyleAndBoxModelMetrics,
and we'll need to be able to resolve images from inside
NodeWithStyle::apply_style().
2025-02-28 13:50:13 +01:00
Sam Atkins
09d2c5eb9b LibWeb/CSS: Remove unused includes from CSSStyleValue.h
A couple of these were needed transitively, so I've added them to the
relevant files.
2025-02-28 13:50:13 +01:00