Commit Graph

7081 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
Shannon Booth
8d099b9cec LibWeb: Add non const global object getter to EnvironmentSettingsObject
And sneak in a as_if tidyup too.
2026-02-26 07:22:50 +01:00
Shannon Booth
9e7aa878bc LibWeb: Properly determine if running in SecureContext for Workers
Fixes the included imported test. Note that this required a minor
edit of the WPT import to work with our test harness setup to
try and create a non secure context setup as both file:// and
localhost are considered secure contexts.
2026-02-26 07:22:50 +01:00
Shannon Booth
457b83313e LibWeb/HTML: Add representation to WorkerGlobalScope to track owner set
Note that this is done using the serialized versions of these objects
as this is always used across different processes and the javascript
realm should never be relevant for owner set.
2026-02-26 07:22:50 +01:00
Shannon Booth
025ddd385b LibWeb/HTML: Track secure context as part of Serialized{Document,Worker}
This is somewhat awkward as the spec refers to 'is secure context'
with respect to these objects 'relevant settings object'. A natural
way of implementing this could be storing a pointer to the relevant
settings object like the JS representations of these objects do
(and then changing is_secure_context to accept this representation
too), but for now it seems much simpler to just store a boolean for
this purpose and sidestep both problems above.
2026-02-26 07:22:50 +01:00
Tim Ledbetter
245eb7d91d LibWeb: Use margin box for vertical overlap checks in float placement
Previously, a float with `padding-top` would overlap a preceding float
instead of being placed beside it. The vertical overlap check was
comparing the new float's content box Y,which includes the padding
offset, against preceding floats' margin box rects, causing the check
to incorrectly conclude the floats do not overlap.
2026-02-25 12:03:31 +01:00
Andreas Kling
7b0d818f8e LibWeb: Update layout before accessing paintables in viewport scroll
perform_a_scroll_of_the_viewport() accesses paintable_box() without
ensuring layout is up to date. This can lead to a null dereference
if the paintable tree was torn down (e.g. by adding a dialog to the top
layer via showModal()) between the last layout update and the scroll.

One concrete path: Window::scroll() has an optimization that skips
update_layout when scrolling to (0, 0), but still calls
perform_a_scroll_of_the_viewport if the viewport is at a non-zero
position.

Fix by adding an update_layout call at the top of
perform_a_scroll_of_the_viewport.
2026-02-25 10:18:08 +01:00
Aliaksandr Kalenik
9231b54d49 LibWeb: Pre-populate viewport in SVG subtree relayout
During SVG subtree relayout, position:fixed elements inside
<foreignObject> use the viewport as their containing block. Since the
viewport is outside the SVG subtree, it was not pre-populated in the
LayoutState, causing a VERIFY failure in ensure_used_values_for().

Fix this by unconditionally pre-populating the viewport node from its
paintable in relayout_svg_root().
2026-02-25 09:05:10 +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
Andreas Kling
73b0ecd89d LibWeb: Use GC::WeakHashSet for AnimationTimeline associated animations
Replace the unsafe HashTable<GC::Weak<Animation>> with
GC::WeakHashSet<Animation>, and update all callers to use reference
syntax instead of pointer syntax since the iterator now yields T&.
2026-02-24 22:35:03 +01:00
Zaggy1024
e195d4e33e LibWeb: Move canvas and media element iteration methods out of line
This reduces the number of rebuilt files when modifying
HTMLMediaElement.h and HTMLCanvasElement.h significantly.
2026-02-24 21:09:27 +01:00
Zaggy1024
2e4ef086f3 LibWeb: Include Requests.h in SharedResourceRequest.cpp
This is only transitively included through Page.h ->
HTMLMediaElement.h.
2026-02-24 21:09:27 +01:00
Luke Wilde
21713377e2 LibWeb: Paint SVG-in-img with a nested display list
This makes SVG-in-img appear sharp no matter the current
(pinch-to-)zoom level.
2026-02-24 19:13:23 +01:00
Aliaksandr Kalenik
abb392bd65 LibWeb: Remove redundant flush() in DisplayListPlayer::execute_impl()
The flush() call at the end of execute_impl() was accidentally left
behind in 2d2af9cd3b. That commit moved flushing into execute(), but
didn't remove the old call from execute_impl(). This caused every
nested display list to trigger a redundant GPU flush.

On an M4 MacBook, this improves Discord from ~65 FPS to 120 FPS.
2026-02-24 18:50:02 +01:00
Tim Ledbetter
84043cd82d LibWeb: Track deleted state on IndexedDb Index and ObjectStore
An `InvalidStateError` is now thrown when an attempt is made to
interact with an index or object store that has been deleted.
2026-02-24 17:37:04 +01:00
Luke Wilde
f06732d180 LibWeb: Mark CacheStorage as Experimental
CacheStorage is currently a stub that breaks anything that uses it.
2026-02-24 17:08:48 +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
bca6f3e4b5 LibWeb/DOM: Always give Document a FontFaceSet
In practice, the event loop queries Document::fonts(), so we don't gain
anything by delaying the allocation, apart from making it unclear when
it happens.
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
Aliaksandr Kalenik
efbefb3b59 LibWeb: Skip display list commands under zero-area clips
Add a pre-computed `has_empty_effective_clip` flag on
AccumulatedVisualContext that propagates from parent to child. When a
clip rect or clip path has zero area, all descendant commands are
skipped at display list recording time in `DisplayList::append()`,
so they are never stored or executed.

This allows skipping ~10% of display list commands in the Discord app.
2026-02-24 16:41:20 +01:00
Tim Ledbetter
91b7525e18 LibWeb: Ensure favicon URL is valid before fetching it
Previously, we would crash when attempting to fetch the favicon if
the `<base>` element had an invalid URL.
2026-02-24 15:05:31 +01:00
Aliaksandr Kalenik
1fc4c69ad8 LibWeb: Expand PaintNestedDisplayList in internals.dumpDisplayList()
Previously, PaintNestedDisplayList was treated as an opaque command,
printing only its name and rect without showing the nested display
list's contents. This made it impossible to debug painting issues
involving SVG masks/clips, CSS background-clip: text, and iframe
content through display list dumps.

Refactor the command dump loop into a recursive lambda that expands
nested display lists inline with increased indentation.
2026-02-24 14:37:29 +01: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
Aliaksandr Kalenik
d7a8db671b LibWeb: Skip overflow clip generation for SVG inner elements
Per the CSS Overflow spec, overflow properties apply only to block
containers, flex containers, and grid containers — not SVG graphics
elements. Add an `is<SVGPaintable>` check in
`overflow_property_applies()` to return false for SVG inner elements
like `<g>`, `<rect>`, `<path>`.

This doesn't affect `<svg>` elements (which use `SVGSVGPaintable`, a
direct `PaintableBox` subclass) or `<foreignObject>` (which uses
`SVGForeignObjectPaintable`, a `PaintableWithLines` subclass) — both
correctly keep their overflow clips.
2026-02-24 12:28:55 +01:00
Tim Ledbetter
6b3d3468a1 LibWeb: Account for <col> span attribute during table grid formation
Previously, the column count was always incremented by 1. This led to a
mismatch with `compute_outer_content_sizes()`, which did use the `span`
attribute to advance the column index. This mismatch caused an
out-of-bounds access when the column index was greater than the
expected number of columns.
2026-02-24 12:14:54 +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
Aliaksandr Kalenik
37ec6a08a8 LibWeb: Rename is_clip_or_mask to is_clip
The mask case was removed when AddMask was replaced with saveLayer+DstIn
compositing, so this flag now only applies to clip commands.
2026-02-24 07:14:16 +01:00
Aliaksandr Kalenik
2d2af9cd3b LibWeb: Replace m_surfaces stack with m_surface in DisplayListPlayer
After removing the AddMask display list command, no code path ever
pushes more than one surface onto the stack.
2026-02-24 07:14:16 +01:00
Aliaksandr Kalenik
0ac72e40d4 LibWeb: Remove the unused AddMask display list command
All mask call sites now use saveLayer+DstIn compositing, so the AddMask
command, its SkSL runtime shaders, and CachedRuntimeEffects are no
longer needed.
2026-02-24 07:14:16 +01:00
Aliaksandr Kalenik
5ef132ba1a LibWeb: Replace AddMask/clipShader with saveLayer+DstIn compositing
This applies the same pattern used for background-clip: text (commit
f2e6f70fbb).

Results in visible performance improvement in Discord app where
previously, according to profiles, we spent lots of time allocating
surfaces for masks.
2026-02-24 07:14:16 +01:00
Aliaksandr Kalenik
533228f8ad LibWeb: Invalidate stacking context tree after partial SVG relayout
relayout_svg_root() clears individual stacking contexts via
reset_for_relayout() but didn't call invalidate_stacking_context_tree().
The viewport's stacking context remained non-null, so
build_stacking_context_tree_if_needed() skipped the rebuild. This caused
foreignObject to lose its stacking context after relayout, breaking SVG
mask application.
2026-02-24 06:15:07 +01:00
Luke Wilde
0bdc5e52ba LibWeb: Allow document element to be in the top layer
This seems to be an old ad-hoc fix, removing it doesn't make the test
introduced with the commit crash.

Allows YouTube to enter fullscreen.
2026-02-23 18:44:26 +00:00
Simon Farre
4396e5b8d0 LibWeb: Unfullscreen when removing an element or unloading a document 2026-02-23 18:44:26 +00:00
Simon Farre
5613760e06 LibWeb: Allow close requests to exit fullscreen 2026-02-23 18:44:26 +00:00
Simon Farre
04d1e2bf3d LibWeb: Implement exitFullscreen algorithm
Exiting fullscreen from the UI will be added in future commits.
2026-02-23 18:44:26 +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
44e0735d9b LibWebView+UI/Qt: Allow WebContent to enter/exit the fullscreen UI
These IPC methods should be expanded in the future to allow WebContent
to specify what UI elements should be kept/removed, for example, the
navigation UI.
2026-02-23 18:44:26 +00:00
Simon Farre
db076bab92 LibWeb: Add Fullscreen event handlers to Document and Element
This also adds a stub to the Permissions Policy checks.
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
Simon Farre
f5ac0ccf6c LibWeb: Add 'Run the fullscreen steps'
Future commits will populate the pending list with events.
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
Tim Ledbetter
73d948a028 LibWeb: Pre-allocate visual context chain vectors for hit testing
Also use inline storage for typical hit testing depths.
2026-02-23 17:30:25 +01:00