Commit Graph

6708 Commits

Author SHA1 Message Date
Aliaksandr Kalenik
5be98aaa07 LibWeb: Add internals.dumpLayoutTree(node) API
This new testing API dumps the layout subtree rooted at a given DOM
node. It will be useful for testing partial layout tree rebuilds, where
we need to verify the layout tree structure for specific subtrees rather
than the entire document.
2026-02-09 21:05:45 +01:00
Aliaksandr Kalenik
aa24da8a93 LibWeb: Only invalidate layout on SVG viewBox/preserveAspectRatio change
These attributes are consumed during layout in SVGFormattingContext to
compute the viewbox transform. They don't affect the layout tree
structure, so a layout-only invalidation is sufficient instead of a
full layout tree rebuild.
2026-02-09 19:49:10 +01:00
Aliaksandr Kalenik
ed0ce5c17f LibWeb: Unify three layout tree traversals into one in update_layout()
Merge the three consecutive for_each_in_inclusive_subtree traversals
into a single preorder walk. All three operations only depend on
ancestor state which is satisfied before descendants are visited in
preorder traversal.
2026-02-09 19:00:04 +01:00
Tim Ledbetter
4a57fc72cf LibWeb: Omit "row" when serializing grid-auto-flow as "dense" 2026-02-09 17:36:12 +01:00
Tim Ledbetter
f6ad878ea3 LibWeb: Allow interleaving of grid-template line names and track values 2026-02-09 17:36:12 +01:00
Tim Ledbetter
400a1332a6 LibWeb: Correctly parse the grid shorthand property 2026-02-09 17:36:12 +01:00
Tim Ledbetter
e863a04b12 LibWeb: Include grid-auto-* longhands in grid shorthand parsing 2026-02-09 17:36:12 +01:00
Andreas Kling
4fa4ecf31b LibJS: Inline ExecutionContextRareData fields into ExecutionContext
After removing the unwind context stack, ExecutionContextRareData only
held two GC::Ptr fields — both trivially destructible. The indirection
cost more than it saved: a GC cell allocation per EC, an extra pointer
chase on every source range lookup, and unnecessary complexity.

Replace the rare data cell with two inline fields on ExecutionContext:
cached_source_range and context_owner.
2026-02-09 16:35:39 +01:00
Aliaksandr Kalenik
abecc746d7 LibWeb: Implement partial SVG relayout
Previously, any SVG geometry attribute change would mark the entire
document layout tree as dirty, triggering a full layout pass even though
only the SVG subtree was affected. This made SVG geometry animations
unnecessarily expensive.

Fix this by stopping `needs_layout_update` propagation at the SVGSVGBox
boundary and tracking dirty SVG roots separately on the Document. When
`update_layout()` finds that only SVG roots need relayout (and the
document layout root is clean), it runs SVGFormattingContext on each
dirty SVG root in a fresh LayoutState and commits the results directly,
bypassing the full document layout pass entirely.

This results in a substantial performance improvement on pages with
animated SVGs, such as https://www.cloudflare.com/,
https://www.duolingo.com/, and our GC graph explorer page.
2026-02-09 03:02:49 +01:00
Aliaksandr Kalenik
f051bc45fc LibWeb: Scope DOM paintable clearing in commit() to the layout subtree
Instead of walking the entire DOM document to clear paintable refs and
collect inline nodes, walk the layout subtree rooted at the commit root.

This removes an assumption that commit() is always called with the
layout tree root and serves as preparatory refactoring for partial SVG
layout.
2026-02-09 03:02:49 +01:00
Timothy Flynn
9f436356d0 LibWeb: Interpret cookie headers as UTF-8
The cookie RFC strongly suggests that cookies only contain ASCII, and
that non-ASCII values be encoded with e.g. base64. Web reality differs,
however, and browsers are expected to support UTF-8 encoded cookies.
This aligns with document.cookie.

This fixes the following WPT tests:

    /cookies/encoding/charset.html
    /cookiestore/encoding.https.any.html

No test added here because we don't have a mechanism yet to set an
HTTP cookie and inspect it via our file:// URL test infra.
2026-02-08 23:14:31 +01:00
Timothy Flynn
0571e578d6 LibWeb: Reject cookies with non-ASCII domains
This is an alternate fix for the issue addressed by commit
8156531477.

Turns out we don't want to isomorphic decode the cookie header, but
decode it as UTF-8 to align with document.cookie. That will be
addressed in a subsequent commit.
2026-02-08 23:14:31 +01:00
Timothy Flynn
4a8ef68b90 LibWeb: Protect against null navigables in lineage chain more thoroughly
This extends the null navigable check added in commit
b118c99c27 to include all ancestor and
descendant list lookups. Fixes a crash in the following WPT test:

/cookies/schemeful-same-site/schemeful-navigation.tentative.html
2026-02-08 14:51:25 -05:00
Timothy Flynn
5cff8db44c LibWeb: Invoke Document::navigable() fewer times in a row
This is not necessarily a cheap accessor.
2026-02-08 14:51:25 -05:00
Aliaksandr Kalenik
1f0f427a3c LibWeb: Remove Document.h include from XMLDocumentBuilder.h
...and SVGDecodedImageData.h

These headers only use Document via forward-declarable references and
smart pointers. Add explicit Document.h includes to .cpp files that
were relying on the transitive include.
2026-02-08 18:51:13 +01:00
Aliaksandr Kalenik
2452680615 LibWeb: Remove Document.h include from DOMParser.h, DOMImplementation.h
...and WorkerEnvironmentSettingsObject.h

These headers only use Document via forward-declarable references and
smart pointers, so the full include is unnecessary.
2026-02-08 18:51:13 +01:00
Aliaksandr Kalenik
9140348cbd LibWeb: Remove unused Document.h includes from SerializeBitmap.h
...and XMLFragmentParser.h

Neither header uses anything from Document.h directly.
2026-02-08 18:51:13 +01:00
Aliaksandr Kalenik
b41ed92505 LibWeb: Remove Document.h include from Layout/Viewport.h
Move the inline dom_node() method to Viewport.cpp so the header no
longer needs the full Document definition. Add explicit includes to
files that relied on the transitive dependency.
2026-02-08 18:51:13 +01:00
Aliaksandr Kalenik
edf42ec9f9 LibWeb: Remove Document.h include from SVGElement.h
This reduces the recompilation cascade when Document.h is modified,
cutting off the transitive path through ~30 SVG element headers.

Move the inline try_resolve_url_to() template body in
SVGGraphicsElement.h to a non-template helper in the .cpp file to
avoid needing Document.h and ShadowRoot.h in the header.

Add explicit includes to files that relied on the transitive dependency.
2026-02-08 18:51:13 +01:00
Aliaksandr Kalenik
e76cf3e225 LibWeb: Remove Document.h include from Layout/Node.h
This reduces the recompilation cascade when Document.h is modified.
Add explicit includes to files that relied on the transitive dependency.
2026-02-08 18:51:13 +01:00
Psychpsyo
63aeaa81e5 LibWeb: Flatten non-3d transforms 2026-02-07 18:56:23 +01:00
Aliaksandr Kalenik
c62996abd7 LibWeb: Avoid dynamic_cast in SlottableMixin::assigned_slot()
`SlottableMixin::assigned_slot()` was using `as<DOM::Node>(*this)` to
get a `Node` reference. Since `SlottableMixin` has no inheritance
relationship with `Node`, `as_if<>` can't use `static_cast` and falls
through to `dynamic_cast`, which is expensive. Replace this with a
virtual `slottable_as_node()` accessor overridden in `Element` and
`Text`.

This showed up as hot in profiles when loading the GC heap explorer
page.
2026-02-07 16:43:50 +01:00
Aliaksandr Kalenik
488123c75b LibWeb: Don't rebuild layout tree on SVG transform change
The SVG `transform` attribute is stored on the DOM element and read
directly during layout by
`SVGFormattingContext::layout_graphics_element()`. Since changing the
transform doesn't affect which DOM nodes produce layout boxes or how
they're structured, we only need to re-run layout on the existing tree
instead of rebuild it from scratch.
2026-02-07 15:47:17 +01:00
Psychpsyo
8ede5010fa LibWeb: Move some collapsing margin handling to more sensible places 2026-02-07 12:21:16 +01:00
Psychpsyo
12862bea93 LibWeb: Unregister block container y-position update callback 2026-02-07 12:21:16 +01:00
Jelle Raaijmakers
2a2f8ef90b LibWeb+UI: Support triple clicking and dragging paragraphs
When triple clicking on text, we should select the entire paragraph, or
entire line in <input>s and <textarea>s. If the mouse button is held
down and the user starts dragging, the selection expands with additional
paragraphs or lines.

This expands on the work of Kai Wildberger (PR #7681) but was adjusted
for the work that happened previously to support double click + drag
moves and includes triple click support for our Qt UI.

Co-authored-by: Kai Wildberger <kiawildberger@gmail.com>
2026-02-06 14:18:10 +00:00
Jelle Raaijmakers
14b35887de LibWeb: Expose GraphemeEdgeTracker's find_line_start/find_line_end 2026-02-06 14:18:10 +00:00
Jelle Raaijmakers
7f8d052b7e LibWeb: Support double click word selection dragging
In EventHandler, we now keep track of a mouse selection mode which is
either None, Character or Word. By double clicking a word and
immediately dragging, you can now extend the selection word by word
instead of by character.
2026-02-06 14:18:10 +00:00
Jelle Raaijmakers
f55fe69d4d LibWeb: Rework Internals' mouse control
Instead of defining somewhat high level mouse actions, allow granular
control of mouse clicks and mouse down/up/move events. We will want to
simulate things like holding down a mouse button after double clicking
and then dragging the mouse to another position in the future, and this
enables that.
2026-02-06 14:18:10 +00:00
Sam Atkins
108ef5e088 LibWeb/HTML: Actually use charset encoding for linked style sheets
This code that used `charset` created a second `environment_encoding`
variable which shadowed the outer one, making it a no-op. Now we
actually use its value.
2026-02-06 15:04:44 +01:00
Andreas Kling
2cafa154f6 LibWeb: Mark CSSRule::dump() as MUST_UPCALL 2026-02-06 13:50:54 +01:00
Andreas Kling
5b26777904 LibWeb: Don't WEB_SET_PROTOTYPE_FOR_INTERFACE for ShadowRealm global
We weren't doing this before either, but through a slightly sneaky
mechanism: we had overridden Cell::initialize() in
ShadowRealmGlobalScope as a no-op.

Instead of that, do the same thing Window and Worker globals do and
make all of the globals that inherit UniversalGlobalScopeMixin opt
out of WEB_SET_PROTOTYPE_FOR_INTERFACE in EventTarget::initialize().
2026-02-06 13:50:54 +01:00
Andreas Kling
68946b198f LibWeb: Mark CSSRule::clear_caches() as MUST_UPCALL
The base implementation clears the cached layer name. Derived classes
must call it to avoid stale cache values.
2026-02-06 13:50:54 +01:00
Andreas Kling
3110622b04 LibWeb: Mark Paintable::resolve_paint_properties() as MUST_UPCALL
The base implementation computes hit-testing visibility, including
handling inert subtrees. Derived classes must call it.
2026-02-06 13:50:54 +01:00
Andreas Kling
d45bda7b79 LibWeb: Mark Node::inserted() and Node::removed_from() as MUST_UPCALL
Node::inserted() sets needs_style_update, and Node::removed_from()
clears the layout node and paintable pointers. Forgetting to call
either base implementation from a derived class would be a bug.
2026-02-06 13:50:54 +01:00
Andreas Kling
8d2081d3ff LibWeb: Mark Element::attribute_changed() as MUST_UPCALL
The base implementation handles critical bookkeeping like element
ID/name registration and slot assignment. Forgetting to call it
from a derived class would be a correctness bug.
2026-02-06 13:50:54 +01:00
Andreas Kling
706eb0018c LibGC+LibWeb: Mark two GC::Cell functions as MUST_UPCALL
Let's make sure that subclasses always call their base class when
overriding these virtuals:

- void finalize()
- void visit_edges(Visitor&)
2026-02-06 13:50:54 +01:00
Adam Colvin
2df5a7bb31 LibJS: Add source locations to console.trace()
LibJS+DevTools: Implement console.trace() with source locations

- Add Console::TraceFrame struct with source location data
- Implement Console::trace() to gather stack information
- Add WebView::StackFrame and ConsoleTrace for IPC
- Implement DevToolsConsoleClient::printer() for traces
- Update FrameActor to format traces for DevTools
- Update WorkerDebugConsoleClient trace handling
- Update ReplConsoleClient to format trace output
2026-02-06 11:58:07 +00:00
Tim Ledbetter
0b346d1952 LibWeb: Distribute colspan cell width equally when baseline is zero
This matches the behavior of other engines.
2026-02-06 11:37:14 +00:00
Psychpsyo
864018b3dc LibWeb: Don't lie about browsing context being top-level
The VERIFY() this was triggering wasn't actually to spec, and by the
time it gets encountered, the browsing context isn't technically a top-
level context yet, because it has just been created and the definition
of a top-level browsing context requires the document to be the
navigables active document, which it only becomes once a history entry
has been created for it.

Therefore we cannot just verify a top-level browsing context actually
being a top-level browsing context when inserting it into the group,
because that happens to early in its life-cycle as a top-level context.

This makes it so that JS console commands from the devtools no longer
get sent to the last created nested frame in the tab, because nested
frames no longer pretend to have a top-level browsing context.
2026-02-06 10:52:31 +00:00
Jelle Raaijmakers
856091fb56 LibWeb: Implement support for text-decoration in ::selection 2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
48aa199f09 LibWeb: Implement support for text-shadow in ::selection 2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
98b4feb406 LibWeb: Apply CSS ::selection styling to text and form controls
Previously, text selection always used the system highlight color. This
implements support for the ::selection pseudo-element's background-color
and color properties.

For form controls like <input> and <textarea>, the selection style is
looked up on the shadow host element, since the actual text lives inside
their shadow DOM.

The text painting logic has been refactored to split fragments into
styled spans (before selection, selected, after selection) so that each
portion can be rendered with its appropriate colors, taking care not to
allocate in 99%+ of fragment rendering cases.
2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
1dd5409630 LibWeb: Add helpers to convert CSS::ShadowData to Painting::ShadowData 2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
726fe8284c LibWeb: Check if author rule layers are non-empty for pseudo-elements
The author_rules vector always contains at least one layer (the
unlayered entry), so checking is_empty() was always false. Instead,
check whether any layer actually contains rules.
2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
ab82b0147d LibWeb: Compute styles for pseudo-elements with implicit UA styles
Some pseudo-elements have implicit UA styles that need to be computed
even when no CSS rules matched.
2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
7714471aae LibWeb: Recompute style for ::selection pseudo element 2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
b048dbd23a LibWeb: Apply selection highlight to selected images 2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
3d777a8d04 LibWeb: Simplify PaintableFragment::range_rect()
Some of the logic in ::range_rect() was duplicated, and we did not
optimally utilize the early returns. Rearrange the code so we do the
expensive font metrics stuff as late as possible.
2026-02-06 10:47:50 +00:00
Jelle Raaijmakers
69fa144539 LibWeb: Keep track of trailing whitespace for wrapped lines
When rendering selections, we want to extend the selection rect for
wrapped lines to show that there is whitespace present. We don't
actually store this whitespace in the fragments; it's purely a visual
clue.

This reflects how both Chrome and Firefox deal with selection ranges
over wrapped lines.
2026-02-06 10:47:50 +00:00