Commit Graph

2065 Commits

Author SHA1 Message Date
Callum Law
2c3ddc294f LibWeb: Compute math-depth in line with other font properties
The main change here is that we now properly absolutize values which
means we now support `random()` and `sibling-{count,index}()`

We are also more consistent with how we handle computation for the other
font properties
2026-01-15 12:03:16 +00:00
Callum Law
27dd77a538 LibWeb: Don't store resolved math depth directly
There's no need to store this twice

We also now use `set_property_without_modifying_flags` to avoid
overwriting inherited/important flags
2026-01-15 12:03:16 +00:00
Callum Law
eb5b73d3b5 LibWeb: Use existing StyleValues for math-depth
Previously we implemented an all encompassing `MathDepthStyleValue`
specifically for the `math-depth` property, this was unnecessary since
we can represent `auto-add` and `<integer>` using existing `StyleValue`
classes.

This brings the values created from parsing in line with those set via
`StylePropertyMap` which allows us to simplify computation
2026-01-15 12:03:16 +00:00
Tim Ledbetter
40d217bde2 LibWeb/CSS: Serialize shorthands with var() to original value 2026-01-15 11:50:45 +00:00
Andreas Kling
5049599594 LibWeb: Use FixedBitmap in StyleComputer to avoid malloc
Replace two uses of heap-allocated Bitmap with stack-allocated
FixedBitmap. The sizes are known at compile time, so there's no need
to hit malloc for these.
2026-01-14 11:46:23 +01:00
Sam Atkins
692760b109 LibWeb/CSS: Update links to css-scoping and css-shadow-parts specs
These have been merged together into a new "CSS Shadow Module" spec. No
behaviour changes.

Corresponds to:
80d140567a
2026-01-13 16:18:11 +01:00
Tim Ledbetter
03f262f03d LibWeb: Normalize rotate3d() axis vector when computing transform matrix 2026-01-13 12:40:55 +01:00
Callum Law
668d3afde0 LibWeb: Properly parse attributes for CSS-connected FontFace
Previously we would just set the attributes to the serialized
descriptors, even if they were the empty string.

We now apply defaults when we have empty descriptors and apply parsing
logic from the various `set_*` methods (only applicable to `font-family`
so far where we now extract the value from either a string or a
custom-ident)

Fixes an issue in some css/css-shapes WPT tests where we weren't
properly matching fonts.
2026-01-13 10:40:00 +00:00
Callum Law
bbfe7c64fe LibWeb: Disconnect font face if descriptor change makes it invalid 2026-01-13 10:40:00 +00:00
Callum Law
9af90f81bf LibWeb: Use correct base-url for CSS-connected FontFace
Previously we would always try to load the font URL relative to the
document's base URL. This commit means that for CSS-connected
`FontFace`s we now try to load relative to the URL of the stylesheet
that contains the associated `CSSFontFaceRule`
2026-01-13 10:40:00 +00:00
Callum Law
3996d9ec82 LibWeb: Support setting FontFace::family with StringStyleValue 2026-01-13 10:40:00 +00:00
Callum Law
06313acac0 LibWeb: Store updated attributes directly within FontFace
The spec states that updates to descriptors in a `@font-face` rule
should be reflected in the connected `FontFace`'s attributes.

Previously this was achieved by directly accessing those descriptors
when calling the attribute getters, but this has a couple of issues:
 a) The changes are only reflected if we use the accessors (i.e.
    `FontFace::family()` rather than `FontFace::m_family`) which isn't
     the case everywhere
 b) The changes aren't persisted after the `FontFace` is disconnected
    from it's `CSSFontFaceRule`

To fix these issues we now reparse and store the `FontFace`'s attributes
whenever the `CSSFontFaceRule`'s descriptors change.
2026-01-13 10:40:00 +00:00
Callum Law
df03c31e13 LibWeb: Don't crash when serializing @font-face without font-family 2026-01-13 10:40:00 +00:00
Callum Law
e114c7341e LibWeb: Support <custom-ident> in FontFaceSet::load()
This exposed a false positive in our test suite which has been fixed and
made more robust
2026-01-13 10:40:00 +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
Callum Law
1c1476f728 LibWeb: Don't compute font-feature-settings until compute-time
Previously we applied the computation logic (i.e. deduplication and
sorting of tags) at parse time
2026-01-13 10:21:26 +00:00
Callum Law
3a515fd3ee LibWeb: Ignore initial keyword when serializing font shorthand
We know that none of the longhands contain CSS-wide keywords since that
is handled as the first step of `ShorthandStyleValue::serialize()`
2026-01-13 10:21:26 +00:00
Callum Law
252e1d86bd LibWeb: Dont serialize font with non-initial reset-only sub-properties 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
Jelle Raaijmakers
aed9f6a395 LibWeb: Move onanimation* IDL attributes to AnimationEvent.idl
Use the newly added `partial interface mixin` support to move the
CSS animation event handler attributes to their proper location as
specified in CSS Animations Level 1.
2026-01-13 10:09:22 +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
Shannon Booth
5ffc70a2e2 LibWeb/CSS: Implement CSSNumericValue numeric IDL functions 2026-01-12 11:51:15 +00:00
Shannon Booth
09f2db7aa9 LibWeb/CSS: Add various CSSMathXXX constructor helpers
The exact same two steps are repeated for all of these in
CSSNumericValue. These steps are complicated enough that it makes
sense to factor them out into some helpers.
2026-01-12 11:51:15 +00:00
Shannon Booth
3cb428e76d LibWeb/CSS: Remove uneeded ExceptionOr use in CSSMath{Invert,Negate} 2026-01-12 11:51:15 +00:00
Tim Ledbetter
1df792ddbd LibWeb: Avoid intermediate string allocations in calc() serialization 2026-01-12 11:35:01 +00:00
Jonathan Gamble
8f1cb4cbb0 LibWeb: Implement resizing for eligible elements and update scrollbars
Add ElementResizeAction to Page (maybe there's a better place). It's
just a mousemove delegate that updates styles on the target element.

Add ChromeMetrics for zoom-invariant chrome like scrollbar thumb
thickness, resize gripper size, paddings, etc. It's not user-stylable
but separates basic concerns in a way that a visually gifted
designer unlike myself can adjust to taste.

These values are pre-divided by zoom factor so that PaintableBox can
continue using device_pixels_per_css_pixel calls as normal.

The adjusted metrics are computed on demand from Page multiple times
per paint cycle, which is not ideal but avoids lifetime management and
atomics. Maybe someone with more surety about the painting flow control
can improve this, but it won't be a huge win. If profiling shows
this slowing paints, then Ladybird is in good shape.

Update PaintableBox to draw the resize gripper and deconflict
the scrollbars. Set apropriate cursors for scrollbars and gripper in
mousemove. We override EventHandler's cursor handling because nothing
should ever come between a man and his resize gripper.

Chrome metrics use the CSSPixels class. This is good because it's
broadly compatible but bad because they're actually different units
when zoom is not 1.0. If that's a problem, we could make a new type
or just use double.
2026-01-12 11:00:14 +00:00
Jonathan Gamble
4579bb5bed LibWeb: Add resize property plumbing 2026-01-12 11:00:14 +00:00
Callum Law
7c544175e5 LibWeb: Cache compute_font_for_style_values
We already cached the result of `font_matching_algorithm` but we can
instead cache the entire function.
2026-01-11 14:10:37 +01:00
Callum Law
99c06675cf LibWeb: Combine cascaded property lookups during computation
Previously we would do two cascaded property lookups per property during
style computation - the first to get the value of the property and the
second to check whether it was marked as important. We now do this as a
single lookup to save some unnecessary work.
2026-01-11 14:10:37 +01:00
Callum Law
df39394a7e LibWeb: Remove font face from document font source when disconnecting
When a CSS-connected FontFace is disconnected from it's associated
`CSSFontFaceRule` it should be removed from the Document's font source
2026-01-10 03:33:03 +00:00
Callum Law
d8f9caf853 LibWeb: Only run handle_src_descriptor_change once
Previously we would run it once within `set_src()` and then again within
`set_property()` which would lead to us creating two new `FontFace`s
instead of just one
2026-01-10 03:33:03 +00:00
Sam Atkins
35bb1e20ee LibWeb/CSS: Don't serialize "in oklab" in color-mix()
This is the default interpolation method, so should be skipped according
to the rule of the shortest serialization.
2026-01-09 19:11:59 +00:00
Sam Atkins
ade44c7ddb LibWeb/CSS: Make color-interpolation-method optional in color-mix() 2026-01-09 19:11:59 +00:00
Tim Ledbetter
89a391198e LibWeb: Avoid intermediate string allocations in typed om serialization 2026-01-09 17:14:20 +00:00
Tim Ledbetter
cac2ad5ec4 LibWeb: Avoid intermediate string allocation in CSSPropertyRule::dump() 2026-01-09 15:20:06 +00:00
Tim Ledbetter
7335b90c40 LibWeb: Prefer serialize() to to_string() when serializing at-rules 2026-01-09 15:20:06 +00:00
Sam Atkins
960558f30a LibWeb: Register and unregister @property rules when added or removed
Previously, we registered `@property` rules during parsing, and treated
them the same as `CSS.registerProperty()` calls. This is not correct
for a couple of reasons: One, the spec wants us to distinguish between
those two sources of registered custom properties, with
`CSS.registerProperty()` calls taking precedence. Two, we never removed
the registered property when its `@property` was removed from the
document.

This commit deals with this by iterating active CSSPropertyRules to find
which ones currently apply, and storing those in a cache. This cache is
invalidated whenever the Document's style is invalidated, which happens
whenever a CSSRule is added or removed from the Document.

The attached test demonstrates this now working as it should.
2026-01-09 10:54:37 +00:00
Sam Atkins
7c773e73e0 LibWeb/CSS: Read @property initial values in computed style
If a custom property is registered, then it may have an initial value
which we should fall back to here.

This is a temporary hack until we cascade our custom properties (see
https://github.com/LadybirdBrowser/ladybird/pull/6608).
2026-01-09 10:54:37 +00:00
Sam Atkins
02149a8032 LibWeb: Store registered custom properties as CustomPropertyRegistration
This brings us closer to the spec.
2026-01-09 10:54:37 +00:00
Shannon Booth
d901e937b6 LibWeb/CSS: Do not give internal stylesheets a location URL
This fixes Acid3 numbered test 72.
2026-01-09 10:54:11 +00:00
Tim Ledbetter
65f6da8d92 LibWeb: Reduce String allocations in serialize_layer lambdas 2026-01-09 10:00:58 +01:00
Tim Ledbetter
1d2e4e4273 LibWeb: Use StringBuilder when serializing basic grid types 2026-01-09 10:00:58 +01:00
Tim Ledbetter
17ee0e3a19 LibWeb: Use StringBuilder when serializing more CSS types 2026-01-09 10:00:58 +01:00
Tim Ledbetter
d28d04f78e LibWeb: Make InterpolationMethod serialization take a StringBuilder 2026-01-09 10:00:58 +01:00
Tim Ledbetter
b4cf7e8060 LibWeb: Avoid String allocations in easing values serialization methods 2026-01-09 10:00:58 +01:00
Tim Ledbetter
0d7f2b8cba LibWeb: Avoid String allocations in BasicShape serialization methods 2026-01-09 10:00:58 +01:00
Tim Ledbetter
a27d269721 LibWeb: Pass StringBuilder around during StyleValue serialization
Previously, some StyleValues created a large number of intermediate
strings during serialization. Passing a StringBUilder into the
serialization function allows us to avoid a large number of these
unnecessary allocations.
2026-01-09 10:00:58 +01:00
Jelle Raaijmakers
ae20ecf857 AK+Everywhere: Add Vector::contains(predicate) and use it
No functional changes.
2026-01-08 15:27:30 +00:00
Callum Law
2ba1141e3c LibWeb: Don't round when absolutizing lengths
Lengths should be rounded at use-time rather than compute-time

Also removes an unnecessary if statement which was always true
2026-01-08 10:51:35 +01:00
Callum Law
09799e794e LibWeb: Update Length::absolutize() to take a ResolutionContext
All callers are passing individual values from a `ResolutionContext`
anyway so we may as well do it in a single place.
2026-01-08 10:51:35 +01:00