Commit Graph

1727 Commits

Author SHA1 Message Date
sideshowbarker
aa34916d45 LibWeb: Complete support for all ARIA properties in current spec
This change completes handling for all ARIA properties defined in the
current ARIA spec — by adding handling for the following properties:

- aria-braillelabel
- aria-brailleroledescription
- aria-colindextext
- aria-description
- aria-rowindextext

(cherry picked from commit ede6924db8e4440ef3bdb0fbb34d31226568e55a)
2024-11-12 07:14:25 -05:00
sideshowbarker
6598ff9926 LibWeb: Ensure spaces get added where expected within accessible names
This change implements the https://w3c.github.io/accname/#comp_append
step in the “Accessible Name and Description Computation” spec — so that
when an accessible name is computed from multiple sources in a document
subtree, the parts of the computed text are joined together with spaces.

Otherwise without this change, in accessible names computed from
multiple sources in a document subtree, the parts of the computed text
are unexpectedly run together, with no spaces between the parts.

(cherry picked from commit 3ba7c536681e8471e9b53aaf8e5dd32d801e26e4)
2024-11-12 07:14:25 -05:00
Shannon Booth
57cec9ba63 LibWeb: Avoid potential infinite recursion in Document::update_layout
(cherry picked from commit aa585c4182b8755f01118062c6ea54f5739fffcd)
2024-11-12 04:24:21 -05:00
Shannon Booth
78651dda36 LibWeb: Avoid possible infinite recursion in Document::is_fully_active
(cherry picked from commit bfc28bd62157507db711ffab7ae2683cd466da51)
2024-11-12 04:24:21 -05:00
Sam Atkins
3af997c4b2 LibWeb/DOM: Update a spec comment in Range::create_contextual_fragment()
Corresponds to https://github.com/whatwg/html/pull/10732

(cherry picked from commit 1777ddc5e2647d43e65d92da2203fb295ff7a92e)
2024-11-11 19:54:09 -05:00
Tim Ledbetter
f9158f4210 LibWeb: Fire iframe load event on document close
This matches the behavior of other browsers.

(cherry picked from commit e1eeb93cc6095a47371d23db0bbf55eb30215cee)
2024-11-11 19:54:09 -05:00
Edwin Hoksberg
94d2315a59 LibWeb: Handle Refresh header
Fixes a bunch of tests in:
- https://staging.wpt.fyi/results/html/semantics/document-metadata/the-meta-element/pragma-directives/attr-meta-http-equiv-refresh

(cherry picked from commit cbe4ba7f8c825d9732346964c8f1f1f8eec00eac)
2024-11-11 19:54:09 -05:00
Andreas Kling
3479bf0470 LibWeb: Make Document::m_intersection_observers a weak mapping
These registrations are not meant to keep the observers alive.
This fixes a handful of world leaks on Speedometer.

(cherry picked from commit b397a0d5350fad04f43e3e5d9bdb9c801a4e712a)
2024-11-11 17:22:05 -05:00
Ángel Carias
245d577235 LibWeb/DOM: Implement Node.lookupPrefix
Adds https://dom.spec.whatwg.org/#dom-node-lookupprefix

(cherry picked from commit 9624e0d2a2dc952b80e1ce1999f816f60c1ad813)
2024-11-11 15:46:34 -05:00
Shannon Booth
b901a8753d LibWeb: Allow splitting surrogate pairs in CharacterData.substringData()
(cherry picked from commit b999f925dcfb0417c534e1a21aa74626a06b466b)
2024-11-10 21:48:40 -05:00
Andreas Kling
880b6b1375 LibWeb: Stop traversal early when marking nodes for child style update
These flags always propagate to the root, so once we encounter an
ancestor with the flag set, we can stop traversal since everything above
it will already be set as well.

(cherry picked from commit f106aa9e8a8f3a98b498e0f9324123963fad6ca2)
2024-11-10 21:48:40 -05:00
Andreas Kling
c2d89a02c7 LibWeb: Check for active document in descendant_navigables()
This is not in the spec, but I did see a null pointer dereference here
while browsing the web, and it seems completely harmless for this
function to skip over navigables without an active document.

(cherry picked from commit 56e1c0e7eec813c311c41696063a3a31b4b14f0d)
2024-11-10 20:06:23 -05:00
Tim Ledbetter
fa08ac3631 LibWeb: Fire error event when script has an execution error
We now use the "report an exception" AO when a script has an execution
error. This has mostly replaced the older "report the exception" AO in
various specifications. Using this newer AO ensures that
`window.onerror` is invoked when a script has an execution error.

(cherry picked from commit 579a289d3db849657987c3310e7b1d71d290b566)
2024-11-10 10:46:01 -05:00
Daniel La Rocque
fb06647372 LibWeb: Make make_unsalvageable a public field
(cherry picked from commit 8b4dde0b0911f59512e1c40d19f33f49bdeeb10c)
2024-11-10 10:46:01 -05:00
Andreas Kling
1bf3aeaab4 LibWeb: Sync with spec in "destroy a document and its descendants"
The only real change here is that we make the document unsalvageable.
Everything else is fixing up spec comments.

(cherry picked from commit faf097bb4168208a7c0250280ff07e638be8058a)
2024-11-10 10:46:01 -05:00
Andreas Kling
88b2d705e2 LibWeb: Invalidate less style on textContent change and node removal
...unless there are :has() selectors present. Then we have to invalidate
everything for now.

(cherry picked from commit b8ce34068f5bf8ab8cf049d56b864bff52ef3dff)
2024-11-10 10:46:01 -05:00
Andreas Kling
a49ba1914a LibWeb: Distinguish parent/child on style invalidation for DOM insertion
(cherry picked from commit 7d644ecd50c57454dfb73b92e59d7112d54a1b1d)
2024-11-10 10:46:01 -05:00
Andreas Kling
66c8631bf8 LibWeb: Don't try to invalidate style for character data nodes
Character data nodes like text and HTML comments don't have style,
so let's just exit invalidation immediately for those.

(cherry picked from commit f351f75a34619ad969f660312a2e5486f742f685)
2024-11-10 10:46:01 -05:00
Andreas Kling
f23323d3d7 LibWeb: Include siblings+descendants when invalidating style
When an element is invalidated, it's possible for any subsequent sibling
or any of their descendants to also need invalidation. (Due to the CSS
sibling combinators, `+` and `~`)

For DOM node insertion/removal, we must also invalidate preceding
siblings, since they could be affected by :first-child, :last-child or
:nth-child() selectors.

This increases the amount of invalidation we do, but it's more correct.

In the future, we will implement optimizations that drastically reduce
the number of elements invalidated.

(cherry picked from commit df048e10f5a84d7fd90b1115c6bb90f45acd75ec)
2024-11-10 10:46:01 -05:00
Tim Ledbetter
5272446a09 LibWeb: Return a WindowProxy from document.defaultView
This aligns our implementation with the most recent specification steps.

(cherry picked from commit 089139f09dbc78455c5c09916cbc97e33f823ca0)
2024-11-10 10:46:01 -05:00
Andreas Kling
cfa323ed6e LibWeb: Let style elements remember which StyleSheetList they live in
Instead of trying to locate the relevant StyleSheetList on style element
removal from the DOM, we now simply keep a pointer to the list instead.

This fixes an issue where using attachShadow() on an element that had
a declarative shadow DOM would cause any style elements present to use
the wrong StyleSheetList when removing themselves from the tree.

(cherry picked from commit 8543b8ad6a4d96bd0c247052572b8c2abf3929a7)
2024-11-10 10:46:01 -05:00
Andreas Kling
38ed84421b LibWeb: Add StyleElementUtils::visit_edges()
Let's do this instead of making embedders visit every field of this
helper class.

(cherry picked from commit 2064be708f7318f72553fb210f918fe167e08257)
2024-11-10 10:46:01 -05:00
Annya
a371e02c5f LibWeb: Implement Range's extension method
This patch implements `Range::getClientRects` and
`Range::getBoundingClientRect`. Since the rects returned by invoking
getClientRects can be accessed without adding them to the Selection,
`ViewportPaintable::recompute_selection_states` has been updated to
accept a Range as a parameter, rather than acquiring it through the
Document's Selection.

With this change, the following tests now pass:

- wpt[css/cssom-view/range-bounding-client-rect-with-nested-text.html]
- wpt[css/cssom-view/DOMRectList.html]

Note: The test
"css/cssom-view/range-bounding-client-rect-with-display-contents.html"
still fails due to an issue with Element::getClientRects, which will
be addressed in a future commit.

(cherry picked from commit 75c7dbc5d2dd045733a4c319aeab6644b5b7b36d)
2024-11-10 10:46:01 -05:00
Tim Ledbetter
961272cf60 LibWeb: Don't crash when determining slot element auto directionality
(cherry picked from commit 0de314507153b6ae17d15f3b03df10a7844ed224)
2024-11-09 16:08:01 -05:00
Tim Ledbetter
5d9aac0330 LibWeb: Abort dependent signals before firing abort event
Previously, there was a bug in the specification that would cause an
assertion failure, due to the abort event being fired before all
dependent signals were aborted.

(cherry picked from commit 3ae4ea7b10e5022079d0b203844fc93899c08a09)
2024-11-09 16:08:01 -05:00
Jamie Mansfield
89d7ae75b2 LibWeb/SVG: Implement default_tab_index_value for a element
Another FIXME bites the dust :^)

(cherry picked from commit 9c4e80a3eca8329e5fd9e9fe75eac816b5666069)
2024-11-09 07:30:40 -05:00
sideshowbarker
a6017b9116 LibWeb: Make “create an event” set the event’s isTrusted to true
This change ensures that when then the code corresponding to the “create
an event” operation at https://dom.spec.whatwg.org/#concept-event-create
is called, the event’s isTrusted is set to true — as the spec requires.

That causes the failures for the following WPT tests to pass:

- https://wpt.fyi/results/html/semantics/forms/the-input-element/checkbox.html?run_id=5080423051034624
- https://wpt.fyi/results/html/semantics/interactive-elements/the-dialog-element/dialog-close.html?run_id=5080423051034624

…and there are likely a number of similar WPT tests that hit this same
code path which this commit will cause to be changed to passes.

Otherwise, without this change, the “create event” implementation
doesn’t conform to the spec requirements – nor behave interoperably with
other existing engines — and those WPT test would continue to fail.

This change also ensures that isTrusted continues to be set to false for
synthetic events.

(cherry picked from commit 1975640e31c50e9d20b0d307cbe67df4dcb8e36a)
2024-11-09 07:29:52 -05:00
Khaled Lakehal
1cd439b158 LibWeb: Set document type to HTML for text and media documents
This update fixes an issue where the document type was incorrectly set
to XML instead of HTML when initializing text and media documents.

(cherry picked from commit 2565757c7a705758bdd2ddc7ac3f7314a1773ed0)
2024-11-09 07:29:52 -05:00
Jelle Raaijmakers
eb7b733325 LibWeb: Compare start container to parent in Text.splitText()
Tiny mistake in the implementation of the spec; fixes 16 FAILs in the
WPT `/dom/ranges/Range-mutations-splitText.html` tests.

(cherry picked from commit dee81f354531c2e49be34279ca31ccc7ad9cbcca)
2024-11-09 07:29:52 -05:00
Maciej
1e3bb7dbe1 LibWeb: Make innerHTML for XML nodes actually return inner HTML
The spec says to just call the XML serialization algorithm, but it
returns the "outer serialization", and we need the "inner" one. Let's
just concatenate serializations of children; then the result produced is
similar to one from Blink or Gecko.

(cherry picked from commit 9eb568eacbcb36e6c1ffd6e61ebf8242a4422119)
2024-11-08 21:51:25 -05:00
Jamie Mansfield
df05fe55c7 LibWeb/SVG: Implement <metadata> element
(cherry picked from commit e2f599ebee67ee1bf1509685b98abcef7a5d4ca9)
2024-11-07 23:07:20 -05:00
bbb651
3e710465ca HTML: BrowsingContext: Remove m_parent and fix is_ancestor_of
`BrowsingContext::m_parent` has been removed from the spec,
and previously `m_parent` was always null.

`BrowsingContext::is_top_level` was already always returning
true before because of that, and the updated spec algorithm
causes assertions to fail.

This fixes the following example:
```html
<a href="about:blank" target="test">a
<iframe name="test">
```
clicking the link twice no longer causes it to open in a new tab.

(cherry picked from commit e6a668ad913f0755840954c188c255fc5fc66606)
2024-11-07 22:42:20 -05:00
Sam Atkins
32406976d7 LibWeb: Ensure Elements don't need style update after computing style
Previously, we set the "needs style update" flag to false at the
beginning of recomputing the style. This meant that if any code within
the cascade set this flag to true, then we would end style computation
thinking the element still needed its style updating. This could occur
when starting a transition, and would make TreeBuilder crash.

By ensuring that we always set the flag to false at the very end of
style computation, this is avoided, along with any similar issues - I
noticed a comment in `Animation::cancel()` which sounds like a
workaround was needed for a similar problem previously.

(cherry picked from commit 8c79edac085ee164aca5ca7cf287e68e93e03217)
2024-11-04 19:29:49 -05:00
Andreas Kling
da526bac92 LibWeb: Don't invalidate layout tree on all DOM node removals
DOM nodes that didn't have a layout node before being removed from the
DOM are not going to change the shape of the layout tree after being
removed.

Observing this, we can avoid a full layout tree rebuild on some DOM node
removals.

This avoids a bunch of tree building work when loading https://x.com/

(cherry picked from commit 6f34758947852abae773798ba3ffa8e903fdc3d0)
2024-11-04 13:17:01 -05:00
Andreas Kling
5c4c048195 LibWeb: Rename invalidate_layout() => invalidate_layout_tree()
I believe this is slightly less confusing, since what the function does
is trigger a full layout tree *rebuild*, not just a relayout.

(cherry picked from commit aa8f17aea4d1aa1950a66969fc8b5c431fbc1b7c)
2024-11-04 13:17:01 -05:00
Andreas Kling
2be65856ae LibWeb: Don't crash on getClientRects() in document without navigable
I previously believed there was no way a detached document should have
layout information, but it turns out there is a way: getComputedStyle().

So we need to account for cases where we have a layout node, but no
navigable, since that is a state we can get into at this moment.

Fixes #354

(cherry picked from commit 1e7b17f15024d0618f1a1e17e3e927856febde28)
2024-11-02 06:45:28 -04:00
Tim Ledbetter
716bf5cb7a LibWeb: Elide boundary checks when constructing find in page ranges
Previously, unnecessary boundary checks were being done when
constructing the range objects used to represent find in page matches.
These checks are no longer performed leading to a significant speedup
when performing find in page queries on pages containing a lot of text.

(cherry picked from commit e76ad9492e0992f9a6d821240bea2b62f27a03c8)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
7d472b5bc7 LibWeb: Cache text blocks used by find in page
The first step of the find in page algorithm is to walk the layout tree
of each document on the page and construct a list of strings against
which to search for matches.

Previously, this was being done for each new query, even when the
page content hadn't been updated. The output of this process is now
cached in the viewport node of the associated document. This ensures
that this process is no longer repeated unnceessarily.

(cherry picked from commit 156c1083e9de23a93075ec9e3c55cd5f93c48896)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
b9fb8c7972 LibWeb: Ensure layout is up to date before performing find in page query
(cherry picked from commit fee7b4147c97e5c775e17fac30667d02bf01c3c4)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
5a5eda3356 LibWeb: Don't search non-visible text for find in page results
Elements which are `display: none` or `visibility: hidden` are no
longer included in find in page results.

(cherry picked from commit a3a7a65b1c89af5631436c06d2847fe7ad5c51cb)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
6a3170fa09 LibWeb: Don't match text across block elements for find in page queries
Find in page will no longer match text that spans across block elements.
Previously, given the markup `WH<div>F</div>`, the query `WHF` would
find a match. We would now match `WH` and `F` separately, but not `WHF`.

(cherry picked from commit 23166b85d2443cccbdd8fcb1e9d99c9f3f9d04a3)
2024-11-01 09:38:01 -04:00
Tim Ledbetter
7c5f5e62f2 LibWeb: Support finding text split across multiple text nodes
Previously, the find in page function would fail to find text which was
split across multiple text nodes. For example, given the following
markup: `WH<span>F` the query `WHF` would previously fail to be
matched.

This is done by traversing all of the document's text nodes -
constructing a complete string to query against and keeping track of
the locations where that string is split across multiple nodes.

(cherry picked from commit ec4d29849dc1d0357c73690722aea1a7802dd0bc)
2024-11-01 05:15:17 -04:00
Tim Ledbetter
6bd6ab67dc LibWeb: Ensure a repaint occurs when the current selection is cleared
This fixes an issue where clearing the find in page query would not
always visually clear the selection.

(cherry picked from commit 0b33331f3678eb69bc3448949dfc2c1e1e7671e6)
2024-10-31 22:47:20 -04:00
Andreas Kling
b8037403d2 LibWeb: Cache the Document's node navigable when possible
To avoid expensive lookups, we now cache a weak pointer from document to
the last known node navigable. Before using the cache, we validate that
the document is still the navigable's active document.

(cherry picked from commit e746b2b133758b3552ae07941cc6d14332c64d59)
2024-10-31 20:24:54 -04:00
Tim Ledbetter
3a74d614db LibWeb: Ensure ParentNode.getElementsByClassName() matches all classes
(cherry picked from commit 96c0cbf584e99d5c1c9b894d0317d8c2887ade83)
2024-10-31 19:58:12 -04:00
Tim Ledbetter
5dc046bb7a LibWeb/SVG: Implement SVGImageElement
This element allows images to be embedded within SVGs.

(cherry picked from commit 03bbc2b111b211f472bfbc0f04c10f03e28dbbdf)
2024-10-21 12:01:12 -04:00
Andreas Kling
f8fb05ec8b LibWeb: Only invalidate style & DOM version if attribute really changes
When setting an element attribute to the value it already had, we don't
need to update style or invalidate anything that depends on the DOM
version counter.

This was a source of much pointless busywork.

(cherry picked from commit 7df4365e405410bff267644e0a5c1d7b3d76faac)
2024-10-20 01:32:53 -04:00
Andreas Kling
1b73445f55 LibWeb: Note what's causing a style invalidation to happen
You can now build with STYLE_INVALIDATION_DEBUG and get a debug stream
of reasons why style invalidations are happening and where.

I've rewritten this code many times, so instead of throwing it away once
again, I figured we should at least have it behind a flag.

(cherry picked from commit ddbfac38b0074819470766846fca08fd78630eb0;
minorly amended for conflicts in AK/Debug.h.in and
Meta/CMake/all_the_debug_macros.cmake due to us having more debug
macros. Also, downstream got alphabetical order for
STYLE_INVALIDATION_DEBUG wrong.)
2024-10-20 01:32:53 -04:00
Timothy Flynn
c62dd41874 LibWeb: Move the navigable's cursor position to be owned by the document
Navigables are re-used for navigations within the same tab. Its current
ownership of the cursor position is a bit ad-hoc, so nothing in the spec
indicates when to reset the cursor, nor do we manually do so. So when a
cursor update happens on one page, that cursor is retained on the next
page.

Instead, let's have the document own the cursor. Each navigation results
in a new document, thus we don't need to worry about resetting cursors.

This also makes many of the callsites feel nicer. We were previously
often going from the node, to the document, to the navigable, to the
cursor. This patch removes the navigable hop.

(cherry picked from commit faebbbc281d1267062770b02fc6d962d92a3bd62)
2024-10-18 21:58:17 -04:00
Timothy Flynn
cb17194de8 LibWeb: Avoid allocating UTF-16 strings only the UTF-16 length is needed
(cherry picked from commit 4a166a45ec9db910542893133f08cc7de4ec974f,
minorly amended to resolve #include conflict due to our LibLocale
and LibUnicode being separate -- we don't want
https://github.com/LadybirdBrowser/ladybird/pull/257)
2024-10-18 18:21:18 -04:00