Commit graph

1771 commits

Author SHA1 Message Date
Andreas Kling
7f709c6502 LibWeb: Improve the ancestor filter we use during selector matching
Before this change, we'd stop collecting must-be-present identifiers
from the selector once we crossed a combinator that wasn't ' ' or '>'.

However, we can simply skip over sibling combinators and continue
collecting ancestor identifiers on the "other side" of them, since
siblings always have a shared parent.

This allows us to use the ancestor filter to quickly reject more
selectors. It also fixes a harmless bug where we believed the ancestor
filter to be useful while there were 0 ancestor hashes in the selector.
2025-12-20 12:55:26 -06:00
Andreas Kling
95a9ea68a0 LibWeb: Add fast_is<T>() for CalculationNode and all its subclasses 2025-12-20 09:13:19 -06:00
Andreas Kling
b3b3a8602a LibWeb: Mark a handful of CSS properties as not affecting layout
I noticed us invalidating layouts in the wild (e.g on reddit) for
properties that can't possibly affect layout.
2025-12-20 08:21:18 +00:00
Sam Atkins
c446281844 LibWeb/CSS: Remove Transformation in favor of TransformationStyleValue
The Transformation class wasn't really accomplishing anything. It still
had to store StyleValues, so it was basically the same as
TransformationStyleValue, with extra steps to convert from one to the
other. So... let's just use TransformationStyleValue instead!

Apart from moving code around, the behavior has changed a bit. We now
actually acknowledge unresolvable parameters and return an error when
we try to produce a matrix from them. Previously we just skipped over
them, which was pretty wrong. This gets us an extra pass in the
typed-om test.

We also get some slightly different results with our transform
serialization, because we're not converting to CSSPixels and back.
2025-12-19 14:51:53 +01:00
Sam Atkins
6b5836644a LibWeb/CSS: Use PaintableBox for matrix interpolation when available 2025-12-19 14:51:53 +01:00
Sam Atkins
ab176b5dde LibWeb/CSS: Allow unreifiable transform-lists to reify as CSSStyleValues
Some transform-functions are not reifiable as a CSSTransformComponent,
for example a matrix() with sibling-index() in it. In that case, rather
than crashing, fall back to the basic CSSStyleValue reification.

The crash doesn't happen yet, but would with the following commit's
changes. Currently, Transformation::to_matrix() completely ignores
unsupported argument types, but in the next commit that's replaced with
TransformationStyleValue::to_matrix(), which attempts to handle them
properly.
2025-12-19 14:51:53 +01:00
Sam Atkins
b0b0669187 LibWeb/CSS: Add :-webkit-autofill as a legacy alias of :autofill 2025-12-18 14:50:27 +01:00
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
36a9b653ae LibWeb/CSS: Add the :autofill pseudo-class
We don't support autofilling of form data yet, so this matches nothing
for now.
2025-12-18 14:50:27 +01:00
Sam Atkins
4b918cba50 LibWeb/CSS: Serialize very small numbers as 0
The spec asks us to serialize with no more than 6 decimal digits, so if
the number is smaller than 0.000,000,5 then it can't produce any digits
and we should serialize it as 0, instead of using scientific notation.

We also shouldn't use scientific notation for very large numbers, but we
don't seem to have a flag to disable that in the formatter, so I'm
leaving a FIXME for now.

Improves some test results. 🎉
2025-12-18 11:21: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
Tim Ledbetter
da92e1a054 LibWeb: Mark absolute_length_to_px() methods as [[nodiscard]] 2025-12-16 11:22:59 +00:00
Sam Atkins
45fc72214f LibWeb/CSS: Set border-widths to 0 at used time, not computed time
...when the style is `none` or `hidden`. `outline-width` is not affected
by `outline-style: none` at all.

In our codebase, that means doing the border-width conversion when
assigning to ComputedValues.

Corresponds to:
2a3d1e4d10
09f11f2ef9
2025-12-15 21:28:19 +01: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
Sam Atkins
4ab9ac86a7 LibWeb/CSS: Implement basic ::part() matching
Matches elements with a `part` attribute, against their parent shadow
host.
2025-12-15 14:12:39 +00:00
Sam Atkins
f9f4c36f20 LibWeb: Implement the headingoffset and headingreset attributes
:heading() now matches based on a computed heading level, which is based
on the level of the tag (h1, h2, etc) and then modified by these two new
attributes.

I'm caching this heading level on HTMLHeadingElement, based on the dom
tree version. That's more invalidation than is actually needed, but it
saves us calculating it over and over when the document hasn't changed.

The failing test cases are:
- Implicit headingreset for modal dialogs which is apparently unspecced
  and controversial.
- Not walking the flat tree properly. A flat tree ancestor of a
  slot-assigned element is its slot, which is something we don't do
  anywhere that I could find. I've made a note to look into this later.

We also don't implement the `ReflectRange` IDL attribute yet, which
means we're not clamping the read value of `headingOffset`.

Corresponds to:
e774e8e318
2025-12-15 14:08:24 +00:00
Sam Atkins
a54276fba8 LibWeb/CSS: Update UA styling for headings
Corresponds to part of:
e774e8e318
2025-12-15 14:08:24 +00:00
Psychpsyo
c9518fc06c LibWeb: Add handling for view transition selector specificity
The corresponding WPT test was not imported since it still fails
for unrelated reasons. As it stands right now, we have no way of
testing this behavior.
2025-12-15 09:48:19 +00:00
Callum Law
883b190e64 LibWeb: Omit default radius from ellipse() serialization 2025-12-12 12:20:16 +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
375df05ab9 LibWeb: Omit default radius from serialization of CSS circle() 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
7b76b7f6f6 LibWeb: Add PositionStyleValue::create_computed_center
This is equivalent to the existing `PositionStyleValue::create_center`
but returns the value expected after computation has been completed
(i.e. `50% 50%` rather than `center center`)
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
Callum Law
69f05bd45d LibWeb: Store animation time values in abstract type
In level 2 of the web animations spec, times are no longer always
measures in milliseconds, they can also be percents when dealing with
progress-based (i.e. scroll-based) timelines.

We don't actually support percent times yet but this change will make it
easier to implement when we do.
2025-12-12 10:49:18 +00:00
Callum Law
f9df1c4eea LibWeb: Implement distinct specified timing values for AnimationEffect
Web Animations Level 2 disallows setting some `AnimationEffect` timing
values (start delay, end delay, iteration duration) directly and instead
allows authors to set the specified values which are then normalized
into the actual used values taking into account the type of the
associated timeline (i.e. progress- vs time-based)
2025-12-12 10:49:18 +00:00
Callum Law
435791b754 LibWeb: Implement AnimationTimline::duration property
This was added in Level 2 of the Web Animations spec

In this level of the spec, all time values associated with animations
(including this duration property) are no longer simple numbers but are
instead either percentages or numbers for progress- and time-based
timelines respectively. These values are represented internally by a new
`TimeValue` wrapper struct, and externally (i.e. in JS) as
`CSSNumberish`.
2025-12-12 10:49:18 +00:00
Sam Atkins
7ef2a1369c LibWeb/CSS: Use web-exposed available screen area for Screen.avail*
Also spec-comment the methods here, and stop converting the entire rect
to integers when we only care about one value.
2025-12-12 10:17:00 +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
73f41b20b4 LibWeb: Compute rect() and xywh() to their equivalent inset()
This also allows us to remove the path generation and interpolation
handling for `rect()` and `xywh()` since that occurs after computation

Regressions in clip-path-interpolation-xywh.html are due to improper
simplification of length-percentage mixes where the length is 0px.
2025-12-09 11:23:59 +00:00
Callum Law
46da13636e LibWeb: Reduce overlapping inset() dimensions 2025-12-09 11:23:59 +00:00
Callum Law
6a682c5f2b LibWeb: Make logic for creating CalculationNode from StyleValue reusable
This is useful in places other than just interpolation
2025-12-09 11:23:59 +00:00
Callum Law
2fca7a3847 LibWeb: Add absolutized method to BasicShapeStyleValue 2025-12-09 11:23:59 +00:00
Callum Law
0c72b757a4 LibWeb: Use correct calculation context for interpolating basic shapes
This allows us to interpolate between a length and a percentage (or vice
versa)
2025-12-09 11:23:59 +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
c705b47b31 LibWeb/CSS: Serialize idents properly within ::part() 2025-12-08 17:28:09 +01:00
Sam Atkins
c19139f1c7 LibWeb/CSS: Assign layers to @import statements
Specifically, we create and assign a layer if its import conditions
currently apply.

With this change, every case in the `layer-import.html` test actually
functions correctly, apart from our lack of proper `load` event
support. (Tested by hacking in a 100ms wait after the `await Promise()`
statement.)
2025-12-08 13:30:53 +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
5d38a3639f LibWeb/CSS: Implement CSSImportRule.layerName IDL attribute 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
233146421a LibWeb: Don't collapse serialized comma separated StyleValueLists 2025-12-08 11:46:50 +00:00
Callum Law
68d07355ed LibWeb: Coordinate border-* longhands at compute time
Updates the `position-serialization.html` test to be 2-valued so that
all cases are covered.
2025-12-08 11:46:50 +00:00
Callum Law
a11666e097 LibWeb: Simplify creation of background layers
We can deduplicate some code by using `assemble_coordinated_value_list`,
also moves this to a method in `ComputedProperties` to be in line with
other values
2025-12-08 11:46:50 +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