Commit graph

2065 commits

Author SHA1 Message Date
Tim Ledbetter
f05bc7c0cd LibWeb: Implement dominant-baseline for SVG text
This property determines the default baseline used to align content
within the given box.
2026-02-26 09:23:23 +01:00
Jelle Raaijmakers
90a211bf47 LibWeb: Use device-pixel coordinates in display list and AVC
Stop converting between CSS and device pixels as part of rendering - the
display list should be as simple as possible, so convert to DevicePixels
once when constructing the display list.
2026-02-26 07:43:00 +01:00
Andreas Kling
f1573dfc63 LibWeb: Use GC::WeakHashSet for StyleScope's pending :has() nodes
Replace the unsafe HashTable<GC::Weak<DOM::Node>> with
GC::WeakHashSet<DOM::Node>. The null check in the iteration loop is
no longer needed since WeakHashSet's iterator skips dead entries.
2026-02-24 22:35:03 +01:00
Sam Atkins
1ac3ede046 LibWeb/CSS: Make @font-face a critical style subresource
This causes `@font-face`'s loading state to propagate to its style sheet
and upwards.
2026-02-24 15:44:32 +00:00
Sam Atkins
5e3f4d71cc LibWeb/CSS: Remove number_of_css_font_faces_with_loading_in_progress()
This is now unused as of the previous commit.
2026-02-24 15:44:32 +00:00
Sam Atkins
d9f12da712 LibWeb: Implement missing code for FontFace/FontFaceSet loading
As FontFaces are added or removed from a FontFaceSet, and as they load
or fail, the FontFaceSet moves them between a few different lists, and
updates its loading/loaded status. In the spec, this is how the
FontFaceSet.[[ReadyPromise]] gets fulfilled: When the document has
finished loading and FontFaceSet.[[LoadingFonts]] is empty, it resolves
the promise.

To support this, FontFace now keeps a set of FontFaceSets that it is
contained in.

This lets us remove the non-spec resolve_ready_promise() call in
EventLoop which was sometimes triggering before any fonts had attempted
to load.

As noted, there's a spec issue with the ready promise: If nothing
modifies the document's fonts, then it would never resolve. My ad-hoc
fix is to also switch the FontFaceSet to the loaded state if it is
empty, which appears to solve the issues but is not ideal.
2026-02-24 15:44:32 +00:00
Sam Atkins
f82201e908 LibWeb/CSS: Remove unnecessary FontFaceSet::construct_impl()
The current css-font-loading spec doesn't define a constructor for this,
and from our own code we can rely on initializing things in the C++
constructor.
2026-02-24 15:44:32 +00:00
Sam Atkins
4ea87db0a8 LibWeb/CSS: Load all fonts through FontFace::load()
The spec requires us to follow the steps in FontFace::load() whenever a
font is loaded. The simplest way to do so, is to make that the only way
we load fonts. :^)

To support this, FontFace::load() uses its connected CSSFontFaceRule's
ParsedFontFace if it's available.

The 1 regression in generic-family-keywords-003.html seems to be a false
positive: we don't support the system-ui font keyword.
2026-02-24 15:44:32 +00:00
Sam Atkins
86ae5022c2 LibWeb/CSS: Mark CSSStyleSheetInit::baseURL as nullable
Corresponds to:
f0635e6e10

Assigning null to a non-nullable DOMString didn't make sense.
Apparently our bindings generator didn't care though. It's already
nullable on the C++ side by being an Optional<String>.
2026-02-24 14:36:40 +01:00
Sam Atkins
c9350374a1 LibWeb/CSS: Update a couple of font-related comments 2026-02-24 10:05:09 +00:00
Sam Atkins
f657a4b71b LibWeb/CSS: Parse @font-face { font-weight } with two values
WPT has coverage for matching but not parsing, so the test is homemade.
2026-02-24 10:05:09 +00:00
Sam Atkins
2660db3f52 LibWeb/CSS: Make FontFaceKey weights a range of values
For now, both the `min` and `max` are the single value we had before.
2026-02-24 10:05:09 +00:00
Sam Atkins
9e85e52db9 LibWeb/CSS: Reuse OwnFontFaceKey::hash() in hash traits 2026-02-24 10:05:09 +00:00
Simon Farre
bc17805b2b LibWeb: Implement requestFullscreen algorithm
The required functionality to exit fullscreen will be in a followup
commit.
2026-02-23 18:44:26 +00:00
Simon Farre
53eae831e2 LibWeb: Add default user agent style sheet for Fullscreen API
Matching the fullscreen pseudo class is currently a stub that will be
implemented in a future commit.
2026-02-23 18:44:26 +00:00
Luke Wilde
41ef9c2754 LibWeb: Expand PseudoClassBitmap to support more than 64 pseudo classes 2026-02-23 18:44:26 +00:00
Tim Ledbetter
b3e6df5eef LibWeb: Defer vector allocation in StyleValueList::absolutized()
We now only allocate a StyleValueVector if we know absolutization has
caused a value to change.

This change also avoids a double StyleValue::absolutized() computation.
2026-02-23 17:30:25 +01:00
Callum Law
8d4084261a LibWeb: Resolve list item marker using registered counter styles 2026-02-23 11:21:09 +00:00
Callum Law
ca54cc6c79 LibWeb: Resolve <counter> functions using registered counter styles
Previously we only supported a subset of the predefined counter styles,
we now respect counter styles defined by `@counter-style` rules when
resolving the value of `counter()` and `counters()` functions
2026-02-23 11:21:09 +00:00
Callum Law
2008c6be5a LibWeb: Add predefined @counter-styles to UA stylesheet
There are some predefined counter styles (such as the longhand east
asian ones) which are too complex to be defined here and will need to be
implemented ad-hoc, this remains as a FIXME for now.
2026-02-23 11:21:09 +00:00
Callum Law
3e9cdb2cf4 LibWeb: Store whether sheet being parsed is a UA stylesheet
UA stylesheets allow some things that regular stylesheets don't, for
instance allowing use of "non-overridable" `@counter-style` names.
2026-02-23 11:21:09 +00:00
Callum Law
73b07d25ac LibWeb: Resolve and register counter styles from @counter-style rules
The tricky bit of this is resolving cycles in extending rules and
ensuring that counter styles are registered in the required order for
extension (i.e. for any pair of extended/extending rules the extended
one should be registered first).
2026-02-23 11:21:09 +00:00
Callum Law
3d150e46c2 LibWeb: Avoid template for StyleScope::for_each_stylesheet
This only ever takes a `Function<void(CSS::CSSStyleSheet&)` so there is
no need to use a template here.
2026-02-23 11:21:09 +00:00
Callum Law
2cc3fbb017 LibWeb: Pass callback as lvalue ref in for_each_active_stylesheet
Taking the callback as an rvalue ref meant we couldn't use the same
callback more than once
2026-02-23 11:21:09 +00:00
Callum Law
0002d1cfc3 LibWeb: Implement algorithm to generate a counter representation 2026-02-23 11:21:09 +00:00
Callum Law
63e2ed3cd9 LibWeb: Implement counter style fixed algorithm 2026-02-23 11:21:09 +00:00
Callum Law
fb239ceba0 LibWeb: Implement counter style symbolic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
fddeb032b4 LibWeb: Implement counter style alphabetic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
0a2fe1607c LibWeb: Implement counter style numeric algorithm 2026-02-23 11:21:09 +00:00
Callum Law
85c367667e LibWeb: Implement counter style cyclic algorithm 2026-02-23 11:21:09 +00:00
Callum Law
2827e12571 LibWeb: Implement counter style additive algorithm 2026-02-23 11:21:09 +00:00
Callum Law
cfa5bc44d5 LibWeb: Implement creating CounterStyle from CounterStyleDefinition 2026-02-23 11:21:09 +00:00
Callum Law
ff40e9e7ba LibWeb: Stub CounterStyle
Eventually this will be used to resolve counter representations but we
are yet to implement any of the algorithms to do so.
2026-02-23 11:21:09 +00:00
Callum Law
bb5c8bb5be LibWeb: Add CounterStyleDefinition
This serves as an intermediate step between `CSSCounterStyleRule` and a
fully built counter style which will be helpful for:
 - Determining whether a rule defines a counter style
 - Resolving extends cycles
 - Determining registration order
2026-02-23 11:21:09 +00:00
Callum Law
32b9ff21df LibWeb: Add generic int_from_style_value method
Reduces duplication in line with `number_from_style_value`,
`string_from_style_value` etc
2026-02-23 11:21:09 +00:00
Callum Law
49eb9d7a7a LibWeb: Support composition of mixed values
This exposes an existing issue with interpolation where it is not clear
in what situations zero-valued dimensions should be excluded from the
interpolated value of a dimension-percentage mix (e.g. `calc(50% + 0px)`
vs `50%`) - but this is just a serialization issue as both
representations are resolved to the same used value
2026-02-23 09:01:19 +00:00
Callum Law
f7e5e57233 LibWeb: Make get_value_type_of_numeric_style_value reusable
This will also be used in composition of mixed types
2026-02-23 09:01:19 +00:00
Zaggy1024
21019c2fa9 LibWeb: Use UA shadow DOM for media elements' controls
Instead of using a custom paintable to draw the controls for video and
audio elements, we build them out of plain old HTML elements within a
shadow root.

This required a few hacks in the previous commits in order to allow a
replaced element to host children within a shadow root, but it's
fairly self-contained.

A big benefit is that we can drive all the UI updates off of plain old
DOM events (except the play button overlay on videos, which uses the
video element representation), so we can test our media and input event
handling more thoroughly. :^)

The control bar visibility is now more similar to how other browsers
handle it. It will show upon hovering over the element, but if the
cursor is kept still for more than a second, it will hide again. While
dragging, the controls remain visible, and will then hide after the
mouse button is released.

The icons have been redesigned from scratch, and the mute icon now
visualizes the volume level along with indicating the mute state.
2026-02-23 07:27:31 +01:00
Adam Colvin
d2f10c76fd LibWeb: Reject invalid alt text values in CSS content property parsing
The CSS content property's alt text (after `/`) was incorrectly
accepting any content value. Per the CSS Content Module Level 3 spec,
alt text only accepts <string>, <counter>, and <attr()> values. This
change adds type validation in the alt text parsing branch to reject
URLs, quote keywords, images, and other non-alt-text value types.

This fixes 64 subtests in the content-invalid WPT test.
2026-02-22 13:55:22 -05:00
Aliaksandr Kalenik
795222fab3 LibWeb: Validate grid-template-areas rectangles at parse time
Move grid area rectangle computation and validation from layout to the
CSS parser. Named grid areas that don't form filled-in rectangles now
correctly invalidate the declaration per spec.
2026-02-21 21:46:34 +01:00
Andreas Kling
a4d949ff55 LibWeb: Inline trivial CSS::Display query methods
Move all the simple bool query methods (is_table_inside,
is_table_cell, is_none, is_block_outside, etc.) from Display.cpp into
Display.h as inline definitions. These are trivial one-liners called
in very hot painting and layout paths.

Keep only to_string() and from_short() out-of-line.
2026-02-21 15:53:22 +01:00
Andreas Kling
18710f790f LibWeb: Shrink CSS::Display by giving explicit u8 size to inner enums
CSS::Display::Type and CSS::Display::ListItem defaulted to int (4
bytes each). Give them explicit u8 underlying types, shrinking
CSS::Display from 12 bytes to 4 bytes.
2026-02-21 15:53:22 +01:00
Callum Law
21c7de49f8 LibWeb: Remove outdated FIXME
As of 020c4aa we parse all shorthands as `ShorthandStyleValue`s and thus
this FIXME is irrelevant
2026-02-21 06:33:40 +00:00
Callum Law
e6669482e6 LibWeb: Parse font-variant-alternates functions 2026-02-20 22:01:44 +00:00
Callum Law
1be9f1ae9d LibWeb: Move Gfx::FontVariantAlternates to CSS namespace
This is only ever used in the CSS namespace
2026-02-20 22:01:44 +00:00
Callum Law
630117e111 LibWeb: Reuse logic for parsing font-variant-alternates
This means that we only need to add support for parsing of alternates
functions in one place
2026-02-20 22:01:44 +00:00
Callum Law
1faaf83121 LibWeb: Move Gfx::FontVariantLigatures to the CSS namespace
This is only ever used in the CSS namespace and having it there allows
us to reuse existing enums
2026-02-20 22:01:44 +00:00
Callum Law
849e55b7ae LibWeb: Simplify parsing of font-variant-numeric 2026-02-20 22:01:44 +00:00
Callum Law
04fd7e00e9 LibWeb: Disallow disjointed numeric component of font-variant
The grammar groups this component together meaning that all
sub-components must occur together i.e.
`ordinal slashed-zero small-caps` is valid but
`ordinal small-caps slashed-zero` is not.

We also reuse the logic for parsing from the longhand
`font-variant-numeric` property for simplicity.
2026-02-20 22:01:44 +00:00
Callum Law
afc6b7b24c LibWeb: Move Gfx::FontVariantLigatures to the CSS namespace
This is only ever used in the CSS namespace and having it there allows
us to reuse existing enums
2026-02-20 22:01:44 +00:00