Commit graph

130 commits

Author SHA1 Message Date
Andreas Kling
3cda08b6bf LibWeb: Numerically interpolate rotation angles for same-axis rotations
Per the CSS Transforms spec, when interpolating rotate3d() functions
with equal normalized direction vectors (or when one angle is zero),
the rotation angle should be interpolated numerically rather than
using quaternion slerp.

Previously we always used quaternion slerp, which cannot represent
rotations beyond 360 degrees. This meant that animating from
rotateY(0deg) to rotateY(3600deg) produced no visual animation, since
both quaternions are identical (3600 mod 360 = 0).

Now we detect when axes match and interpolate the angle directly,
correctly preserving multi-turn rotations. This fixes 168 WPT tests.
2026-03-21 23:16:32 -05:00
Andreas Kling
36e05884f4 LibWeb: Fall back to discrete interpolation for non-invertible matrices
Per the CSS Transforms spec, when one of the matrices for interpolation
is non-invertible (i.e. cannot be decomposed), the animation must fall
back to discrete interpolation.

Previously we would silently drop the transform, producing "none". Now
we correctly snap between the from/to values at the 50% progress mark,
matching the behavior required by the spec and other browsers.

Also propagate to_matrix() errors instead of silently using a partial
result, and use the previously-unused AllowDiscrete parameter.
2026-03-21 23:16:32 -05:00
Andreas Kling
a146225331 LibWeb: Use unsafe layout/paintable accessors where appropriate
Add unsafe_layout_node(), unsafe_paintable(), and unsafe_paintable_box()
accessors that skip layout-staleness verification. These are for use in
contexts where accessing layout/paintable data is legitimate despite
layout not being up to date: tree construction, style recalculation,
painting, animation interpolation, DOM mutation, and invalidation
propagation.

Also add wrapper APIs on Node to centralize common patterns:
- set_needs_display() wraps if (unsafe_paintable()) ...set_needs_display
- set_needs_paint_only_properties_update() wraps similar
- set_needs_layout_update() wraps if (unsafe_layout_node()) ...

And add Document::layout_is_up_to_date() which checks whether layout
tree update flags are all clear.
2026-02-26 21:09:08 +01:00
Callum Law
49eb9d7a7a LibWeb: Support composition of mixed values
This exposes an existing issue with interpolation where it is not clear
in what situations zero-valued dimensions should be excluded from the
interpolated value of a dimension-percentage mix (e.g. `calc(50% + 0px)`
vs `50%`) - but this is just a serialization issue as both
representations are resolved to the same used value
2026-02-23 09:01:19 +00:00
Callum Law
f7e5e57233 LibWeb: Make get_value_type_of_numeric_style_value reusable
This will also be used in composition of mixed types
2026-02-23 09:01:19 +00:00
Tim Ledbetter
918937231e LibWeb: Use premultiplied alpha when interpolating legacy sRGB colors
Previously, we were only using premultiplied alpha for non-legacy
colors after converting them to the Oklab color space.
2026-02-19 10:45:32 +00:00
Callum Law
9f7f623455 LibWeb: Store FilterOperation::DropShadow sub-values as StyleValues
This simplifies handling and brings it into line with other `StyleValue`
types
2026-02-16 12:09:23 +00:00
Callum Law
98e62cf86a LibWeb: Store FilterOperation::Blur::radius as StyleValue
This simplifies handling and brings it into line with other `StyleValue`
types
2026-02-16 12:09:23 +00:00
Callum Law
c529614e67 LibWeb: Store FilterOperation::HueRotate::angle as StyleValue
This simplifies handling and brings it into line with other `StyleValue`
types
2026-02-16 12:09:23 +00:00
Callum Law
68c596942c LibWeb: Store FilterOperation::Color::amount as StyleValue
This simplifies handling and means we now support tree counting
functions.
2026-02-16 12:09:23 +00:00
Callum Law
cd799aa7e7 LibWeb: Forward declare CSS::FilterOperation structs
This means we don't need to include `FilterValueListStyleValue.h` in as
many places - reducing the rebuild from editing that file from 717 files
to 19.
2026-02-16 12:09:23 +00:00
Tim Ledbetter
66246a0f3a LibWeb: Implement composition for grid track size lists 2026-01-26 03:20:08 +01:00
Callum Law
55ce89d513 LibWeb: Support composition of BasicShapeStyleValue
This also required supporting composition for it's constituent types
(`RadialSizeStyleValue` and `BorderRadiusRect`).

The remaining failing subtests in the two affected tests are because we
dont yet support compositing of mixed values
2026-01-22 11:29:41 +00:00
Callum Law
1029bac5fc LibWeb: Support composition of EdgeStyleValue
The remaining failing tests in `background-position-composition.html`
are because we dont yet support compositing of mixed values
2026-01-22 11:29:41 +00:00
Callum Law
51bea3b308 LibWeb: Clamp interpolation of RadialSizeStyleValue 2026-01-22 11:29:41 +00:00
Tim Ledbetter
115a794291 LibWeb: Implement composition of filter function lists 2026-01-16 11:29:30 +00:00
Callum Law
9b20fe6902 LibWeb: Promote font-style to ValueType
This means we now allow oblique angles when parsing the `font`
shorthand.

This also required us to rename the existing `FontStyle` enum to
`FontStyleKeyword`
2026-01-13 10:21:26 +00:00
Tim Ledbetter
49f8fafc2e LibWeb: Treat content-visibility auto as non-hidden in interpolation
This matches the interpolation behavior of the `visibility` property
and of other engines.
2026-01-13 10:49:31 +01:00
Tim Ledbetter
ba4a58fc0a LibWeb: Use correct angle calculation in quaternion_to_axis_angle()
For small rotations we were returning the quaternion's `w` component
directly. The angle returned should be `2*acos(w)` in all cases.
2026-01-13 09:36:47 +01:00
Tim Ledbetter
3ec53f5a3f LibWeb: Clamp filter function values to valid range when interpolating 2026-01-06 12:13:13 +01:00
Tim Ledbetter
5de5e7522b LibWeb: Implement interpolation of drop-shadow() filter functions 2026-01-06 12:13:13 +01:00
Tim Ledbetter
584e0996c9 LibWeb: Store color as a StyleValue in FilterOperation::DropShadow 2026-01-06 12:13:13 +01:00
Callum Law
ed8eab03d0 LibWeb: Support interpolation of BorderRadiusRectStyleValue 2026-01-06 10:50:06 +01:00
Callum Law
1b7567cc86 LibWeb: Support parsing of border radius in inset() function
Respecting this value during basic shape path resolution is yet to be
implemented
2026-01-06 10:50:06 +01:00
Callum Law
6964593377 LibWeb: Add absolutized method to EdgeStyleValue
Fixes #7192.

We absolutize `EdgeStyleValue` to always be relative to the top/left
edge which allows for some simplification.
2026-01-02 11:43:10 +01:00
Callum Law
e6ddb7db9e LibWeb: Store EdgeStyleValue sub-values directly
As well as being required to implement absolutization this also means we
now bypass a limitation with `LengthPercentage` where we would always
use `SerializationMode::Normal` for the constituent lengths which gains
us some WPT passes
2026-01-02 11:43:10 +01:00
Sam Atkins
c446281844 LibWeb/CSS: Remove Transformation in favor of TransformationStyleValue
The Transformation class wasn't really accomplishing anything. It still
had to store StyleValues, so it was basically the same as
TransformationStyleValue, with extra steps to convert from one to the
other. So... let's just use TransformationStyleValue instead!

Apart from moving code around, the behavior has changed a bit. We now
actually acknowledge unresolvable parameters and return an error when
we try to produce a matrix from them. Previously we just skipped over
them, which was pretty wrong. This gets us an extra pass in the
typed-om test.

We also get some slightly different results with our transform
serialization, because we're not converting to CSSPixels and back.
2025-12-19 14:51:53 +01:00
Sam Atkins
6b5836644a LibWeb/CSS: Use PaintableBox for matrix interpolation when available 2025-12-19 14:51:53 +01:00
Callum Law
f17f4f233d LibWeb: Don't serialize omitted ellipse() position argument 2025-12-12 12:20:16 +00:00
Callum Law
daf464844b LibWeb: Support all <radial-extent> values in ellipse()
To do this we use the generic `RadialSizeStyleValue` which allows us to
remove the remaining logic around `<shape-radius>`
2025-12-12 12:20:16 +00:00
Callum Law
ad1083f14e LibWeb: Don't serialize omitted circle() position argument
This should only be defaulted to `center` at use time
2025-12-12 12:20:16 +00:00
Callum Law
8501d6995d LibWeb: Support all <radial-extent> values in circle() 2025-12-12 12:20:16 +00:00
Callum Law
73f41b20b4 LibWeb: Compute rect() and xywh() to their equivalent inset()
This also allows us to remove the path generation and interpolation
handling for `rect()` and `xywh()` since that occurs after computation

Regressions in clip-path-interpolation-xywh.html are due to improper
simplification of length-percentage mixes where the length is 0px.
2025-12-09 11:23:59 +00:00
Callum Law
6a682c5f2b LibWeb: Make logic for creating CalculationNode from StyleValue reusable
This is useful in places other than just interpolation
2025-12-09 11:23:59 +00:00
Callum Law
0c72b757a4 LibWeb: Use correct calculation context for interpolating basic shapes
This allows us to interpolate between a length and a percentage (or vice
versa)
2025-12-09 11:23:59 +00:00
Callum Law
6466001367 LibWeb: Store BasicShapeStyleValue sub-values directly
Storing these within `LengthPercentage`, `LengthBox`, and `Variant`
over-complicated things.

We also now use the correct `SerializationMode` when serializing `xywh`
and `rect`
2025-12-09 11:23:59 +00:00
Callum Law
0595d52be2 LibWeb: Simplify handling of {text,box}-shadow
We know that shadow values are always parsed as a `KeywordStyleValue`
with `Keyword::None` or a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
46abc0e8e2 LibWeb: Handle calc in multi-argument rotate property interpolation
Previously we assumed the angle would always be an `AngleStyleValue` but
it can also be a `CalculatedStyleValue`

Fixes #6870
2025-11-23 09:43:24 +01:00
Sam Atkins
c4b9e7eadf LibWeb: Parse and propagate extended text-indent property values
CSS Text 3 gives `text-indent` a couple of optional keywords to control
which lines are affected. This commit parses them, but doesn't yet do
anything with them.
2025-11-20 16:02:40 +01:00
Jelle Raaijmakers
674e1a5c47 LibWeb: Support transitions between 3D and non-derivative 2D functions
If either of the two transform functions during interpolation is a 3D
function, both of them get coerced to a 3D function before deciding what
to do next. However, we only supported converting 2D functions to 3D if
they had a 2D primitive they could be converted to first.

Change our behavior to default to converting to matrix3d() if there is
no explicit conversion path. Fixes a crash in
`css/css-transforms/animation/transform-interpolation-004.html`.
2025-11-19 10:08:11 +01:00
Jelle Raaijmakers
9394c9a10b LibWeb: Deduplicate transformation creation logic
We had two code blocks responsible for turning a
TransformationStyleValue into a Transformation; get rid of one.
2025-11-18 14:36:26 +01:00
Jelle Raaijmakers
e4dc2663ba LibWeb: Reimplement transform interpolation according to spec
We had a partial implementation of transformation function interpolation
that did not support numerical interpolation of simple functions (e.g.
`scale(0)` -> `scale(1)`). This refactors the interpolation to follow
the spec more closely.

Gains us 267 WPT subtest passes in `css/css-transforms`.

Fixes #6774.
2025-11-18 14:36:26 +01:00
Callum Law
ec14948175 LibWeb: Handle calc percentages when interpolating scale function
Also clean up the corresponding handling in
TransformationStyleValue::to_transformation
2025-11-16 22:50:01 +01:00
Callum Law
f49cf75d44 LibWeb: Don't pass unnecessary PropertyComputationDependencies struct
Since we now have access to the `AbstractElement` through the
`ComputationContext` we can just set the flag that this element relies
on tree counting functions directly, no need to pass this struct around.
2025-10-22 00:01:30 +02:00
Callum Law
2404f95e03 LibWeb: Invalidate style for tree counting functions when required
We mark any element that relies on tree counting functions as needing a
style update when a sibling is inserted/removed.
2025-10-20 16:12:08 +01:00
Sam Atkins
0afa93e639 LibWeb/CSS: Add a Property -> CalculationContext factory method
We have this code duplicated in multiple places, and we'll want to
handle registered custom properties too at some point, so wrap it in a
reusable `CalculationContext::for_property()` method.

Noticed while doing this that ValueParsingContext will eventually need
to take a PropertyNameAndID, not a PropertyID, so I've added a FIXME.
2025-10-13 09:59:38 +01:00
Callum Law
102edf638d LibWeb: Support interpolation of SuperellipseStyleValue 2025-10-09 10:23:20 +01:00
Callum Law
25192d3c20 LibWeb: Store BorderRadiusStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
2ebf446cbf LibWeb: Store BackgroundSizeStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
309ff33278 LibWeb: Add convenience from_style_value for LengthPercentage{OrAuto} 2025-10-07 10:50:01 +01:00