Commit graph

422 commits

Author SHA1 Message Date
Sam Atkins
35fd3bda79 LibWeb/CSS: Promote <transform-list/function> to parsable types
The `transform` property is now parsed based on its JSON data, and
shouldn't behave any differently than before.

This makes `<transform-list>` and `<transform-function>` work in the
`syntax` descriptor for `@property`, and also means we know that
`transform` can accept the `none` keyword. We get a few WPT passes out
of that.
2025-10-14 13:41:47 +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
Sam Atkins
882bdbb019 LibWeb/CSS: Stop asserting that UnresolvedSV contains an ASF
Typed-OM means that the author can set a property's value to a
CSSUnparsedValue, which may or may not have any arbitrary substitution
functions in it. This VERIFY was just there to catch parsing bugs that
created UnresolvedStyleValues unnecessarily, and removing it is
harmless.
2025-10-09 16:14:58 +02:00
Callum Law
814efa9809 LibWeb: Parse corner-*-shape physical longhands 2025-10-09 10:23:20 +01:00
Tim Ledbetter
03fa367d9d LibWeb: Parse the anchor-scope property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
85a15ea1d4 LibWeb: Parse the position-visibility value 2025-10-07 11:30:23 +01:00
Tim Ledbetter
2bde14b148 LibWeb: Parse the position-try-fallbacks property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
27cdf3a2c8 LibWeb: Parse the position-anchor property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
7374a07fbc LibWeb: Parse the anchor-name property 2025-10-07 11:30:23 +01:00
Callum Law
e772a992be LibWeb: Store CursorStyleValue sub-values directly
Storing these within NumberOrCalculated is unnecessary
2025-10-07 10:50:01 +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
f2a302663c LibWeb: Simplify value parsing code
We know that `parse_calculated_value` returns a
`RefPtr<CalculatedStyleValue const>` so we can avoid various checks on
the StyleValue type.
2025-10-07 10:50:01 +01:00
Callum Law
05c336ea4e LibWeb: Use document's viewport when resolving lengths in media queries
Previously we would always use the window's viewport which was incorrect
if we were within an iframe.

This is likely applicable to all uses of
`Length::ResolutionContext::for_window`.
2025-10-07 10:32:59 +01:00
Tim Ledbetter
51ea4a7e2a LibWeb: Align position-area values with the specification
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 change renames the following `position-area` values:

x-self-start -> self-x-start
x-self-end -> self-x-end
y-self-start -> self-y-start
y-self-end -> self-y-end
span-x-self-start -> span-self-x-start
span-x-self-end -> span-self-x-end
span-y-self-start -> span-self-y-start
span-y-self-end -> span-self-y-end
2025-10-05 15:48:21 +01:00
Sam Atkins
561fdc0228 LibWeb/CSS: Use PropertyNameAndID in Parser::convert_to_style_property() 2025-10-02 13:46:04 +01:00
Sam Atkins
c0ef7f09e4 LibWeb/CSS: Use PropertyNameAndID instead of old Variant 2025-10-02 13:46:04 +01:00
Sam Atkins
89c89470ef LibWeb/CSS: Stop rejecting declarations with vendor-prefixed keywords
property_accepts_type() only looks at the property itself, not any
longhands it might have, so we thought that `font` didn't accept
`<custom-ident>`s, and seeing "-apple-..." makes us throw out the
declaration even though it's valid as a font name.

We'll reject these like any other unrecognized value if it's somewhere
that's not supported, so this was really just an optimization for a
rare edge case, and removing the check doesn't have any observable
effect except fixing this bug and any similar cases.

Changing property_accepts_type() to look at longhands is not
straightforward, as not all longhand values are valid in the shorthand.
2025-10-02 13:26:26 +02:00
Sam Atkins
3916e33276 LibWeb/CSS: Parse the container-type property
This applies size, inline-size, and style containment in some cases.
There are other WPT tests for that, but we seem to not implement enough
of containment for this to have an effect so I've not imported those.

Gets us 35 WPT subtests.
2025-09-30 22:05:45 +01:00
Sam Atkins
56c7d838f0 LibWeb/CSS: Stop using PropertyID::Invalid in border parsing 2025-09-30 15:21:09 +02:00
Sam Atkins
7d4b2d10e4 LibWeb/CSS: Remove default value for parse_css_value() PropertyID
Every user provides this, and it's not clear what passing
PropertyID::Invalid here actually means.
2025-09-30 15:21:09 +02:00
Tim Ledbetter
eb571a1a46 LibWeb: Parse the position-area property 2025-09-29 09:53:27 +02:00
Tim Ledbetter
83ad5ce8a2 LibWeb: Don't deduplicate font-variation-settings values at parse time
We now only deduplicate and sort the computed value of the
`font-variation-settings` property.
2025-09-26 11:20:54 +01:00
Sam Atkins
995b7eb7b4 LibWeb/CSS: Replace resolve_percentage_deprecated() with undeprecated 2025-09-24 16:33:53 +01:00
Sam Atkins
0dba531772 LibWeb/CSS: Replace resolve_number_deprecated() with resolve_number() 2025-09-24 16:33:53 +01:00
Callum Law
869442c206 LibWeb: Parse animation shorthand as comma separated list
We now parse (but don't yet trigger animations for) multiple definitions
within a single animation property.
2025-09-24 11:58:20 +01:00
Callum Law
030e6d7c9b LibWeb: Parse animation-* properties as comma separated lists
We are yet to actually support having more than one value but this gets
us closer and gains us some WPT tests in the process.
2025-09-24 11:58:20 +01:00
Tim Ledbetter
0aec8912c9 LibWeb: Remove special casing for font oblique angle from CSS parser 2025-09-24 11:40:38 +01:00
Tim Ledbetter
27de4fdcea LibWeb: Clamp interpolated font-style angle
This change adds the allowed angle range to the `font-style` property
definition. This allows these angles to be clamped after interpolation.

Ideally, the generator should be updated so that we can specify the
angle is in degrees. This would allow us to make use of this
information during parsing, which we can't do currently because we
don't know what the unit is. Using this value for interpolation
purposes is fine because the angle has been converted to its canonical
unit by this point.
2025-09-24 11:40:38 +01:00
Callum Law
e17d91780d LibWeb: Clamp computed value for font-style oblique angle
Values outside [-90deg,90deg] are invalid and should be clamped
2025-09-19 10:06:33 +01:00
Callum Law
004bd3dc8f LibWeb: Clamp calc()'d shadow blur radius to positive values
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-09-18 15:21:22 +01:00
Callum Law
19e3ddc0c6 LibWeb: Simplify parse_single_shadow_value
The `possibly_dynamic_length` function was unnecessary and can be
replaced with the standard `parse_length_value`
2025-09-18 15:21:22 +01:00
Callum Law
c3a78d2884 LibWeb: Don't include spread distance when serializing text-shadow
We shouldn't include spread distance when serializing `text-shadow` as
it is not supported unlike `box-shadow` - to achieve this we store
whether this is a text or box shadow within the ShadowStyleValue and
serialize appropriately.
2025-09-18 15:21:22 +01:00
Callum Law
1ac7b47764 LibWeb: Disallow spread distance value when parsing text-shadow
`text-shadow` does not support setting a value for spread distance
unlike `box-shadow`.
2025-09-18 15:21:22 +01:00
Sam Atkins
95aceb6ec9 LibWeb: Store custom properties in an OrderedHashMap
We are expected to preserve their order within a style declaration, so
let's do that. Passes 1 tracked WPT subtest.
2025-09-18 14:59:14 +02:00
Callum Law
b0e3af7d10 LibWeb: Parse text-underline-position property
This introduces the `TextUnderlinePositionStyleValue` class, it is
possible to represent `text-underline-position` as a `StyleValueList`
but would have required ugly workarounds for either serialization or in
`ComputedProperties::text_underline_position`
2025-09-15 15:24:20 +01:00
Callum Law
a6812e1005 LibWeb: Store parsed shorthands in canonical order 2025-09-15 15:24:20 +01:00
Callum Law
50239b58aa LibWeb: Reset border-image to initial value when using border
Also includes associated handling for serialization of the `border`
shorthand.
2025-09-15 08:42:22 +01:00
Sam Atkins
83aee2c7fc LibWeb: Take AbstractElement in resolve_unresolved_style_value() 2025-09-11 18:45:35 +02:00
Sam Atkins
b3c099bd68 LibWeb/CSS: Use dimension_for_unit() when we don't need the exact unit
A small code reduction, and means that NumericType will catch if new
dimensions are added, and attr() will just work in that case.
2025-09-11 17:06:44 +01:00
Sam Atkins
b3e32445d3 LibWeb/CSS: Use generated FooUnit types instead of Foo::Type
I've also renamed the `m_type` and `type()` members to be `m_unit` and
`unit()` instead, to match what they actually are.
2025-09-11 17:06:44 +01:00
Pratyush Nair
01be928a16 LibWeb: Avoid dereferencing a null pointer to document 2025-09-10 16:57:36 +01:00
Callum Law
a7e5ded188 LibWeb: Add generic logic for parsing "positional-value-list-shorthands"
Continues the work started in #5386 to simplify handling of positional
value list shorthand properties.

Previously we would parse these as `StyleValueList`s and then rely on
`StyleComputer::for_each_property_expanding_shorthands` to expand them
into longhands.

This required a bit of work to handle `ShorthandStyleValue`s for the
`@page` `margin` descriptor.
2025-09-09 11:45:47 +02:00
Callum Law
b1e77b3522 LibWeb: Parse longhands of border as ShorthandStyleValues
Previously we would instead parse these as single values and rely on
ad-hoc functionality in `for_each_property_expanding_shorthands` to
expand them to longhands.

This gets us a step closer to removing that ad-hoc functionality.
2025-09-09 11:45:47 +02:00
Callum Law
246a1c41ff LibWeb: Don't resolve calc'd opacity percentages at parse time
This behaviour should only apply to literal percentages as clarified
here: 4ee8429

We were also doing this wrong by converting the numeric type of the calc
to Length which was causing values to be defaulted to 1 instead (hence
the new passing tests for computed values as well)
2025-09-08 11:03:32 +01:00
Psychpsyo
9ea8b5a0a3 LibWeb: Add CSS column-height property
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-09-07 15:59:39 +01:00
Aliaksandr Kalenik
308c2eab0e LibWeb: Throw parsing error if ::slotted() argument is not 1 compound
...selector. Grammar per spec: `::slotted( <compound-selector> )`, so
we should reject selector as invalid if first compound selector is
followed by something else.

This change makes layout more correct on https://www.rottentomatoes.com/
2025-09-04 13:55:20 +01:00
Sam Atkins
930ee495e7 LibWeb/CSS: Remove the "Auto" type from Length
This has always been a bit of a hack. Initially it made sense as a lot
of properties that accept a length also accept `auto`, but while
convenient, that leads to problems: It's easy to forget to check if a
length is `auto`, and places that don't accept it end up with an
invalid state lurking in the type system, which makes things unclear.
2025-09-04 13:31:24 +01:00
Sam Atkins
dd122e2f74 LibWeb: Make LengthBox hold LengthPercentageOrAuto
Not every user of this requires an `auto` state, but most do.

This has quite a big diff but most of that is mechanical:
LengthPercentageOrAuto has `resolved_or_auto()` instead of `resolved()`,
and `to_px_or_zero()` instead of `to_px()`, to make their output
clearer.
2025-09-04 13:31:24 +01:00
Sam Atkins
04622f3940 LibWeb/CSS: Use LengthPercentageOrAuto for background sizes
...instead of `auto` Lengths.

This also fixes interpolating between two `auto` `<bg-size>`s, which
fixes a lot of animation tests for both `background-size` and `mask`.
2025-09-04 13:31:24 +01:00