Commit graph

539 commits

Author SHA1 Message Date
Sam Atkins
2b2e5a1db3 LibWeb/CSS: Support legacy selector aliases for pseudo-classes
These are replaced with the pseudo-class they are an alias of, during
parsing.
2025-12-18 14:50:27 +01:00
Sam Atkins
0241652611 LibWeb/CSS: Parse number as a type in attr()
Dealing with `unit_name` as a separate variable was becoming unwieldy,
so I've also combined that into the `syntax` variant.

Corresponds to:
0e6b4ef33b
2025-12-17 11:53:08 +00:00
Sam Atkins
e1b5a1c803 LibWeb/CSS: Parse attr(foo %) as a <percentage> token
There were two bugs here: `%` is a `<delim>` not an `<ident>`; and we
created a `<dimension>` token when we should create a `<percentage>`.
2025-12-17 11:53:08 +00:00
Sam Atkins
38b02c79ad LibWeb/CSS: Allow a slash in border-radius longhand properties
`border-radius` requires a slash between the x/y components, but the
longhands like `border-top-left-radius` don't allow it. This spec
change allows authors to put a slash there for consistency.

Corresponds to:
e938d7d705
2025-12-15 14:30:20 +00:00
Callum Law
f17f4f233d LibWeb: Don't serialize omitted ellipse() position argument 2025-12-12 12:20:16 +00:00
Callum Law
daf464844b LibWeb: Support all <radial-extent> values in ellipse()
To do this we use the generic `RadialSizeStyleValue` which allows us to
remove the remaining logic around `<shape-radius>`
2025-12-12 12:20:16 +00:00
Callum Law
ad1083f14e LibWeb: Don't serialize omitted circle() position argument
This should only be defaulted to `center` at use time
2025-12-12 12:20:16 +00:00
Callum Law
8501d6995d LibWeb: Support all <radial-extent> values in circle() 2025-12-12 12:20:16 +00:00
Callum Law
4909e19aca LibWeb: Make <radal-size> parsing generic
Previously this was implemented inline within the parsing of
`{repeating}-radial-gradient()` functions but it will also be useful for
`circle()` and `ellipse()`.

We now support the CSS Images Module Level 4 additions to the
`<radial-size>` syntax, namely:
 - `<length-percentage>` rather than just `<length>` for circles.
 - Distinct `<radial-extent>` values for horizontal and vertical for
   ellipses.
 - Mixing of `<radial-extent>` and `<length-percentage>` values for
   ellipses.

The regressions are due to WPT not being updated to expect the first of
these additions.
2025-12-12 12:20:16 +00:00
Timothy Flynn
7114872073 LibWeb: Include "url(" in the original source text of URL tokens
When we invoke Tokenizer::consume_a_url_token, we have already consumed
the "url(" text from the source. Thus we would set the original source
text to the text starting just after those consumed code points. Let's
instead pass in the known starting position from the caller.

This fixes a bug seen on https://lichess.org, where they perform a
`substring(4)` on the property value to remove the "url(" text. This
would strip away the "http" part of the URL, and we would try to load
"s://lichess.org/image.svg". With this fixed, we can play chess games
on this site.
2025-12-10 20:50:02 +01:00
Sam Atkins
bb4f2f49f5 LibWeb/CSS: Reject selectors with multiple pseudo-elements
Our codebase assumes that a selector only contains a single
pseudo-element, and that it's in the final compound selector. If there
are multiple of them, or they're somewhere else in the selector, we
just silently pretend the others aren't there, which is *not* what we
want, and causes the selector to match things it shouldn't.

A proper fix is quite involved, so as a temporary fix, just reject any
selector that doesn't fit our assumptions during parsing. That way we
get false negatives instead of false positives.
2025-12-09 15:48:57 +00:00
Callum Law
6466001367 LibWeb: Store BasicShapeStyleValue sub-values directly
Storing these within `LengthPercentage`, `LengthBox`, and `Variant`
over-complicated things.

We also now use the correct `SerializationMode` when serializing `xywh`
and `rect`
2025-12-09 11:23:59 +00:00
Sam Atkins
fbcaa8edde LibWeb/CSS: Make CSSImportRule.media return its own MediaList
...instead of returning the one from its associated style sheet.

This reverts 848a250b29 where I made
`CSSImportRule.media` nullable.

CSSImportRule may not have an associated style sheet, because of not
matching a supports condition, or just failing to load the URL.
Regardless of whether we do or not, the expected (non-spec) behaviour
is that we should return a MediaList always, which matches the media
queries specified on the `@import` rule.
2025-12-08 13:30:53 +00:00
Sam Atkins
eb679e5726 LibWeb/CSS: Parse layer in @import rules 2025-12-08 13:30:53 +00:00
Callum Law
13291a9180 LibWeb: Treat background-* and mask-* as lists for initial values
This is required after e937f5d - it went unnoticed until now since the
serialization is the same and the relevant code just fell back to it's
own defaults which were the same.
2025-12-08 11:46:50 +00:00
Callum Law
89ce62fa2a LibWeb: Always parse background longhands as StyleValueLists
Matches the behavior of parsing these longhands directly.
2025-12-08 11:46:50 +00:00
Callum Law
020c4aadff LibWeb: Parse background-position as ShorthandStyleValue
This makes us consistent with how we handle this value within the
`background` shorthand and allows us to remove the special handling in
`StyleComputer::for_each_property_expanding_shorthands`
2025-12-08 11:41:13 +00:00
Callum Law
540b26e426 LibWeb: Remove unnecessary parse_overflow_value method
This is handled by the generic logic for parsing positional value list
shorthands once we register the legacy value alias of `overlay>auto` on
the shorthand as well as longhand properties.
2025-12-08 11:41:13 +00:00
Callum Law
46914aa876 LibWeb: Generically parse coordinating value list properties
Some of the remaining coordinating value list properties (e.g.
transition-property) require custom handling as they are not always
simple comma separated lists but others (e.g. background-size) can be
removed if we promote their relevant syntax to a `ValueType`
2025-12-08 11:41:13 +00:00
Callum Law
fc72cb25af LibWeb: Simplify parse_transition_value 2025-12-08 11:41:13 +00:00
Callum Law
00ab0c8dea LibWeb: Simplify parsing of positional value list shorthands
We can use the (relatively) new `parse_all_as` method to remove some
boilerplate here
2025-12-08 11:41:13 +00:00
Sam Atkins
16c12c1485 LibWeb: Parse the ::part() pseudo-element selector
It doesn't yet do anything, but it helps a few tests that just check
serialization.
2025-12-08 09:44:32 +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
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
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
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
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
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
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
InvalidUsernameException
28ba610f32 Everywhere: Avoid large rebuilds when editing (Immutable)Bitmap headers
This reduces the number of recompiled files as follow:
- Bitmap.h: 1309 -> 101
- ImmutableBitmap.h: 1218 -> 75
2025-11-28 18:32:48 +01:00
Callum Law
9afb523be3 LibWeb: Remove unnecessary parse_list_of_time_values function
We can achieve the same thing by using
`parse_simple_comma_separated_value_list`
2025-11-28 16:15:49 +00:00
Callum Law
b0ab94c00c LibWeb: Allow multiple values for transition-behavior 2025-11-28 16:15:49 +00:00
Callum Law
70c4ed261f LibWeb: Reduce the number of headers CSS Parser.h is included in
Reduces the rebuild required when editing this file
2025-11-28 16:15:49 +00:00
Callum Law
c8d91c127e LibWeb: Parse view() for the animation-timeline CSS property 2025-11-28 13:24:11 +00:00
Callum Law
7d70714eac LibWeb: Parse scroll() for the animation-timeline CSS property 2025-11-28 13:24:11 +00:00
Callum Law
5bbcd0a48f LibWeb: Parse the animation-timeline CSS property 2025-11-28 13:24:11 +00:00
Callum Law
d79aba68d2 LibWeb: Allow reset-only longhands in coordinating value list shorthands
Required for `animation-timeline` and the various `animation-trigger-*`
properties within the `animation` coordinating value list
2025-11-28 13:24:11 +00:00
Callum Law
6bb7224f4e LibWeb: Parse the view-timeline shorthand CSS property
The remaining failing tests in view-timeline-shorthand.html are due to
either:
 a) incorrect tests, see web-platform-tests/wpt#56181 or;
 b) a wider issue where we collapse coordinating value list longhand
properties to a single value when we shouldn't.
2025-11-28 13:24:11 +00:00