Commit graph

1714 commits

Author SHA1 Message Date
Callum Law
12716dccf0 LibWeb: Avoid including ComputedProperties.h in Element.h
This reduces the size of the recompile when ComputedProperties.h is
modified from ~1200 to ~70
2025-10-27 14:50:54 +00:00
Callum Law
76dadd45d6 LibWeb: Favour !important property values over animated values 2025-10-27 09:51:50 +00:00
Callum Law
c8f345356e LibWeb: Maintain property importance into ComputedProperties
Previously we wouldn't propagate this from CascadedProperties to
ComputedProperties
2025-10-27 09:51:50 +00:00
Callum Law
823dd11b67 LibWeb: Add ComputedProperties::set_property_without_modifying_flags
There are a few places in style computation where we want to update the
value of a property without modifying the inherited or important flags.

Previously we would look up these flags and pass them to the normal
`set_property` method but this is unnecessary and was easy to forget to
do.
2025-10-27 09:51:50 +00:00
Callum Law
84762021b8 LibWeb: Support triggering multiple animations per animation property
We also now use the computed (rather than cascaded) values when
triggering animations.
2025-10-27 09:48:25 +00:00
Callum Law
18477b0d84 LibWeb: Promote animation-composition values to enum
This brings us in line with the other `animation-*` enum properties
(`animation-play-state` and `animation-fill-mode`)
2025-10-27 09:48:25 +00:00
Tim Ledbetter
ebd802f6fc LibWeb+LibGfx: Move CSS sRGB color serialization function to LibGfx 2025-10-26 18:55:22 +01:00
Lorenz A
fb258639d1 LibWeb: CSS selector read-write honor is_allowed_to_be_readonly 2025-10-24 19:15:58 +01:00
Tim Ledbetter
5294559f7b LibWeb: Use logical properties in UA stylesheet 2025-10-24 10:11:49 +01:00
Andreas Kling
a056b26e56 LibWeb: Don't create identical StyleValueList if absolutization is no-op
This case is actually incredibly common, and this ends up reducing the
memory footprint on https://gymgrossisten.com/ by 2.07 MiB.
2025-10-24 08:52:53 +02:00
Callum Law
8417d74328 LibWeb: Parse transition property as a coordinating list shorthand
We don't need all this specific logic for parsing the `transition`
property - we also now maintain `none` as such until use time which
gains us a couple extra tests
2025-10-23 10:09:11 +01:00
Callum Law
94c788f2e0 LibWeb: Make animation parsing logic reusable
This is useful for parsing of other coordinating list shorthands
2025-10-23 10:09:11 +01:00
Callum Law
bb7d5747e7 LibWeb: Serialize transition as a coordinating list shorthand 2025-10-23 10:09:11 +01:00
Callum Law
2e6988d681 LibWeb: Make logic for serializing coordinating list shorthand reusable
Previously this was just used for `animation` serialization but can be
used for other properties (e.g. transition, background) as well
2025-10-23 10:09:11 +01:00
Callum Law
fc5cdd69a0 LibWeb: Extract transition coordination logic to reusable method
This will be useful for other coordinating list property groups (e.g.
background and animation)
2025-10-23 10:09:11 +01:00
Callum Law
e78cb71eb3 LibWeb: Dont skip invalid properties when coordinating transition list
Unrecognized property names should still be kept in the list to preserve
matching of indices (e.g. that the Nth property should associate with
the Nth duration)
2025-10-23 10:09:11 +01:00
Callum Law
0b45a68423 LibWeb: Avoid early conversion to CSSPixels when simplifying calculation
Converting to CSSPixels caused us to lose precision and the sign of
signed zeroes.

The values we resolve against in Length::ResolutionContext are still
themselves rounded too early but this is in the right direction.
2025-10-23 09:34:12 +01:00
Callum Law
43b06cbbdd LibWeb: Propagate NaN through CSS sign() function 2025-10-23 09:34:12 +01:00
Callum Law
1977a976da LibWeb: Handle inaccuracies resolving transformation matrix type
Doing trigonometric calculations with floating point numbers can
introduce small inaccuracies. This meant that we would sometimes
incorrectly generate a 3d rather than 2d matrix for the resolved value
of `transform`.

Gains us 3 WPT tests.
2025-10-23 09:34:12 +01:00
Callum Law
2d331b9176 LibWeb: Don't swap atan2 arguments in with_simplified_children 2025-10-23 09:34:12 +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
5b9a36b172 LibWeb: Pass AbstractElement in ComputationContext
Passing the `AbstractElement` rather than the
`TreeCountingFunctionResolutionContext` allows us to only compute the
resolution context when necessary (i.e. when we actually need to resolve
a tree counting function)
2025-10-22 00:01:30 +02:00
Andreas Kling
d17f666a8c LibWeb: Better CSS inheritance for nodes that represent a pseudo-element
When we compute style for elements inside a UA-internal shadow tree that
represent a pseudo-element (e.g ::placeholder), we actually run the
StyleComputer machinery for (host element :: pseudo-element).

While that lets us match the correct selectors, it was incorrectly
applying CSS inheritance, since we'd also then inherit from whatever was
above the host element in the tree.

This patch fixes the issue by introducing an inheritance override in
AbstractElement and then using that to force inheritance from whatever
is actually directly above in the DOM for these elements instead of
jumping all the way up past the host.

This fixes an issue where `text-align: center` on input type=text
elements would render the main text centered but placeholder text was
still left-aligned.
2025-10-21 16:42:00 +02:00
R-Goc
e8a9d23f92 CSS: Use i64 in StepsEasingFunction
Unbreaks Windows build. resolve_integer returns an i64 making creation
of a StepsEasingFunction with its result a narrowing conversion before
this change as a long is 32 bits on Windows.
2025-10-21 14:51:47 +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
Callum Law
e9036c7c75 LibWeb: Support tree counting functions within calc() 2025-10-20 16:12:08 +01:00
Callum Law
55bcdcf824 LibWeb: Set up initial infrastructure for non-math functions in calc
There are some non-math functions (such as tree counting functions)
which we should allow within `calc()`s . This commit implements the
initial infrastructure for this.

We don't yet parse any of these non-math functions in
`parse_a_calculation` so there is no functional change.
2025-10-20 16:12:08 +01:00
Callum Law
831e471444 LibWeb: Support top-level tree counting functions
Adds support for `sibling-index()` and `sibling-count()` when parsing
`<number>` and `<integer>`. This is achieved by a new
`TreeCountingFunctionStyleValue` class which is converted within
`absolutized` to `NumberStyleValue` and `IntegerStyleValue` respectively

There are still a few kinks to work out in order to support these
everywhere, namely:
 - There are some `StyleValue`s which aren't absolutized (i.e. those
   which are stored within another `StyleValue` without an
   `absolutize()` method.
 - We don't have a way to represent this new `StyleValue` within
   `{Number,Integer}OrCalculated`. This would be fixed if we were to
   instead just use the `StyleValue` classes until style computation at
   which time they would be absolutized into their respective
   primitives (double, i64, etc) bypassing the need for *OrCalculated
   entirely.
2025-10-20 16:12:08 +01:00
Callum Law
9cd23e3ae5 LibWeb: Compute and propagate tree-counting function resolution context
Tree counting functions should be resolved at style computation time -
to do this we will need to know the element's sibling count and index.

This commit computes that information and propagates it to the various
`StyleValue::to_computed_value` methods.
2025-10-20 16:12:08 +01:00
Callum Law
fd31fbd84b LibWeb: Add method for whether tree-counting function is allowed
Some contexts (e.g. descriptors, media conditions) don't allow tree
counting functions, this commit adds an easy way to check if the current
value context is one of those.
2025-10-20 16:12:08 +01:00
Callum Law
fbc6a4c96f LibWeb: Allow setting initial value context when creating CSS parser 2025-10-20 16:12:08 +01:00
Callum Law
8284a99f0a LibWeb: Add absolutized method for FontStyleStyleValue 2025-10-20 16:12:08 +01:00
Callum Law
28451b16c9 LibWeb: Absolutize StyleValues before computing font properties
We also avoid prematurely constructing CSSPixels when computing
font-size which gains us a couple of test passes
2025-10-20 16:12:08 +01:00
Callum Law
ca9d107a1a LibWeb: Remove unused variable in white-space property serialization 2025-10-20 16:12:08 +01:00
Sam Atkins
7ba496b798 LibWeb/CSS: Add ValueTypes for <foo-percentage> 2025-10-20 13:55:23 +01:00
Callum Law
26b82986c4 LibWeb: Clean up parse_css_value_for_properties
We no longer rely on parsing easing functions before keywords so this
can be moved down with the other parse_for_type calls.

`parse_for_type` is used for more than just parsing easing functions so
the variable name `maybe_easing_function` was misleading
2025-10-20 11:27:44 +01:00
Callum Law
03be70087d LibWeb: Maintain easing keywords as KeywordStyleValue until use-time
This excludes `step-end` and `step-start` which are expected to be
converted to the equivalent function at parse time.

We are expected to serialize these as the explicit keywords - previously
we would parse as `EasingStyleValue` and serialize equivalent functions
as the keywords. This caused issues as we would incorrectly serialize
even explicit functions as the keyword.

This also allows us to move the magic easing functions to
`EasingFunction` rather than `EasingStyleValue` which is a bit tidier
2025-10-20 11:27:44 +01:00
Callum Law
755a576013 LibWeb: Support relative lengths within easing function calc()s 2025-10-20 11:27:44 +01:00
Callum Law
ad41f053b8 LibWeb: Clamp calculated steps() interval count using normal system
Previously we were doing this ad-hoc later in the process but we now
have the `calc` clamping system which can simplify things.

This reveals some false-positives in that we don't handle relative
lengths within these `calc`s but these are fixed in the next commit
2025-10-20 11:27:44 +01:00
Callum Law
06a57a280d LibWeb: Clamp calculated cubic-bezier() X coords using normal system
Previously we were doing this ad-hoc later in the process but we now
have the `calc` clamping system which can simplify things
2025-10-20 11:27:44 +01:00
Callum Law
ef4f01ea44 LibWeb: Discard Number type when converting to CalculationNode
Before this change we would maintain explicit signs when serializing
e.g. `animation-iteration-count: calc(+1)` would serialize as `calc(+1)`
rather than `calc(1)` as intended
2025-10-20 11:27:44 +01:00
Callum Law
2f83356c0f LibWeb: Support calc within linear() easing function 2025-10-20 11:27:44 +01:00
Callum Law
91925db9ca LibWeb: Don't canonicalize linear easing function points until use time
Canonicalization can require information that is only known after
compute time (i.e. resolved relative lengths within calcs).

This also allows us to get rid of the `had_explicit_input` flag and just
rely on whether Optional has a value
2025-10-20 11:27:44 +01:00
Callum Law
95e26819d9 LibWeb: Separate use time easing functions from EasingStyleValue
In the future there will be different methods of creating these use-time
easing functions (e.g. from `KeywordStyleValue`s)
2025-10-20 11:27:44 +01:00
Callum Law
0e30de82cc LibWeb: Implement <step-position> as an enum
This simplifies parsing and serialization by using the generated
functions
2025-10-20 11:27:44 +01:00
Luke Wilde
eeb5446c1b LibWeb: Avoid including Navigable.h in headers
This greatly reduces how much is recompiled when changing Navigable.h,
from >1000 to 82.
2025-10-20 10:16:55 +01:00
Callum Law
b1801c0bc9 LibWeb: Avoid crash evaluating media query in document lacking window
In some cases a document may lack an associated window - to fix this for
now we just return false but perhaps there are some media queries we
should still attempt to resolve.
2025-10-17 18:24:59 +02:00
Andreas Kling
dfa796a4e4 LibJS+LibWeb: Use GC::Weak instead of AK::WeakPtr for GC-allocated types
This makes some common types like JS::Object smaller (by 8 bytes) and
yields a minor speed improvement on many benchmarks.
2025-10-17 17:22:16 +02:00
Callum Law
1a3635cda5 LibWeb: Parse the shape-margin property 2025-10-17 11:10:05 +01:00
Callum Law
9c7202e3f3 LibWeb: Parse the shape-image-threshold property 2025-10-17 11:10:05 +01:00