Commit graph

1281 commits

Author SHA1 Message Date
Callum Law
dca80ad5eb LibWeb: Account for animated values when computing font
Computing the font for an element in `compute_font` is premature since
we are yet to apply animated properties - instead we should compute the
value on the fly (with a cache to avoid unnecessary work) to ensure we
are respecting the latest values
2025-12-05 10:03:15 +00:00
Callum Law
6c236d04d8 LibWeb: Separate font computation logic from StyleComputer
Font computation and loading is distinct enough from style computation
that it makes more sense to have this in it's own class.

This will be useful later when we move the font loading process to
`ComputedProperties` in order to respect animated values.
2025-12-05 10:03:15 +00:00
Callum Law
dfa47d9ed6 LibWeb: Simplify handling of font-variation-settings
Since we resolve any relative lengths at compute time there's no need
for the value to be passed around as a `NumberOrCalculated` and we can
just resolve it within `ComputedProperties::font_variation_settings`.

The only place this is used it is used with value_or so there's no need
to return it is an `Optional`.

This is only used for loading fonts (which occurs during style
computation) so there's no need to store it in `ComputedValues`
2025-12-05 10:03:15 +00:00
Sam Atkins
4fb28539a9 LibWeb/HTML: Implement NavigationTransition committed promise 2025-12-05 09:20:02 +00:00
Sam Atkins
945c4ca5b3 LibWeb/HTML: Implement NavigationTransition.to
Corresponds to:
f19930f98a
2025-12-05 09:20:02 +00:00
Sam Atkins
43bd5342c5 LibWeb/HTML: Create a temporary execution context to abort navigation
Stops this WPT test from crashing:
navigation-api/ordering-and-transition/transition-to.html

...it now times out instead, so more work is needed before importing.
2025-12-05 09:20:02 +00:00
Feng Yu
d2029b1814 LibWeb: Relax HTML parser to allow more tags inside <select>
This implements parsing part of customizable <select> spec update.
See whatwg/html PR #10548.

Two failing subtests in `html5lib_innerHTML_tests_innerHTML_1.html`
and `customizable-select/select-parsing.html` are due to the spec
still disallowing `<input>` inside `<select>`, even though Chrome
has already implemented this behavoir (see whatwg/html#11288).
2025-12-04 17:17:01 +00:00
Timothy Flynn
674075f79e Everywhere: Remove LibCore/System.h includes from header files
This reduces the number of compilation jobs when System.h changes from
about 750 to 60. (There are still a large number of linker jobs.)
2025-12-04 15:40:46 +00:00
Sam Atkins
58b32814e0 LibWeb/HTML: Bring HTMLDialogElement up to spec
I missed when these changes actually happened, but the big differences
here are that a few steps got extracted into their own algorithms; and
the dialog now only does things when it's attached to a fully-active
document, instead of immediately.

I've imported a WPT test that exercises this by calling show() on an
unattached dialog.
2025-12-04 14:47:16 +00:00
Sam Atkins
a1fbcfb4c6 LibWeb/HTML: Implement CloseWatcher::getEnabledState closer to spec
We previously had this implemented in an ad-hoc way, where we used a
boolean on the CloseWatcher instead of a proper function with steps.
This worked at the time, but causes problems with the current version
of the spec, so let's just implement it properly.

This commit consciously does not update the spec text, because it's
diverted quite a lot. That will happen in a subsequent commit.
2025-12-04 14:47:16 +00:00
Sam Atkins
c541d14232 LibWeb/HTML: Add spec asserts to HTMLDialogElement::set_close_watcher()
Not sure when this change happened. This does include the fixed assert
from here though:
71e70e9006
2025-12-04 14:47:16 +00:00
Andreas Kling
4d27e9aa5e LibWeb: Make setInterval() reuse the timer to reduce drift
Instead of creating a new single-shot timer every time a setInterval
timer reschedules itself, we now use a repeating Core::Timer internally.

This dramatically reduces timer drift, since the next timeout is now
based on when the timer fired, rather than when the timer callback
completed (which could take arbitrarily long since we run JS).

It's not perfect, but it's a huge improvement and allows us to play
DiabloWeb at full framerate (20 fps).
2025-12-01 19:58:47 +01:00
Sam Atkins
e5ea4f9bdf LibWeb/HTML: Add source field to ToggleEventInit
Corresponds to:
95131eec8f

As we now have a field in that dictionary, I removed the separate
`source` parameter from ToggleEvent::create(). Also updated the
relevant test.
2025-12-01 14:58:20 +00:00
Andreas Kling
1c45930767 LibWeb+LibWebView+LibRequests: Reduce dependency on LibIPC includes
Let's try to include the IPC encoder/decoder stuff in fewer headers
to make rebuilds more pleasant when editing these files.
2025-12-01 15:12:52 +01:00
Sam Atkins
62d7011f45 LibWeb/HTML: Update worker construction spec steps
This is largely editorial. One behaviour change is that events are now
sent from a global task on the DOMManipulation task source.

Somewhat awkwardly, the spec refers to `this` before the Worker exists.
As it's for getting the relevant global object / settings object, I've
had to work around that.

Corresponds to:
917c2f6a73
2025-12-01 15:02:27 +01:00
Sam Atkins
d5d1b5351e LibWeb: Hide stepper buttons on appearance: textfield number inputs
The spec says:

> For the purpose of this specification, they all have the same effect
  as auto. However, the host language may also take these values into
  account when defining the native appearance of the element.

https://drafts.csswg.org/css-ui/#typedef-appearance-compat-special

Firefox at least hides the stepper buttons when this is set.
2025-12-01 11:10:13 +00:00
Sam Atkins
c3d23a2487 LibWeb/HTML: Clone integrity policy when cloning policy container
Corresponds to:
3c6cb6c0c5
2025-12-01 11:07:16 +00:00
Sam Atkins
b3d9ffdfce LibWeb/HTML: Update ImageRequest::prepare_for_presentation spec steps
Corresponds to:
ad281924e2

We don't implement this at all yet, it's still just FIXMEs.
2025-12-01 11:07:16 +00:00
Sam Atkins
573d5362f4 LibWeb/HTML: Add FIXMEs to honor WebDriver BiDi emulated language
Corresponds to:
547f8044b0

We currently don't follow the spec for these language getters, and the
BiDi changes are still ongoing, so it seems better to leave a FIXME for
them rather than try to make any changes right now.
2025-12-01 11:07:16 +00:00
Sam Atkins
c8990697d1 LibWeb: Add FIXME for moving "stop parsing" step for error documents
Corresponds to:
48cd393d1e

Actually doing so was causing crashes and other issues, so I'll leave it
as a FIXME for later.
2025-12-01 11:07:16 +00:00
Sam Atkins
2feff2b519 LibWeb/HTML: Capitalize autocorrection and autocapitalization states
Only comment changes.

Corresponds to:
ea29ce1963
2025-12-01 11:07:16 +00:00
Sam Atkins
c0b8f47a76 LibWeb/HTML: Move connectedness check for script post_connection()
Corresponds to:
905384d140

Also import the test added along with that change.
2025-12-01 11:07:16 +00:00
Sam Atkins
04f1dbce2e LibWeb/HTML: Update BroadcastChannel::is_eligible_for_messaging() spec
Corresponds to part of:
e9ccb97eb1

The majority of that spec change is in algorithms that we don't yet
implement. So this is just a small text change and an update to use
as_if() instead of static_cast().
2025-12-01 11:07:16 +00:00
Sam Atkins
ed5169af8d LibWeb/HTML: Make command events not composed
Also re-import the affected button-event-dispatch test.

Corresponds to:
787316d519
2025-12-01 11:07:16 +00:00
Tete17
42284f8006 LibWeb: Modify DomParser parseFromString to accept TrustedHTML
We made the internal changes to accept this new type, but we forgot to
expose it.
2025-12-01 09:54:04 +01:00
Tete17
901afee50b LibWeb: Implement slot validation for HTMLScriptElement
This should be the last section missing in the TrustedType spec.
2025-12-01 09:54:04 +01:00
Lorenz A
7260159b8f LibWeb: Add loading event to style element 2025-11-30 19:22:02 +01:00
InvalidUsernameException
ce2c4a3417 LibGfx+LibWeb: Fix compile errors in clang-cl from recent header cleanup
The recent commits 28ba610f32 and
70c4ed261f adjusted some include
directives to avoid excessive recompilation when changing some header
files. This has broken compilation with clang-cl on Windows without
getting noticed before the PRs were merged.
2025-11-30 08:45:29 -05:00
Sam Atkins
6ca69d9e26 LibWeb/Layout: Spec-comment Table "algorithm for processing rows"
Some of this is rearranged for clarity, but it's mostly the exact same
code. Steps 3, 10, 11, and 15 are new, but don't have any effect until
we implement downward-growing cells.
2025-11-30 11:48:14 +01:00
Sam Atkins
2af63149ec LibWeb/HTML: Resolve/reject apiMethodTracker before dispatching events
Corresponds to:
93634aed57

The current live spec has been rearranged since this went in, so that
these steps are no longer located here. But that's a much larger change
that I don't want to implement right now. See here:
e09d10202d

While I was at it, I also made use of extract_error_information() to
populate the ErrorEvent.
2025-11-30 11:47:10 +01:00
Sam Atkins
c1e4024eca LibWeb/HTML: Split out "abort a NavigateEvent" method
I missed where this change happened in the spec. The second half of
abort_the_ongoing_navigation() becomes a separate method, which is
slightly rearranged. I've placed this in Navigation instead of
NavigateEvent because of how many steps poke at the Navigation's
internals.

The text here includes the amendments I made in
https://github.com/whatwg/html/pull/11967 to correct a variable name.

A bonus is that we now actually populate the ErrorEvent instead of
leaving it blank.
2025-11-30 11:47:10 +01:00
Sam Atkins
218e646e72 LibWeb/HTML: Extract ErrorInformation struct into its own files
This is used from a few different places in the spec.
2025-11-30 11:47:10 +01:00
InvalidUsernameException
28ba610f32 Everywhere: Avoid large rebuilds when editing (Immutable)Bitmap headers
This reduces the number of recompiled files as follow:
- Bitmap.h: 1309 -> 101
- ImmutableBitmap.h: 1218 -> 75
2025-11-28 18:32:48 +01:00
Callum Law
70c4ed261f LibWeb: Reduce the number of headers CSS Parser.h is included in
Reduces the rebuild required when editing this file
2025-11-28 16:15:49 +00:00
Daniel Price
b0c48b961e LibWeb: Check that import map elements are ordered maps (json objects) 2025-11-27 14:15:33 -06:00
Sam Atkins
85478c9215 LibWeb/HTML: Rename popover "invoker"
Lots of renames, no behaviour differences. (Apart from the rename of the
IDL type, which does of course affect JS.)

Corresponds to:
16cb7808da
2025-11-27 16:44:51 +00:00
Timothy Flynn
9375660b64 LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP
The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP
caching) implementation. We currently have one implementation in LibWeb
for our in-memory cache and another in RequestServer for our disk cache.

The implementations both largely revolve around interacting with HTTP
headers. But in LibWeb, we are using Fetch's header infra, and in RS we
are using are home-grown header infra from LibHTTP.

So to give these a common denominator, this patch replaces the LibHTTP
implementation with Fetch's infra. Our existing LibHTTP implementation
was not particularly compliant with any spec, so this at least gives us
a standards-based common implementation.

This migration also required moving a handful of other Fetch AOs over
to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP
folder, so perhaps it makes sense for LibHTTP to be the implementation
of that entire set of facilities.)
2025-11-27 14:57:29 +01:00
Timothy Flynn
3dce6766a3 LibWeb: Extract some CORS and MIME Fetch helpers to their own files
An upcoming commit will migrate the contents of Headers.h/cpp to LibHTTP
for use outside of LibWeb. These CORS and MIME helpers depend on other
LibWeb facilities, however, so they cannot be moved.
2025-11-27 14:57:29 +01:00
Timothy Flynn
0fd80a8f99 LibTextCodec+LibWeb: Move isomorphic coders to LibTextCodec
This will be used outside of LibWeb.
2025-11-27 14:57:29 +01:00
Sam Atkins
936c7f05df LibWeb/HTML: Account for User-Agent not starting with "Mozilla/"
Corresponds to:
a93c6fa9fa
2025-11-27 07:20:32 -05:00
Sam Atkins
37d0741099 LibWeb/HTML: Implement HTMLTemplateElement.content to spec
No real behaviour change - it just means we VERIFY before returning the
value we returned before.
2025-11-27 10:26:13 +00:00
Sam Atkins
a25cb679fb LibWeb/HTML: Update spec text related to template's content
Corresponds to:
aa52274b5a
2025-11-27 10:26:13 +00:00
Timothy Flynn
f675cfe90f LibWeb: Store HTTP methods and headers as ByteString
The spec declares these as a byte sequence, which we then implemented as
a ByteBuffer. This has become pretty awkward to deal with, as evidenced
by the plethora of `MUST(ByteBuffer::copy(...))` and `.bytes()` calls
everywhere inside Fetch. We would then treat the bytes as a string
anyways by wrapping them in StringView everywhere.

We now store these as a ByteString. This is more comfortable to deal
with, and we no longer need to continually copy underlying storage (as
ByteString is ref-counted).

This work is largely preparatory for an upcoming HTTP header refactor.
2025-11-26 09:15:06 -05:00
Prajjwal
50a79c6af8 LibWeb: Change SessionHistoryTraversalQueue to use Promises
If multiple cross-document navigations are queued on
SessionHistoryTraversalQueue, running the next entry before the current
document load is finished may result in a deadlock. If the new document
has a navigable element of its own, it will append steps to SHTQ and
hang in nested spin_until.
This change uses promises to ensure that the current document loads
before the next entry is executed.

Fixes timeouts in the imported tests.

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-11-26 12:27:12 +01:00
Sam Atkins
8ca4833885 LibWeb/HTML: Update spec text in create_element_for()
No behaviour changes.
2025-11-26 09:52:47 +01:00
Sam Atkins
6e2f8166f4 LibWeb/HTML: Combine duplicate parsing branches
These are combined in the current spec. No behaviour change.
2025-11-26 09:52:47 +01:00
Sam Atkins
6a4ab26b48 LibWeb/HTML: Return early from find_appropriate_place_for_inserting_node
Step 2.(a).5 says to abort, but we were instead carrying on and would
run steps 3 and 4. Those steps would not change the result at all, but
this avoids a little unnecessary work.

I wrapped a couple of comments at 120 columns while I was at it.
2025-11-26 09:52:47 +01:00
Sam Atkins
418e22d65a LibWeb/HTML: Bring hand_in_head in HTML parser more up to date
A couple of spec text changes I noticed, and use `has_attribute()`
instead of manually checking it.
2025-11-26 09:52:47 +01:00
Aliaksandr Kalenik
69cede4a0f AK+LibWeb: Make StringBase::bytes() lvalue-only
Disallow calling `StringBase::bytes()` on temporaries to avoid returning
`ReadonlyBytes` that outlive the underlying string.

With this change, we catch a real UAF:
`load_result.data = maybe_response.release_value().bytes();`
All other updated call sites were already safe, they just needed to use
an intermediate named variable to satisfy the new lvalue-only
requirement.
2025-11-25 13:02:20 -05:00
Aliaksandr Kalenik
4c22c372a4 LibWeb: Avoid full DOM tree traversal in Window::named_objects()
Instead, take advantage of `ElementByIdMap` and
`m_potentially_named_elements` to gather elements with specified name
more efficiently.
2025-11-25 09:16:17 +01:00