Commit Graph

1749 Commits

Author SHA1 Message Date
Timothy Flynn
fb4e032c8f LibWeb: Update spec steps for destroying a DOM document
This just updates our copied spec steps - new steps are not implemented
here. This is mostly just to highlight new steps we are missing around
MessagePorts.

No behavior change, but this does resolve an outstanding FIXME around
spec step ordering.

(cherry picked from commit 83be2606dba7ac430bab4d61a70e926d12d452ee)
2024-11-21 09:41:42 -05:00
Julius Elshoff
15e1590def LibWeb: Rename 'cross-origin opener policy' to 'opener policy'
(cherry picked from commit de31ea5852e3fc0aca1e86e06c6bc019f27824de)
2024-11-21 07:32:56 -05:00
Luke Wilde
27c1ce5299 LibWeb: Make default document readiness be "complete"
This is required by mini Cloudflare invisible challenges, as it will
only run if the readyState is not "loading". If it is "loading", then
it waits for readystatechange to check that it's not "loading" anymore.

Initial about:blank iframes do not go through the full navigation and
thus don't go through HTMLParser::the_end, which sets the ready state
to something other than "loading". Therefore, the challenge would never
run, as readyState would never change.

Seen on https://discord.com/login

(cherry picked from commit f638f84185938c74a47f5691e8d7c5e1d4dca07c)
2024-11-20 22:51:34 -05:00
Andreas Kling
e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
2024-11-18 20:22:45 -05:00
Andrew Kaster
38f93f5e18 LibWeb: Remove uses of obsolete PlatformObject::global_object()
This API is a relic from the time when it was important for objects to
have easy access to the Window, and to know it was the global object.

We now have more spec-related concepts like relevant_global_object and
current_global_object to pull the Window out of thin air.

(cherry picked from commit 02a56f648000517f191eeaea2abc68783c097486)
2024-11-16 14:12:55 -05:00
Sam Atkins
d6c79e8349 LibWeb: Add Document::get_style_sheet_source()
This returns the source text of the specified style sheet. StyleComputer
now exposes user agent style sheets so that these can also be requested.

(cherry picked from commit 49b2eb5f51be2ddfd2c6009e7d8064b58d665af3)
2024-11-15 23:10:03 -05:00
Sam Atkins
6046f9d61f LibWeb: Add method for listing all style sheets on a page
This will be used by the inspector, for showing style sheet contents.

Identifying a specific style sheet is a bit tricky. Depending on where
it came from, a style sheet may have a URL, it might be associated with
a DOM element, both, or neither. This varied information is wrapped in
a new StyleSheetIdentifier struct.

(cherry picked from commit 51a426cc0562d12a6e8f7d1d1a38f9ecac77072a)
2024-11-15 23:10:03 -05:00
Sam Atkins
23959eeb6f LibWeb: Rename Document::for_each_css_style_sheet for clarity
This only iterates style sheets that are in use, so make this clear by
renaming it to `for_each_active_css_style_sheet()`.

(cherry picked from commit c29f4f69ef9a16bd63a4bf133618120068e96bf3)
2024-11-15 23:10:03 -05:00
Asutosh Variar
50cc1b5d63 Everywhere: Convert from_string_view -> from_string_literal where static
(cherry picked from commit 229b64a4b723a391c21f247d72d78cd575ace6ff;
minorly amended to fix conflict in image.cpp due to serenity in the
meantime adding webp writing support, and due to changes in Android and
Vulkan-related files that serenity doesn't have)
2024-11-15 08:56:39 -05:00
Gingeh
af93b65e26 LibWeb: Use Content-Type header to set document encoding
Co-authored-by: Shannon Booth <shannon@serenityos.org>
(cherry picked from commit 8e342e3e23f5c0d7e6df5b1bcc3cc4db31a9de2b)
2024-11-14 22:21:55 -05:00
0x4261756D
fcfe89e21d HTMLEncodingDetection: Use mime type in encoding sniffing
Also added proper spec comments.
Fixes at least one WPT test that was failing previously:
https://wpt.live/encoding/single-byte-decoder.window.html?document

(cherry picked from commit c1a14f66adf4b5e55a0e2a78068749e7d8b3ed98)
2024-11-14 21:38:52 -05:00
Shannon Booth
8e6d036dc5 LibWeb: Factor out AO for 'try to scroll to the fragment'
I had made a stab at implementing this to determine whether it could
assist in fixing an issue where scroll_to_the_fragment was not getting
called at the appropriate time. It did not fix that issue, and actually
ended up breaking one of our in tree tests. In the meantime, factor out
this method into a standalone function.

(cherry picked from commit 41f574155df89bb5122646a0978fa8821c35fc16)
2024-11-14 17:46:06 -05:00
Jelle Raaijmakers
f36546d591 LibWeb: Update DOM IDL specs
I noticed some of these were running behind the upstream spec.

(cherry picked from commit d5fd29adb79641830835e2efd9541de08d0ad6fc)
2024-11-14 17:46:06 -05:00
ronak69
8fbecc096d LibWeb: Insert title as first child on setting title of svg document
Before, the new title element got appended instead of prepended, as
nullptr was passed as the "child" argument to the insert_before()
function.

This change makes two WPT tests pass in:
http://wpt.live/html/dom/documents/dom-tree-accessors/document.title-09.html

(cherry picked from commit 3ff613712132bd3d03f44f27986f7ca5aaea8eb5)
2024-11-14 17:46:06 -05:00
Luke Wilde
dd6ede831d LibWeb: Actually traverse the shadow root of the inclusive descendant
Previously, the inclusive descendant, which is the node that
for_each_shadow_including_inclusive_descendant was called on, would not
have it's shadow root traversed if it had one.

This is because the shadow root traversal was in the `for` loop, which
begins with the node's first child. The fix here is to move the shadow
root traversal outside of the loop, and check if the current node is an
element instead.

(cherry picked from commit 6df4e5f5e75d7d6d439d1365ed7bed4fd2a8a1da)
2024-11-13 19:32:02 -05:00
Andreas Kling
bff196be31 LibWeb: Avoid unnecessary style recomputation during traversal
While traversing the DOM tree, looking for nodes that need a style
update, we were recomputing style for every node visited along the way,
even nodes that didn't themselves need a style update (but one of their
descendants did).

This avoids a bunch of completely unnecessary style recomputation on
basically every website.

(cherry picked from commit 5431db8c1c9d366d0a27959cfbf0f146bf4be20d)
2024-11-13 10:17:34 -05:00
Andreas Kling
337b113e68 LibWeb: Use the correct document URL in DOMParser.parseFromString()
We were hard-coding "about:blank" as the document URL for parsed HTML
documents, which was definitely not correct.

This fixes a bunch of WPT tests under /domparsing/ :^)

(cherry picked from commit 55f58eea99c0429dcc39cd0430fafa60eecf5542)
2024-11-13 10:17:34 -05:00
Sam Atkins
ca5b3dbd7b LibWeb/CSS: Stop invalidating style when setting an animation's effect
This reverts 6d25bf3aac

Invalidating the style here means that transitions can cause an element
to leave style computation with its "needs style update" flag set to
true. This then causes a VERIFY to fail in the TreeBuilder.

This invalidation does not otherwise seem to have any effect. The
original commit suggests this was to fix a bug, but it's not clear what
bug that was. If it reappears, we can try to solve the issue in a
different way.

(cherry picked from commit 81596b41457d250bac28db37c1390fa46e6532de;
amended test with leading whitespace since we don't have
LadybirdBrowser/ladybird#1603 yet)
2024-11-13 10:17:34 -05:00
Jamie Mansfield
5ef8538d38 LibWeb/UIEvents: Implement TextEvent
(cherry picked from commit f610a12671cccc5bf96c7ce8f7773c02412b8d81)
2024-11-12 22:26:21 -05:00
Jamie Mansfield
ad93d00ed2 LibWeb/UIEvents: Implement CompositionEvent
(cherry picked from commit 86e20ea2469c0defb6fca40de3cbb339c168b543)
2024-11-12 22:26:21 -05:00
ronak69
9ee02fc952 LibWeb: Frameset should be the body element if it comes before body
Fixes one WPT test: "Frameset followed by body inside the html element"
http://wpt.live/html/dom/documents/dom-tree-accessors/Document.body.html

(cherry picked from commit 5f9a36feacede04cd51c1a286bc5fb87b60fb5e2)
2024-11-12 19:57:55 -05:00
Jelle Raaijmakers
957ee8276a LibWeb: Use right interface for custom SVG and MathML elements
The DOM spec gets overridden by both the SVG2 and MathML core specs in
that unknown elements should not inherit DOM::Element, but
SVG::SVGElement and MathML::MathMLElement respectively.

(cherry picked from commit 76e638b4ca10a91983877d6f6e7f037c1a720965)
2024-11-12 07:14:25 -05:00
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