Commit graph

1714 commits

Author SHA1 Message Date
Callum Law
dca80ad5eb LibWeb: Account for animated values when computing font
Computing the font for an element in `compute_font` is premature since
we are yet to apply animated properties - instead we should compute the
value on the fly (with a cache to avoid unnecessary work) to ensure we
are respecting the latest values
2025-12-05 10:03:15 +00:00
Callum Law
6c236d04d8 LibWeb: Separate font computation logic from StyleComputer
Font computation and loading is distinct enough from style computation
that it makes more sense to have this in it's own class.

This will be useful later when we move the font loading process to
`ComputedProperties` in order to respect animated values.
2025-12-05 10:03:15 +00:00
Callum Law
dfa47d9ed6 LibWeb: Simplify handling of font-variation-settings
Since we resolve any relative lengths at compute time there's no need
for the value to be passed around as a `NumberOrCalculated` and we can
just resolve it within `ComputedProperties::font_variation_settings`.

The only place this is used it is used with value_or so there's no need
to return it is an `Optional`.

This is only used for loading fonts (which occurs during style
computation) so there's no need to store it in `ComputedValues`
2025-12-05 10:03:15 +00:00
Sam Atkins
315ffb91af LibWeb/CSS: Dump more information about CSSImportRules
Specifically, we now dump the conditions, and the imported style sheet -
these sheets were previously skipped entirely when dumping everything
out.
2025-12-04 16:24:04 +00:00
Sam Atkins
5343c9bd2e LibWeb/CSS: Dump out media queries in more detail
Instead of just serializing them, dump out the query condition as a
tree, taking advantage of the existing dump code for
BooleanExpressions.
2025-12-04 16:24:04 +00:00
Sam Atkins
1db13c52be LibWeb/CSS: Make Supports responsible for dumping itself entirely
This will reduce the boilerplate for other things that want to dump a
Supports, such as `@import`.
2025-12-04 16:24:04 +00:00
Sam Atkins
180cd4b799 LibWeb: Move CSSRule dumping code into CSSRule classes
Having the dumping code in a separate Dump.cpp meant that it was often
overlooked when the rules gained new features, and also limits dumping
to publicly-accessible information.
2025-12-04 16:24:04 +00:00
Sam Atkins
6b46bed970 LibWeb/CSS: Update syntax comments for a couple of properties
Corresponds to:
3a2ac8d75c
fdc08f79a2

No code changes.
2025-12-04 08:37:39 -05:00
Sam Atkins
d717dd64b3 LibWeb: Make Animation's owning element an AbstractElement
From the spec:
> The owning element of a transition refers to the element or
  pseudo-element to which the transition-property property was applied
  that generated the animation.

https://drafts.csswg.org/css-transitions-2/#owning-element

Previously we only stored the element.
2025-12-03 13:29:51 +01:00
Sam Atkins
b61c857c64 LibWeb/CSS: Use AbstractElement animation helpers 2025-12-03 13:29:51 +01:00
Callum Law
e935dfbf5b LibWeb: Simplify compute_style_value_list 2025-12-02 12:47:10 +00:00
Callum Law
38efc39e17 LibWeb: Simplify assemble_coordinated_value_list
We know that all coordinated value list longhands are parsed as
`StyleValueList`s
2025-12-02 12:47:10 +00:00
Callum Law
74e6c5074f LibWeb: Store list-valued properties as lists in StylePropertyMap::set()
This matches the behavior of parsed values
2025-12-02 12:47:10 +00:00
Callum Law
953f9775a4 LibWeb: Mark animation-* properties as list-valued 2025-12-02 12:47:10 +00:00
Callum Law
758432c1cd LibWeb: Don't mark mask-type as list-valued
This is distinct from the other `mask-*` properties and is not a
longhand of `mask`, and is thus not a coordinating value list longhand
2025-12-02 12:14:27 +00:00
Callum Law
4034ce995a LibWeb: Account for transition-{delay,duration} always being a list
This fixes the optimization implemented in 46acdbd that was no longer
working after e937f5d
2025-12-02 11:45:46 +00:00
Callum Law
d7d4f90a2c LibWeb: Update style attribute when calling attributeStyleMap.set()
We also now invalidate the element
2025-12-02 11:37:11 +00:00
Sam Atkins
b376ab4e81 LibWeb/CSS: Serialize Supports::Declaration as original representation
Fixes some WPT tests that expected `supports(foo:bar)` to serialize as
`supports(foo:bar)`, instead of `supports(foo: bar)` with a space
between.

Reading the original_full_text directly also lets us delete
Declaration::to_string(), which was only used here.
2025-12-02 09:49:23 +00:00
Sam Atkins
db910c68a3 LibWeb/CSS: Add option to retain a Declaration's full source text
This will be needed by Supports, which expects declarations to serialize
verbatim.
2025-12-02 09:49:23 +00:00
Sam Atkins
a8d0be4382 LibWeb/CSS: Expose consumed tokens from TokenStream
In some situations we want to examine a sequence of tokens that have
been already consumed from a TokenStream. These methods let us do so:
- current_index() provides the current internal token index
- tokens_since() provides a span from the given index to the current one
2025-12-02 09:49:23 +00:00
Sam Atkins
8d5eac28a4 LibWeb/CSS: Rename Declaration.original_text -> original_value_text
Otherwise this will conflict with a different original text that I'm
about to add.
2025-12-02 09:49:23 +00:00
Sam Atkins
faba11f33c LibWeb/CSS: Pull out Supports::Declaration parsing
Avoid repeating this in two places.
2025-12-02 09:49:23 +00:00
Sam Atkins
4ed1c56267 LibWeb/CSS: Parse all supports features in @import supports()
The previous implementation assumed that the contents of `supports()`
was either a raw declaration, or a block containing some number of them.
This meant we wouldn't parse things like `supports(not (a:b))` or
`supports(selector(*))`.

`parse_a_supports()` actually does what we want in every case except for
raw declarations (`supports(a: b)`), so let's always call it first, and
then fall back to parsing a single declaration.
2025-12-02 09:49:23 +00:00
Sam Atkins
d9abfdf2ab LibWeb/CSS: Allow non-StyleValueLists in animation properties
Reverts 51f694c6af and
b52beb5105.

The animation-* properties are in an awkward place currently, where
they *should* be lists, and a lot of our code acts as if they are, but
actually we parse them as single values. The above commits caused a few
WPT tests to crash - see link below. I've imported one of them to
prevent future regressions.
https://wpt.fyi/results/css/css-typed-om/the-stylepropertymap/properties?diff&filter=ADC&run_id=6293362870321152&run_id=5123272984494080
2025-12-02 09:48:32 +00:00
Sam Atkins
cdc81e8921 LibWeb/CSS: Add -moz-appearance property alias 2025-12-01 11:10:13 +00:00
Sam Atkins
d5d1b5351e LibWeb: Hide stepper buttons on appearance: textfield number inputs
The spec says:

> For the purpose of this specification, they all have the same effect
  as auto. However, the host language may also take these values into
  account when defining the native appearance of the element.

https://drafts.csswg.org/css-ui/#typedef-appearance-compat-special

Firefox at least hides the stepper buttons when this is set.
2025-12-01 11:10:13 +00:00
Sam Atkins
f81bb1bd8c LibWeb/CSS: Absolutize GradientStyleValues
This lets us not care about non-absolute Length units when resolving
gradient data, as they'll already have been converted to px.

We can also use Angle::from_style_value() safely on absolutized angles,
which reduces some boilerplate code.
2025-12-01 11:01:06 +00:00
Sam Atkins
fbe0567f90 LibWeb/CSS: Store RadialGradientStyleValue sizes as StyleValues
No significant consequences of this, but it'll make it easier to
absolutize these values.
2025-12-01 11:01:06 +00:00
Sam Atkins
d327f677c5 LibWeb/CSS: Store linear-gradient() angle as a StyleValue
This means we now support calc() there too.
2025-12-01 11:01:06 +00:00
Sam Atkins
73fbaaba77 LibWeb: Store GradientStyleValue color-stop positions as StyleValues
A few things fall out of this:
- We no longer need to templatize our color-stop list types.
- A bit more code is required to resolve gradient data.

This results in a slightly different rendering for a couple of the test
gradients, with a larger difference between macOS and Linux. I've
expanded the fuzziness factor to cover for it.
2025-12-01 11:01:06 +00:00
Callum Law
12e8f503aa LibWeb: Support non-fixed <random-value-sharing>
This works by generating random values using XorShift128PlusRNG at
compute time and then caching them on the document using the relevant
random-caching-key
2025-12-01 11:00:33 +00:00
Callum Law
86e6aa0291 LibWeb: Keep track of random function index within property value
Caching keys for 'auto' <random-value-sharing> rely on this value to
distinguish between two random functions in a single property
2025-12-01 11:00:33 +00:00
Callum Law
bad9efac22 LibWeb: Support CSS random() function step argument 2025-12-01 11:00:33 +00:00
Callum Law
2a5e389f63 LibWeb: Implement basic CSS random() function
At the moment this is limited to only fixed value sharing and does not
support step values
2025-12-01 11:00:33 +00:00
Callum Law
8944130fde LibWeb: Serialize CSS::Number to spec
We were previously serializing with 5 instead of 6 digits of precision
2025-12-01 11:00:33 +00:00
Callum Law
76108b1979 LibWeb: Update math function argument parsing to use TokenStream
This brings us in line with the rest of the parsing methods
2025-12-01 11:00:33 +00:00
Callum Law
cd0976395a LibWeb: Remove unused class in CSS parser 2025-12-01 11:00:33 +00:00
Callum Law
2477a8eb0d LibWeb: Use property_initial_value rather than hardcoded default value 2025-12-01 10:16:41 +00:00
Callum Law
d6371fe896 LibWeb: Simplify parse_coordinating_value_list_shorthand 2025-12-01 10:16:41 +00:00
Callum Law
51f694c6af LibWeb: Simplify compute_style_value_list 2025-12-01 10:16:41 +00:00
Callum Law
3ab0bdf4fd LibWeb: Simplify handling of unicode-range descriptor
We know that this is always a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
47bed173b4 LibWeb: Simplify ComputedProperties::will_change()
We know that `will-change` parses as either `Keyword::Auto` or
`StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
b52beb5105 LibWeb: Simplify assemble_coordinated_value_list
We know that all coordinated value list longhands are parsed as
`StyleValueList`s
2025-12-01 10:16:41 +00:00
Callum Law
e8ba1b4fdf LibWeb: Simplify serialization of coordinating value list shorthands
We know that longhand values are always `StyleValueList`s

Introduces a new fail in the `view-timeline-shorthand.html` WPT test
but this is because the test is incorrect and we now correctly don't
contract when `view-timeline-inset` has dissimilar cardinality. See
web-platform-tests/wpt#56181
2025-12-01 10:16:41 +00:00
Callum Law
11a9b5a67b LibWeb: Simplify handling of font-family
We know `parse_comma_separated_value_list` always returns a
`StyleValueList`
2025-12-01 10:16:41 +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
4c4fa5c9cd LibWeb: Simplify expansion of background-position shorthand
We know that this is always a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
40596d5b99 LibWeb: Simplify getting resolved value for animation-duration
We now know that `animation_duration_computed_value` is always a
StyleValueList
2025-12-01 10:16:41 +00:00
Callum Law
e937f5db57 LibWeb: Always parse comma separated value lists as StyleValueList
Previously we would either parse these as `StyleValueList<T>` or `T`
depending on whether or not there was more than one value, this meant we
always had to handle both cases anywhere we used these values.
2025-12-01 10:16:41 +00:00
Callum Law
1af0364cfc LibWeb: Store last_css_animation_play_state on anim instead of effect
Since it is the animation rather than the effect which has a play state
it makes more sense to store it here
2025-12-01 10:16:41 +00:00