Commit graph

963 commits

Author SHA1 Message Date
aplefull
34f0ac15fd LibWeb: Resolve calculated time values in animations and transitions
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
This lets us play animations and transitions when time values are
stored in the form of calculated values, such as `calc(1s + 500ms)`.
2025-07-23 15:21:23 +01:00
Sam Atkins
943cc0e32a LibWeb/CSS: Implement "legacy value aliases" in generated code
This uses a `foo>bar` notation in the `valid-identifiers` field of
Properties.json, to say "replace `foo` with `bar`".

The motivation here is to avoid calling `parse_css_value_for_property()`
inside the per-property switch in `parse_css_value()`. Eventually we'll
need to be able to call that switch from
`parse_css_value_for_properties()` so that shorthands can make use of
any bespoke parsing code to parse their longhands.
2025-07-23 12:50:42 +01:00
Tim Ledbetter
062862f315 LibWeb/CSS: Add -webkit-filter as a legacy alias
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
2025-07-23 09:32:39 +02:00
ayeteadoe
77d9508618 LibWeb/CSS: Fix implicit narrowing cast in interpolate_rotate
The changes introduced in 484a09d6a2
broke the Windows LibWeb build, so this fixes that
2025-07-22 13:21:17 -06:00
Tim Ledbetter
484a09d6a2 LibWeb: Support interpolating rotate values 2025-07-22 11:09:45 +01:00
Tim Ledbetter
cf33dec6d6 LibWeb: Extract SLERP algorithm into its own method
No functional changes.
2025-07-22 11:09:45 +01:00
norbiros
90c0decd95 LibWeb/CSS: Add CSS.registerProperty JS method
This adds an *almost* complete implementation of `CSS.registerProperty`
method enabling further progress on the `@property` feature.
2025-07-22 10:57:54 +01:00
Andreas Kling
038d8ade50 LibWeb: Always parse calc() inside CSS color functions consistently
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Before this change, calc() would resolve to different types depending on
the nearest containing value context. This meant that rgb(calc(), ...)
by itself worked correctly due to fallbacks, but rgb(calc(), ...) inside
e.g a linear-gradient would create a calc() value that resolves to a
length, which subsequently got rejected by the color value parser.

Fixing this makes various little gradients show up on Discord.
2025-07-22 08:47:22 +01:00
Tim Ledbetter
854d48f973 LibWeb: Use correct angle type when serializing hue-rotate filter values
At some point `hue-rotate` was changed to use `AngleOrCalculated`
rather than `Angle`, but `Angle` was still being used in a `visit`,
which otherwise defaulted to zero. This caused all `hue-rotate` angles
to serialize to zero.
2025-07-22 00:53:10 +02:00
Andreas Kling
e749be2295 LibWeb: Only cascade relevant CSS properties for logical alias context
We only need the cascaded values for writing-mode and direction when
resolving the logical alias context, so we can skip all other
properties.
2025-07-21 20:37:17 +01:00
Luke Wilde
8210a7b3e3 LibWeb: Resolve FontFaceSet::load promise with all loaded FontFaces
Some checks failed
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Build Dev Container Image / build (push) Has been cancelled
The resulting array is required on https://www.canva.com/
2025-07-21 16:29:55 +01:00
dmaivel
52a23dc02e AK+LibWeb/CSS: Add lower-greek counter style 2025-07-21 15:18:17 +01:00
Sam Atkins
938f27bbe3 LibWeb/CSS: Update UA styling for view-transition pseudo-elements
And also indent the file consistently.

Corresponds to 3d13816af7
2025-07-21 15:29:31 +02:00
Aliaksandr Kalenik
4319e6b80e LibWeb: Don't put unlayered rules into into empty "service" layer
Fixes bug when `build_matching_rule_set()` mistakenly included all
unlayered rules twice. This was caused by mistakenly including all
unlayered rules into `""` named "service" layer, because we couldn't
tell if FlyString = `""` means no layer or layer named `""`.
2025-07-21 12:33:35 +01:00
Sam Atkins
11e2dbb555 LibWeb/CSS: Support text-justify: distribute legacy value alias
...for `text-justify: inter-character`.

We previously had this mapped in Enums.json, but the behaviour is
different: `a=b` in Enums.json keeps `a` around but makes it behave the
same as `b`. A legacy name alias is instead expected to replace `a`
with `b`, so we have to do that separately.
2025-07-21 10:04:42 +01:00
Sam Atkins
db75405881 LibWeb/CSS: Support overlay keyword as alias to auto in overflow
We don't yet have a system for "legacy value aliases", but until we have
a lot of them we can handle them manually.

We also have to do this in two places because
parse_css_value_for_property() doesn't call any property-specific
parsing code.
2025-07-21 10:04:42 +01:00
Andreas Kling
128b66e30d LibWeb: Avoid duplicate work when computing style
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Before this change we were running the CSS cascade machinery twice per
element:

- First, to compute the "logical alias mapping context" based on
  writing-mode and pals.

- Then, to compute all properties.

This patch factors out the heaviest work from the cascade machinery
to a separate step that can be run only once. This step will:

- Collect all the matching rules for the element
- Resolve custom properties for the element

We still perform the per-element cascade twice, but now this is hogging
less than 1% of CPU time when typing on Discord (compared to 9% before.)
2025-07-20 17:22:23 -04:00
Gingeh
f38e07e0c5 LibWeb: Don't crash when an unknown property begins with a single dash 2025-07-20 08:54:53 +02:00
Aliaksandr Kalenik
714ff4e3f9 LibWeb: Fix previous style calculation for CSS transitions on pseudo
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
...elements. Adds missing pseudo-element type passed into computed
properties getter.

Previously, due to this bug, we were using the element's computed
properties as the previous computed properties for its pseudo-elements.
This caused an excessive number of unintended CSS transitions to run.
The issue was particularly noticeable in Discord's emoji picker, where
each emoji has `::after` pseudo-element. We were incorrectly triggering
transitions on all their properties, resulting in significant
unnecessary work in style computation and animation event dispatching.
2025-07-18 21:19:37 +02:00
Aliaksandr Kalenik
2fc405f1b2 LibWeb: Allow to pass pseudo-element type in computed properties getter
...and setter. We had lots of places where we check if pseudo-element
type is specified and then use `pseudo_element_computed_properties()` or
`computed_properties()`. This change moves these checks from caller side
to the getter and setter.
2025-07-18 21:19:37 +02:00
Callum Law
4ee8110449 LibWeb: Handle flood-opacity in line with other opacity properties
We now do the proper thing in terms of:
 - Allowing percentages
 - Returning the computed value in getComputedStyle
 - Handling values out of the [0,1] range

Gains us 13 WPT passes in the imported tests.
2025-07-18 11:04:55 -04:00
Jelle Raaijmakers
8dd259b8d8 LibWeb: Stub CSSCounterStyleRule
Just the interface. Adds 6 new WPT subtest passes.
2025-07-18 11:51:41 +01:00
norbiros
7ad01d28a8 LibWeb/CSS: Add basic registered properties with initial values
Add global registry for registered properties and partial support
for `@property` rule. Enables registering properties with initial
values. Also adds basic retrieval via `var()`.

Note: This is not a complete `@property` implementation.
2025-07-18 11:12:39 +01:00
Sam Atkins
0ff61e5e7b LibWeb/CSS: Implement path() basic shape 2025-07-17 13:59:23 -04:00
Callum Law
3d7c5115d8 LibWeb: Move Transformation::to_matrix to new CSV resolve methods
This gains us 2 WPT passes as we now correctly disallow relative lengths
in more places in the `DOMMatrix` constructor.
2025-07-17 08:31:52 +02:00
Sam Atkins
27a666f3b2 LibWeb/CSS: Implement type(<syntax>) in attr()
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Build Dev Container Image / build (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
This lets the `attr()` interpret the attribute's contents as an
arbitrary type instead of just as a string or number.
2025-07-16 14:47:45 +01:00
Sam Atkins
0a5e8c2865 LibWeb/CSS: Implement "parse with a <syntax>"
Uses the SyntaxNode tree to parse a list of ComponentValues into some
kind of StyleValue.
2025-07-16 14:47:45 +01:00
Sam Atkins
ded2207762 LibWeb/CSS: Parse the CSS <syntax> type into a tree
`<syntax>` is a limited subset of the "value definition syntax" used in
CSS specs. It's used for `@property`'s `syntax` descriptor, and for the
`type()` function in `attr()`.
2025-07-16 14:47:45 +01:00
Sam Atkins
72a7a18502 LibWeb/CSS: Use parse_value() to shrink parse_css_value_for_properties() 2025-07-16 14:47:45 +01:00
Sam Atkins
c7d4c4fbff LibWeb/CSS: Add a method to parse a value based on a ValueType 2025-07-16 14:47:45 +01:00
Sam Atkins
08bf9d39de LibWeb/CSS: Add String->ValueType conversion function
And also move this out of PropertyID.h because it's a separate thing.

I considered generating this but there's really not much to it.
2025-07-16 14:47:45 +01:00
Sam Atkins
7e2fa2650d LibWeb/CSS: Sort the entries in Enums.json
I semi-unintentionally add a checker for this in the next commit.
2025-07-16 14:47:45 +01:00
Sam Atkins
d18b0c07ca LibWeb/CSS: Make UnresolvedStyleValue figure out if it contains ASFs
UnresolvedStyleValue::create() has one user where we know if there are
any arbitrary substitution functions in the list of CVs, and two users
where we don't know and just hope there aren't any. I'm about to add
another user that also doesn't know, and so it seems worth just making
UnresolvedStyleValue::create() do that work instead.

We keep the parameter, now Optional<>, so that we save some redundant
work in that one place where we do already know.
2025-07-16 14:47:45 +01:00
Sam Atkins
5aba457009 LibWeb/CSS: Add tokenize() method to style values, to get a list of CVs
A couple of arbitrary substitution functions require us to get or
produce some style value, and then substitute its ComponentValues into
the original ComponentValue list. So this commit gives CSSStyleValue a
tokenize() method that does so.

Apart from a couple of unusual cases like the guaranteed-invalid value,
style values can all be converted into ComponentValues by serializing
them as a string, and then parsing that as a list of component values.
That feels unnecessarily inefficient in most cases though, so I've
implemented faster overrides for a lot of the basic style value
classes, but left that serialize-and-reparse method as the fallback.
2025-07-16 14:47:45 +01:00
Callum Law
33cf3d7782 LibWeb: Serialize RGB, HWB and HSL colors with unresolved components
Gains us 44 WPT passes.
2025-07-16 13:05:33 +01:00
Callum Law
6a9c8d7767 LibWeb: Don't resolve colors with unresolved components
`CSSColorValue`s which have unresolved `calc` components should be able
to be resolved. Previously we would always resolve them but with
incorrect values.

This is useful as we will now be able to now whether we should serialize
colors in their normalized form or not.

Slight regression in that we now serialize (RGB, HSL and HWB) colors
with components that rely on compute-time information as an empty
string, but that will be fixed in the next commit.
2025-07-16 13:05:33 +01:00
Callum Law
e66332c07a LibWeb: Add new CalculatedStyleValue::resolve_* methods
These new methods are built on top of the spec's
`simplify_a_calculation_tree` algorithm where the old methods were
ad-hoc.

These methods are not used anywhere yet as callers will need to be
migrated over from the deprecated methods one-by-one to account for
differences in behaviour.

No functionality changes.
2025-07-16 13:05:33 +01:00
Callum Law
afa95c2815 LibWeb: Mark CalculatedStyleValue::resolve_* methods as deprecated
The existing resolve methods are not to spec and we are working to
replace them with new ones based on the `simplify_a_calculation_tree`
method.

These are marked as deprecated rather than replaced outright as work
will need to be done on the caller side to be made compatible with the
new methods, for instance the new methods can fail to resolve (e.g.
if we are missing required context), where the existing methods will
always resolve (albeit sometimes with an incorrect value).

No functionality changes.
2025-07-16 13:05:33 +01:00
Callum Law
1d3e539c09 LibWeb: Account for logical property groups in set_a_declaration
When setting a declaration for a property in a logical property group,
it should appear after all other declarations which belong to the same
property group but have different mapping logic (are/aren't a logical
alias).

Gains us 1 WPT pass.
2025-07-16 11:16:49 +01:00
Callum Law
47ddc2ea87 LibWeb: Respect logical property groups when serializing shorthands
We should not serialize a group of properties `longhands` as a single
shorthand if there is any property declared between the first and
last property in `longhands` which is not part of `longhands` but
belongs to the same logical property group, and has different mapping
logic to any of property in `longhands`
2025-07-16 11:16:49 +01:00
Callum Law
a1c9b86ad3 LibWeb: Account for non-shorthand sub-properties when serializing border
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
When parsing values in `process_a_keyframes_argument` we don't expand
properties using `StyleComputer::for_each_property_expanding_shorthands`
unlike most other places - this means that if we parse a `border` we end
up with the `border`'s sub-properties (`border-width`, `border-style`,
`border-color`) still in their unexpanded forms (`CSSKeywordValue`,
`LengthStyleValue`, `StyleValueList`, etc) rather than
`ShorthandStyleValue`s which causes a crash when serializing the
`border` value in `KeyframeEffect::get_keyframes`.

The proper fix here is to parse `border`'s sub-properties directly to
`ShorthandStyleValue`s instead of relying on
`StyleComputer::for_each_property_expanding_shorthand` to do this
conversion for us but this may be a while off.

This commit also imports the previously crashing tests.
2025-07-16 06:49:38 +01:00
Sam Atkins
632ce9523b LibWeb/CSS: Add :unchecked pseudo-class
This just got added to the Selectors spec:

b78c97c19d

It's thus missing from the HTML spec and WPT, but I figured it was
simple enough to add.
2025-07-15 21:27:44 +02:00
Sam Atkins
b973c8d275 LibWeb/CSS: Remove the :target-within pseudo-class
This has been removed from the spec:

03b340c34f
2025-07-15 21:27:44 +02:00
Callum Law
93f957051a LibWeb: Handle serialization of invalid border in all contexts
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / 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
Previously as we handled this in `get_property_internal` there were some
contexts that we missed, for instance `CSSStyleProperties::serialized`.
2025-07-15 14:26:02 +01:00
Callum Law
927cd969b2 LibWeb: Generically serialize "positional-value-list-shorthand"s
We were previously handling this ad-hoc via logic in
`get_property_internal` but this didn't cover all contexts (for
instance `CSSStyleProperties::serialized`.

Gains us 9 more WPT tests as we now cover properties which weren't
included in the previous ad-hoc approach.
2025-07-15 14:26:02 +01:00
Callum Law
9ed85ddd63 LibWeb: Mark relevant properties as "positional-value-list-shorthands"
Some shorthand properties work differently to normal in that mapping of
provided values to longhands isn't necessarily 1-to-1 and depends on the
number of values provided, for example `margin`, `border-width`, `gap`,
etc.

These properties have distinct behaviors in how they are parsed and
serialized, having them marked allows us to implement theses behaviors
in a generic way.

No functionality changes.
2025-07-15 14:26:02 +01:00
Callum Law
48153ecf45 LibWeb: Remove duplicate logic for white-space special keywords
This is already handled in `ShorthandStyleValue::to_string`.

No functionality change.
2025-07-15 14:26:02 +01:00
Callum Law
09a5c04e5c LibWeb: Handle serialization of invalid font-variant in all contexts
Previously as we handled this in `get_property_internal` there were some
contexts that we missed, for instance `CSSStyleProperties::serialized`.
2025-07-15 14:26:02 +01:00
Shannon Booth
9054ff29f0 LibWeb/CSS: Parse the ::slotted pseudo-element 2025-07-15 13:54:17 +01:00
Shannon Booth
0151a088ad LibWeb/CSS: Fix missing ':' in debug logging for pt-name-selector 2025-07-15 13:54:17 +01:00