Commit graph

407 commits

Author SHA1 Message Date
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
Sam Atkins
d10eaa996e LibWeb/CSS: Use empty optional for stretch in FitContentSV
...instead of using an `auto` Length.
2025-09-04 13:31:24 +01:00
Sam Atkins
240536acaa LibWeb: Remove auto length from SourceSet
The spec is a bit awkward here: A few algorithms create an "empty"
SourceSet, and then assign its source-size value a few steps later, so
we have a temporary state with no length. In order to avoid complicating
the types with Optional, I've chosen to just assign it to 0px.
Previously we used `auto`, but `auto` is not a valid value here - it is
used inside the "parse a sizes attribute" algorithm, but that always
returns an actual length (or calc).
2025-09-04 13:31:24 +01:00
Sam Atkins
9b27aaa00c LibWeb/CSS: Use LengthOrAuto for clip rects 2025-09-04 13:31:24 +01:00
Sam Atkins
ae40c7ed95 LibWeb/CSS: Use Size in GridSize
Reduces a bunch of duplicate logic here for holding different sizing
functions, and also removes a user of `auto` Length.
2025-09-04 13:31:24 +01:00
Sam Atkins
277117eed5 LibWeb/CSS: Implement CSSNumericValue.parse()
Reifying the result gets quite ad-hoc. Firstly because "parse a
component value" produces a ComponentValue, not a full StyleValue like
we need for math functions. And second, because not all math functions
can be reified as a CSSNumericValue:

Besides the fact that I haven't implemented CalculatedStyleValue
reification at all yet, there are a lot of math functions with no
corresponding CSSMathValue in the spec yet. If the calculation tree
contains any of those, the best we can do is reify as a CSSStyleValue,
and that isn't a valid return value from CSSNumericValue.parse(). So, I
made us throw a SyntaxError in those cases. This seems to match
Chrome's behaviour. Spec issue:
https://github.com/w3c/css-houdini-drafts/issues/1090
2025-08-29 11:57:10 +02:00
Sam Atkins
f93819eda2 LibWeb/CSS: Remove unused <an+b># code for pseudo-classes
This reverts e7890429aa and partly reverts
a59c15481f.

The one pseudo-class that accepted multiple of these was :heading(), and
since that got changed to take integers instead, there's no need to keep
this extra complexity (and memory usage) around.
2025-08-28 12:40:03 +02:00
Sam Atkins
d461e96f40 LibWeb/CSS: Make :heading() pseudo-class take integers not AN+B
Corresponds to 8eb3787e34
2025-08-28 12:40:03 +02:00
Tim Ledbetter
a87a9156d5 LibWeb/CSS: Parse the paint-order property 2025-08-28 10:31:09 +01:00
ayeteadoe
3df8e00d91 LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Sam Atkins
5bdc2981e3 LibWeb/CSS: Rename CSSNumericType to NumericType
The CSSNumericType defined in the spec is a simple dictionary which is
only used for OM purposes. This NumericType class is used internally
and matches the more abstract definition of a "type".
2025-08-22 09:48:30 +01:00
Tim Ledbetter
4f663ca6e7 LibWeb: Parse the will-change property
This property provides a hint to the rendering engine about properties
that are likely to change in the near future, allowing for early
optimizations to be applied.
2025-08-18 12:36:37 +01:00
Sam Atkins
e7890429aa LibWeb/CSS: Add support for pseudo-classes taking <an+b># 2025-08-13 09:47:28 +01:00
Sam Atkins
a59c15481f LibWeb/CSS: Prepare pseudo-classes for multiple An+B patterns
The upcoming `:heading()` pseudo-class takes multiple comma-separated
An+Bs. Also rename this field as the `:nth-[last-]child()`
pseudo-classes are only a subset of the users.
2025-08-13 09:47:28 +01:00
Callum Law
6025805f19 LibWeb/Meta: Compute the accepted value range for CalculationContexts
This currently only applies to property-level calculation contexts, more
work to be done to generate accepted ranges for other calculation
contexts (e.g. within transformation functions, color functions, etc)
2025-08-11 17:10:04 +01:00
Callum Law
2af7016a77 LibWeb: Rename ValueType::OpenTypeTag to ValueType::OpentypeTag
This is the correct capitalization in line with what it is called in the
spec "opentype-tag".
2025-08-11 17:10:04 +01:00