Commit Graph

2238 Commits

Author SHA1 Message Date
Sam Atkins
492cfc58d9 LibWeb/CSS: Add flags for element-backed & tree-abiding pseudo-elements
Generate a couple of functions for checking if a pseudo-element fits
these categories.
2026-04-08 10:37:05 +01:00
Andreas Kling
e15b1a33cb LibWeb: Parse sizes media conditions per HTML
The HTML sizes algorithm does not use full media queries. It evaluates
a restricted media-condition grammar and then parses the selected
source size value as a length.

Teach the parser to follow that split more closely: treat sizes
conditions as two-valued booleans, validate MQ5 <general-enclosed>
contents more strictly, accept calc(0) for media feature values, and
reject only source-size math results that are negative or non-finite.

The imported sizes parsing tests then progress from 140/171 to
171/171 in all four cases.
2026-04-05 22:01:18 +02:00
Shannon Booth
bb0f244667 LibWeb: Remove ShadowRealm HTML integration 2026-04-05 13:57:58 +02:00
Andreas Kling
e2e3c7fcdf LibWeb: Rebuild counter style cache lazily
Stop rebuilding the counter style cache from every style update.
That made unrelated restyles pay the full counter-style cost even when
no relevant stylesheet state had changed.

Dirty the cache when stylesheet rule caches are invalidated and rebuild
it on the first counter-style lookup instead. Also make cold cache
rebuilds include user stylesheets.

Add regression tests covering insertRule() and replaceSync() updates
that should make newly defined counter styles take effect.
2026-04-05 12:34:28 +02:00
Andreas Kling
0b5ef8fa22 LibWeb: Invalidate styles after constructable sheet updates
Constructed stylesheets updated their rule lists, but adopted documents
and shadow roots were not restyled when replace(), replaceSync(),
or disabled-state changes modified the sheet.  That left several CSSOM
tests passing stale computed styles.

Invalidate stylesheet owners after those updates so adopted sheets
recompute promptly. Also set replace()-produced rules' parent
stylesheet so non-import rules keep their stylesheet context.

The imported baseURL test assumes a tuple origin, so move it to the
HTTP fixture now that replaceSync() actually triggers a restyle.
2026-04-05 12:34:28 +02:00
Tim Ledbetter
5b584fde1d LibWeb: Register JS-created FontFace objects for font matching
Previously, FontFace objects created via the JS and added to
`document.fonts` were stored in the FontFaceSet but never participated
in font matching during style resolution. We now store both
CSS-connected and JS-created font faces in a unified map on
`FontComputer`, keyed by family name, and include them all as
candidates in the font matching algorithm.
2026-04-05 00:13:35 +02:00
Tim Ledbetter
d0b1482e80 LibWeb: Consolidate OwnFontFaceKey and FontFaceKey into a single type
Previously, `FontComputer` used two key types for its font map: a
non-owning `FontFaceKey` for lookups and an owning `OwnFontFaceKey` for
storage. This change replaces both with a single FontFaceKey that owns
its FlyString.
2026-04-05 00:13:35 +02:00
Tim Ledbetter
333df3b399 LibWeb: Cache parsed font descriptors on FontFace objects 2026-04-05 00:13:35 +02:00
Glenn Skrzypczak
f1d3244b22 LibWeb: Support CSS modules
This adds support for importing CSS stylesheets from CSS files in
javascript.
2026-04-03 21:21:09 +02:00
Jelle Raaijmakers
38342b2ad3 LibWeb: Add valid normal and none keywords for position-anchor
The WPT test was updated from upstream, but still assumes a wrong
initial value of `none`.

Co-authored-by: Rob Ryan <rob@affclicks.com>
2026-04-01 19:41:46 +01:00
Jelle Raaijmakers
4293c841f3 LibWeb: Implement CSS anchor positioning
When `position-anchor` is used, resolve the insets for that absolutely
positioned box.

Co-authored-by: Rob Ryan <rob@affclicks.com>
2026-04-01 19:41:46 +01:00
Jelle Raaijmakers
00397b4808 LibWeb: Keep track of elements with an anchor-name set
We maintain a registry of elements with an anchor-name so once they are
referenced for anchor positioning, we can find them with an O(1) lookup
instead of traversing the entire DOM tree.
2026-04-01 19:41:46 +01:00
Jelle Raaijmakers
1012aad322 LibWeb: Remove bogus discard_a_token() from CSS anchor fallback parsing
This correctly rejects invalid trailing tokens from `anchor()` fallback
values. Also introduces discard_whitespace() to take care of any
whitespace between the fallback value and the closing parenthesis.
2026-04-01 19:41:46 +01:00
Jelle Raaijmakers
6068d94752 LibWeb: Update/remove unused includes
No functional changes.
2026-04-01 19:41:46 +01:00
Tim Ledbetter
5a05909eab LibWeb: Disallow animation properties inside keyframe declarations
We now ignore all animation properties from `css-animations-1` declared
within keyframes, except `animation-timing-function`, which is treated
specially.
2026-04-01 11:38:48 +01:00
Tim Ledbetter
af6bc07c4f LibWeb/CSS: Resolve var() in keyframe animation-timing-function
When a `@keyframes` rule contains `animation-timing-function` with a
`var()`, we cannot eagerly resolve it to an `EasingFunction` at rule
cache build time because there is no element context available. We now
store the unresolved `StyleValue` and defer resolution to
`collect_animation_into()`, where the animated element's custom
properties can be used to substitute the variable. Previously, an
`animation-timing-function` with a `var()` in a `@keyframe` would cause
a crash.
2026-04-01 11:38:48 +01:00
Tim Ledbetter
9640e08646 LibWeb: Normalize color-mix() percentages at resolution time
Previously it was possible to hit a null deference if to_color() was
called on a non-absolutized `ColorMixStyleValue`.
2026-03-31 21:02:57 +02:00
Tim Ledbetter
e8a13b30b6 LibWeb: Absolutize ScrollbarColorStyleValue color values 2026-03-31 21:02:57 +02:00
Tim Ledbetter
58ce1f9ec4 LibWeb: Absolutize color in ShadowStyleValue
ShadowStyleValue was not absolutizing its color component, which meant
that complex color values like `color-mix()` would retain unresolved
state. This caused a null pointer dereference when `color-mix()` with
omitted percentages was used as a shadow color. We now absolutize the
color component, avoiding this crash.
2026-03-31 21:02:57 +02:00
Shannon Booth
a066ee720e LibWeb/CSS: Remove redundant has_alt_text() from ContentStyleValue
Replace the has_alt_text() / alt_text() calls by directly null
checking on the returned pointer from alt_text().
2026-03-31 13:48:50 +01:00
Jelle Raaijmakers
bff863d6d9 LibGfx+LibWeb: Remove unused code from Gfx::Point/Rect/Size
No functional changes.
2026-03-31 10:37:23 +02:00
Callum Law
847cf74ff8 LibWeb: Remove Length::ResolutionContext::for_window
This didn't work within iframes and all users have been moved over to
use `for_document` instead
2026-03-31 10:06:18 +02:00
Callum Law
90e0e5a0f2 LibWeb: Use correct viewport units for font properties in iframe root el 2026-03-31 10:06:18 +02:00
Callum Law
fec79b62e4 LibWeb: Always pass ASF presence to UnresolvedSV::create()
There was only one place that we weren't passing this where we could
have ASFs so let's just handle that there and explicitly mark the others
as having no ASFs to avoid unnecessary work.

No functional changes
2026-03-30 19:57:36 +01:00
Callum Law
03d479c1da LibWeb: Validate ASF syntax at parse time 2026-03-30 19:57:36 +01:00
Callum Law
04f634eeb2 LibWeb: Disallow ASF in initialValue when calling registerProperty 2026-03-30 19:57:36 +01:00
Callum Law
071b000d9f LibWeb: Only allow ASFs in descriptor values if explicitly supported
`@function` descriptors are the only ones that support ASFs, while most
descriptors enforce this through their syntaxes implicitly disallowing
ASFs, this wasn't the case for `@property/initial-value`.

We now explictly disallow ASFs unless they are marked as allowed within
`Descriptors.json`.
2026-03-30 19:57:36 +01:00
Callum Law
8b66e7f463 LibWeb: Consider semicolon in parse_descriptor_value a SyntaxError
Everywhere we use this expects us to parse the whole value, either
because we are parsing the value of a declaration (in which case there
will be no semicolons), or because it is called from a JS setter which
takes whole values and semicolons make the value invalid.

Previously we would just ignore everything after a semicolon.

This also allows us to avoid creating a new `Vector` and copying all the
component values
2026-03-30 19:57:36 +01:00
Callum Law
7d2f772317 LibWeb: Move ASF presence checking into Parser
We are going to extend this and use it elsewhere in the future so it's a
bit neater here.

No functional changes
2026-03-30 19:57:36 +01:00
Adam Colvin
36c549eba7 LibWeb: Support ::part() pseudo-element chaining
Allow CSS pseudo-element chaining with ::part() so that
selectors like ::part(title)::before can style pseudo-elements
within shadow DOM parts.

Parser changes (SelectorParsing.cpp): The pseudo-element
validation logic now tracks which pseudo-element appears first
and second in a compound selector. When multiple pseudo-elements
are found, the parser permits the selector only if the first is
::part() and the second is NOT ::part(). A maximum of two
pseudo-elements is enforced.

Selector changes (Selector.cpp, Selector.h): The Selector
constructor now stores the last pseudo-element (the styling
target) rather than the first. For ::part(foo)::before, the
selector reports ::before as its target. A new
m_contains_part_pseudo_element flag separately tracks whether
::part() is present for the selector engine.

Fixes 9 WPT tests: 6 in css/selectors/parsing/parse-part.html
for chained selector parsing, and 3 in
css/css-shadow-parts/multiple-scopes.html for correct scoping
of exported, middle-scope, and non-exported part selectors.
2026-03-30 16:47:34 +01:00
Adam Colvin
cf67db5f0d LibWeb: Only match ::part() in direct child shadow trees
When matching ::part(), only consider shadow trees whose host lies in
the same style scope as the rule. Use MatchContext::rule_shadow_root,
which is already set when collecting ::part() rules, as that scope.

For cross-scope rules, accept a candidate shadow root only if its
host's containing_shadow_root() matches the rule's shadow root: the
rule's scope is the document when rule_shadow_root is null, or that
shadow root when the rule comes from its stylesheet.

The one exception is :host::part(): the rule and the part live in the
same shadow root, so its host is outside the rule's scope and the
comparison would never pass. Allow the check to be skipped for this
case by setting MatchContext::for_host_part_matching when the compound
selector contains :host (directly or inside :is(), which is how CSS
nesting resolves &::part() inside a :host rule).

Run that :host pre-scan only when rule_shadow_root is set. Document
rules never use the same-shadow-root exception; scanning would
otherwise set for_host_part_matching whenever :host appears in the
compound and break cross-scope ::part() matching (e.g. multiple-scopes).

Previously the engine walked all ancestor shadow roots without this
cross-scope check.
2026-03-30 16:47:34 +01:00
Sam Atkins
c2f0d61eb6 LibWeb/CSS: Implement initial parsing for @container rules
The main limitation here are that none of the container-query features
are parsed in a meaningful way; they all become `<general-enclosed>`.
Parsing for them will be added as they are implemented.
2026-03-30 14:49:24 +01:00
Sam Atkins
214d2b5e1f LibWeb/CSS: Implement CSSContainerRule
No parsing yet, just CSSContainerRule and the supporting ContainerQuery
class.

CSSContainerRule is unusual in how it matches, because instead of it
either matching or not matching globally, it instead is matched against
a specific element. But also, some at-rules inside it always apply, as
if they were written outside it. This doesn't fit well with how
CSSConditionRule is implemented, and will likely require some rework
later. For now, `condition_matches()` always returns false, and
`for_each_effective_rule()` is overridden to always process those
global at-rules and nothing else.
2026-03-30 14:49:24 +01:00
Callum Law
0219eb2ef9 LibWeb: Remove FooOrCalculated classes
These are unused since we now store values as `StyleValue`s before
used-value time, and as their resolved type (e.g. CSSPixels) after
2026-03-30 14:05:10 +01:00
Callum Law
cbc2bb7aa7 LibWeb: Don't pass layout node when resolving EdgeRect
We know that these lengths have already been absolutized at computed
value time
2026-03-30 14:05:10 +01:00
Callum Law
3aa71034de LibWeb: Support calc() within clip: rect() 2026-03-30 14:05:10 +01:00
Callum Law
ab6f5b36d2 LibWeb: Add LengthOrAuto::from_style_value 2026-03-30 14:05:10 +01:00
Callum Law
3b3f06bfa3 LibWeb: Support non-literal integers in repeat()
We now support non-literal integers (i.e. `calc()` and tree counting
functions) within `<track-repeat>` and `<fixed-repeat>`
2026-03-30 14:05:10 +01:00
Callum Law
f2a8099d13 LibWeb: Parse sizes attribute as StyleValue
Gets us a step closer to removing the `FooOrCalculated` classes
2026-03-30 14:05:10 +01:00
Callum Law
3e58e15217 LibWeb: Support relative lengths within color-mix percentage calc()s 2026-03-30 14:05:10 +01:00
Callum Law
3c00a13237 LibWeb: Remove redundant normalization of percentages in ColorMixSV
We normalize percentages at computed value time so there's no need to
normalize them again when converting to used value
2026-03-30 14:05:10 +01:00
Callum Law
9b2dd73359 LibWeb: Store ColorMixComponent::percentage as StyleValue
This simplifies handling and gets us closer to removing the
`OrCalculated` classes
2026-03-30 14:05:10 +01:00
Callum Law
149acdd7c5 LibWeb: Add Percentage::from_style_value 2026-03-30 14:05:10 +01:00
Callum Law
fe5d6471f0 LibWeb: Store GridTrackPlacement sub-values as StyleValues
Gets us one step closer to removing the `FooOrCalculated` classes
2026-03-30 14:05:10 +01:00
Dylan Hart
1354eb1ac2 LibWeb: Resolve var() in shorthands before pseudo-element filtering
When a shorthand like `background` containing `var()` is used in
a `::selection` rule, the shorthand was filtered out by the pseudo-
element property whitelist before variable resolution could occur.
This left PendingSubstitutionStyleValue longhands unresolved,
causing either a crash or incorrect computed values.

Allow unresolved shorthands to bypass the pseudo-element filter so
variable resolution can proceed. After resolution and expansion
into longhands, filter out any that the pseudo-element does not
support.

Fixes #8625.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 12:46:20 +01:00
Tim Ledbetter
4c48827ed2 LibWeb: Merge duplicate @keyframe rule selector values
Previously, a keyframe with duplicate selector would cause a crash.
2026-03-30 12:42:57 +01:00
Sam Atkins
fd46ade2a2 LibWeb/CSS: Add the env() function to @supports conditions
This was just added to the spec and doesn't yet have WPT coverage, but
it's also pretty trivial.
2026-03-29 21:27:20 +01:00
Tim Ledbetter
657060ccc2 LibWeb: Implement FontFaceSet.check()
This returns true if the given text can be rendered with the fonts in
the set that are fully loaded.
2026-03-27 15:28:59 +00:00
Callum Law
c7b402eff5 LibWeb: Parse @function rules 2026-03-27 11:19:28 +00:00
Callum Law
01394322ac LibWeb: Propagate media query evaluation into @function rules
`CSSFunctionRule`s can contain `CSSMediaRule`s so we need to propagate
evaluation through `CSSFunctionRule`
2026-03-27 11:19:28 +00:00