Commit graph

717 commits

Author SHA1 Message Date
Timothy Flynn
9a62e33517 LibWeb: Protect document observers from GC during observer invocation
We currently (sometimes) copy the observer map to a vector for iteration
to ensure we are not iterating over the map if the callback happens to
remove the observer. But that list was not protected from GC.

This patch ensures we protect that list, and makes all document observer
notifiers protected from removal during iteration.
2024-12-11 17:38:31 -07:00
Timothy Flynn
fe891727dc LibWeb: Use correct URL parsing methods throughout LibWeb
There are essentially 3 URL parsing AOs defined by the spec:
1. Parse a URL
2. Encoding parse a URL
3. Encoding parse a URL and serialize the result

Further, these are replicated between the Document and the ESO.

This patch defines these methods in accordance with the spec and updates
existing users to invoke the correct method. In places where the correct
method is ambiguous, we use the encoding parser to preserve existing ad-
hoc behavior.
2024-12-10 10:37:01 -08:00
Jelle Raaijmakers
1c55153d43 LibWeb: Refactor "editable" and "editing host" concepts
The DOM spec defines what it means for an element to be an "editing
host", and the Editing spec does the same for the "editable" concept.
Replace our `Node::is_editable()` implementation with these
spec-compliant algorithms.

An editing host is an element that has the properties to make its
contents effectively editable. Editable elements are descendants of an
editing host. Concepts like the inheritable contenteditable attribute
are propagated through the editable algorithm.
2024-12-10 14:54:19 +01:00
Shannon Booth
02efb64e64 LibWeb/DOM: Implement the DOM post connection steps
See: https://github.com/whatwg/dom/commit/0616094
2024-12-10 10:38:56 +00:00
Andrew Kaster
6ed2bf2bb1 LibWeb: Mark local variables captured in GC functions as ignored
These variables are all captured in queued events or other event loop
tasks, but are all guarded by event loop spins later in the function.

The IGNORE_USE_IN_ESCAPING_LAMBDA will soon be required for all locals
that are captured by ref in GC::Function as well as AK::Function.
2024-12-10 07:13:00 +01:00
Glenn Skrzypczak
156f9fff32 LibWeb: Support the X-Frame-Options header
Navigation responses are now checked for adherence to the
`X-Frame-Options` header and an error is shown accordingly.
2024-12-07 08:38:02 +00:00
sideshowbarker
68894306e2 LibWeb: Compute default ARIA roles context-sensitively where required
This change implements spec-conformant computation of default ARIA roles
for elements whose expected default role depends on the element’s
context — specifically, either on the element’s ancestry, or on whether
the element has an accessible name, or both. This affects the “aside”,
“footer”, “header”, and “section” elements.

Otherwise, without this change, “aside”, “footer”, “header”, and
“section” elements may unexpectedly end up with the wrong default roles.
2024-12-06 18:31:45 +00:00
Tim Ledbetter
d946d94e2d LibWeb: Improve relList feature detection support
`DOMTokenList.supports()` is now correct for all possible `rel`
attribute values for `link`, `a`, `area` and `form` elements.
2024-12-06 18:09:53 +00:00
Sam Atkins
e457252c97 LibWeb/Painting: Use GlyphRun font for measuring selection rectangle
We incorrectly used the first available font to measure this before,
which may or may not be the correct font for this text.
2024-12-06 02:57:34 +01:00
Timothy Flynn
4152870b85 LibWeb: Use a standard x-macro to create FlyString ARIA attribute names
We are currently constructing the attribute names as FlyStrings every
time we invoke one of the ARIA attributes getters/setters. If there are
not any other instances of these strings in-memory, then we're thrashing
the FlyString cache.

Instead, let's follow suit of all other Web attributes - use an x-macro
to generate the attribute names.
2024-12-05 11:45:58 -05:00
Timothy Flynn
6381ed26f2 LibWeb: Modernize the ARIA spec comment style a bit
Namely, use consistent wrapping and hanging indents on numbered spec
lines.
2024-12-05 11:45:58 -05:00
sideshowbarker
989c2f9e87 LibWeb: Use el.aria_foo(), not el.has_attribute("aria-foo"_string)
This change replaces some element.has_attribute("aria-foo"_string) calls
with element.aria_value_foo() calls instead.
2024-12-05 08:05:01 -05:00
sideshowbarker
5d47ba1e38 LibWeb: Minor code cleanup; use HTML::AttributeNames::value, not string
This is a minor change to the Node::name_or_description code to switch
some instances of element.has_attribute("value"_string) over to instead
using element.has_attribute(HTML::AttributeNames::value).
2024-12-05 08:05:01 -05:00
Psychpsyo
d4d335ebda LibWebView: Display layouting information in devtools
Specifically, you can now see whether an element is visible,
scrollable or creates a stacking context in the devtools.
2024-12-04 17:15:15 +00:00
Shannon Booth
0fa54c2327 LibURL+LibWeb: Make URL::serialize return a String
Simplifying a bunch of uneeded error handling around the place.
2024-12-04 16:34:13 +00:00
Tim Ledbetter
163b8a69e3 LibWeb: Assert that nodes share shadow-including root in BP calculation
Previously, it was assumed that nodes must share the same root, prior
to the calculation of their relative boundary point positions. This is
no longer the case, since `Selection.setBaseAndExtent()` now accepts
anchor and focus nodes that may be in different shadow trees.
2024-12-03 15:31:41 +01:00
Andreas Kling
a7b3360fb6 LibWeb: Make HTMLIFrameElement.sandbox.supports() not throw
We have to list the set of allowed values for the DOMTokenList to not
throw when asking if one is supported.

This fixes an issue where YouTube embeds would hang indefinitely trying
to report an endless series of exceptions, seen on https://null.com/
2024-12-03 15:30:18 +01:00
Netanel Haber
d743fcb376 LibWeb: Take namespace into account when matching attribute 2024-11-30 16:47:14 +00:00
Jelle Raaijmakers
4b0d8cbfad LibWeb: Implement document.execCommand("styleWithCSS") 2024-11-30 17:35:45 +01:00
Jelle Raaijmakers
4a64557876 LibWeb: Implement document.execCommand("defaultParagraphSeparator") 2024-11-30 17:35:45 +01:00
Jelle Raaijmakers
7bb865052a LibWeb: Implement document.execCommand("delete")
To facilitate the implementation of "delete" and all associated
algorithms, split off this piece of `Document` into a separate
directory.

This sets up the infrastructure for arbitrary commands to be supported.
2024-11-30 17:35:45 +01:00
Jelle Raaijmakers
c87960f8f3 LibWeb: Use GC::Ref<Node> in Range for start/end containers
Let's propagate the GC'ness of it all to the users of Range.
2024-11-30 17:35:45 +01:00
Sam Atkins
63688148b9 LibURL: Promote Host to a proper class
This lets us move a few Host-related functions (like serialization and
checks for what the Host is) into Host instead of having them dotted
around the codebase.

For now, the interface is still very Variant-like, to avoid having to
change quite so much in one go.
2024-11-30 12:07:39 +01:00
sideshowbarker
6bfc35b6a9 LibWeb: Fix aria-label precedence in accessible-name computation
This change makes Ladybird give the value of the aria-label attribute
the correct precedence for accessible-name computation required by the
“Accessible Name and Description Computation” and HTML-AAM specs and by
the corresponding WPT tests.

Otherwise, without this change, Ladybird fails some of the WPT subtests
of the test at https://wpt.fyi/results/accname/name/comp_label.html.
2024-11-29 12:18:28 +00:00
sideshowbarker
314e5d6bb7 LibWeb: Compute accessible names for hidden/hidden-but-referenced nodes
This change implements full support for the “A. Hidden Not Referenced”
step at https://w3c.github.io/accname/#step2A in the “Accessible Name
and Description Computation” spec — including handling all hidden nodes
that must be ignored, as well as handling hidden nodes that, for the
purposes of accessible-name computation, must not be ignored (due to
having aria-labelledby/aria-describedby references from other nodes).

Otherwise, without this change, not all cases of hidden nodes get
ignored as expected, while cases of nodes that are hidden but that have
aria-labelledby/aria-describedby references from other nodes get
unexpectedly ignored.
2024-11-29 12:18:28 +00:00
Gingeh
0adf261c32 LibWeb: Don't end parsing after reaching the insertion point 2024-11-26 23:50:18 +01:00
Jelle Raaijmakers
06863479be LibWeb: Fix various local names for custom elements
This fixes the typo in `HTMLFieldSetElement` and adds valid local names
for `<meta>`, `<ol>` and `<optgroup>`.
2024-11-26 15:52:54 +01:00
stelar7
4357c3229c LibWeb: Implement legacyOutputDidListenersThrowFlag 2024-11-26 14:50:27 +01:00
Sam Atkins
310cdc35f0 LibWeb: Fill-in some fixmes around sandboxing flag sets
...Including a couple of steps in
obtain_a_browsing_context_to_use_for_a_navigation_response() which
didn't have FIXMEs.

No apparent changes on WPT.
2024-11-26 10:59:50 +01:00
Milo van der Tier
aa33acf3a2 LibWeb: Update existing style object when setting style attribute
Previously any existing ElementInlineCSSStyleDeclaration would get
overwritten by e.setAttribute("style", ...), while it should be updated
instead.

This fixes 2 WPT subtests.
2024-11-25 17:16:29 +01:00
Sam Atkins
bdabc9b70d LibWeb/DOM: Update "inner invoke" to current spec
Two differences:

1. An extra step inserted to record timing info, which we don't yet
   implement.

2. The last step in the loop breaks instead of returning the value
   directly. (But this is functionally the same, as the following step
   does return that value.)

(Also removed the duplicated part of the comment in step 11 née 10.)

So, there's no actual change in behavior.
2024-11-25 13:34:40 +01:00
sideshowbarker
e2a7f844e6 LibWeb: Handle accessible-name computation for shadow roots and slots
This change adds handling for the “Determine Child Nodes” substep at
https://w3c.github.io/accname/#comp_name_from_content_find_child in the
“Accessible Name and Description Computation” spec. Specifically, it
adds handling for the “If the current node has an attached shadow root”
and “if the current node is a slot with assigned nodes” conditions.

Otherwise, without this change, AT users don’t hear the expected
accessible names in cases where the content for which an accessible name
being computed is in a shadow root or slot element.
2024-11-25 11:52:48 +01:00
sideshowbarker
db29d248ad LibWeb: Fix accessible-name computation for “encapsulation” cases
This change makes Ladybird correctly handle all “encapsulation” tests in
the https://wpt.fyi/results/accname/name/comp_host_language_label.html
set of tests in WPT.

Those all test the requirement that when computing the accessible name
for a <label>-ed form control, then any content (text content or
attribute values) from the control itself that would otherwise be
included in the accessible-name computation for it ancestor <label> must
instead be skipped and not included.

The HTML-AAM spec seems to try to achieve that result by expressing
specific steps for each particular type of form control. But what all
that reduces/optimizes/simplifies down to is just, “skip over self”.

Otherwise, without this change, Ladybird includes that “self” content
from those “encapsulated” elements when doing accessible-name
computation for the elements — which results in AT users hearing
unexpected extra content in the accessible names for those elements.
2024-11-25 11:21:23 +01:00
sideshowbarker
7a6813cdea LibWeb: Fix input@type=button|submit|reset accessible-name computation
This change makes Ladybird conform to the requirements in the HTML-AAM
spec at https://w3c.github.io/html-aam/#accname-computation for the
cases of HTML input@type=button, input@type=submit, and input@type=reset
elements. Otherwise, without this change, Ladybird fails to expose the
expected accessible names for those cases.
2024-11-25 11:21:23 +01:00
sideshowbarker
12b7304876 LibWeb: Fix accessible-name computation for table, fieldset, image input
This change makes Ladybird conform to the requirements in the HTML-AAM
spec at https://w3c.github.io/html-aam/#accname-computation for the
cases of HTML table, fieldset, and input@type=image elements. Otherwise,
without this change, Ladybird fails to expose the expected accessible
names for those cases.
2024-11-25 11:21:23 +01:00
Milo van der Tier
15741350ba LibWeb: Make replaceData create new surrogate pairs
When inserting a new utf-16 surrogate next to an existing surrogate
with replaceData, the surrogates would not get merged correctly into a
single code point. This is because internally the text data is stored
as utf-8, and the two surrogates would be converted seperately. This
has now been fixed by first recreating the whole string in utf-16 and
then converting it back to utf-8.

It's not the most efficient solution, but this fixes at least 6 WPT
subtests.
2024-11-24 13:04:06 +00:00
Andreas Kling
01f4bbbba7 LibWeb: Abandon Node.replaceChild() if removal rejigs the DOM
This isn't directly in the spec, but since replaceChild is implemented
in terms of remove + insert, the removal step may cause arbitrary code
to execute, and so we have to verify that the replaceChild inputs still
make sense afterwards, before doing the insertion.

This roughly matches what WebKit does, and makes a bunch of HTML parsing
tests in WPT stop asserting.
2024-11-24 11:45:23 +01:00
Milo van der Tier
54b0476d70 LibWeb: Handle second condition in NamedNodeMap's property names
This removes the FIXME and fixes a WPT subtest.
2024-11-23 23:21:50 +00:00
Tim Ledbetter
f378f41526 LibWeb: Use correct comparison logic in NamedNodeMap::get_attribute()
Previously, we were doing a case insensitive comparison, which could
return the wrong result if the attribute name was uppercase.
2024-11-23 21:19:28 +00:00
Shannon Booth
9724c67be2 LibWeb: Default initialize StructuredDeserialize memory argument
This is optional in the spec, so let's make it actually optional at the
call site.
2024-11-23 16:43:55 +01:00
Gingeh
7444f76b0d LibWeb: Make querySelectorAll match each element at most once 2024-11-23 09:49:33 +01:00
Gingeh
bb678e75f9 LibWeb: Reject selectors with named namespaces in querySelectorAll 2024-11-23 09:49:33 +01:00
Gingeh
ba0cc7fe46 LibWeb: Use correct case-sensitivity when matching attribute selectors
Also removed get_attribute_with_lowercase_qualified_name
because it was buggy, duplicated logic, and now unused.
2024-11-23 09:49:33 +01:00
sideshowbarker
8965698ce7 LibWeb: Support accessible-name computation for SVG elements
This change adds support for computing accessible names for SVG
elements, per the https://w3c.github.io/svg-aam/#mapping_additional_nd
spec requirements. Otherwise, without this change, accessible names for
SVG elements don’t get exposed as expected.
2024-11-23 04:34:23 +00:00
Shannon Booth
75b7a3e413 LibWeb: Add definitions for PointerEvent event handlers
Also removing a FIXME about not covering all of the event names as it is
not exactly clear when such a FIXME would be addressed, especially as
these come from multiple specifications.
2024-11-22 14:33:58 +01:00
Jonne Ransijn
f093a8af67 LibWeb: Copy m_resize_observers before iterating
An inopportune garbage collection may cause collected `ResizeObserver`s
to unregister themselves from `m_resize_observers` while we are
iterating over it, resulting in a use-after-free.
2024-11-21 19:18:26 +01:00
Shannon Booth
d6bcd3fb0b LibWeb: Make CallbackType take a realm instead of settings object
In line with the ShadowRealm proposal changes in the WebIDL spec:
webidl#1437 and supporting changes in HTML spec.

This is required for ShadowRealms as they have no relevant settings
object on the shadow realm, so fixes a crash in the QueueingStrategy
test in this commit.
2024-11-20 18:01:21 -07:00
Luke Wilde
f638f84185 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
2024-11-20 16:20:28 +01:00
Andreas Kling
4203b7823f LibWeb: Fix incorrect exception on replaceChild() with doctypes
We were checking for presence of the wrong child in the parent.
2024-11-20 16:10:57 +01:00
Andreas Kling
ab0dc83d28 LibWeb: Make Node.normalize() ignore CDATASection nodes
We hadn't modeled the "exclusive text node" concept correctly.
2024-11-20 16:10:57 +01:00