Commit Graph

3456 Commits

Author SHA1 Message Date
Callum Law
614a5cf33e LibWeb: Set context for parsing against <foo-percentage> syntax
This means that we correctly parse dimension percentage mixes (i.e.
`calc(10px + 10%)` is a valid `<length-percentage>`)
2026-03-26 01:11:39 +00:00
Callum Law
ed2909674f LibWeb: Add computationally independent check for custom properties
Registered custom properties only accept "computationally independent"
values for their initial value
2026-03-26 01:11:39 +00:00
Glenn Skrzypczak
6074424486 LibWeb/HTML: Update the button activation behaviour steps
This commit updates the activation behaviour steps of the button
element in order to properly determine if a command is valid for
a target.
2026-03-25 23:14:10 +01:00
Glenn Skrzypczak
88167149f6 LibWeb/HTML: Properly get the attr-associated element
This replaces ad-hoc implementations of the get the attr-associated
element steps with a call to the proper implementation. This fixes
issue #8585.
2026-03-25 23:14:10 +01:00
mikiubo
29ae949798 LibWeb: Use outputLength instead of length in KmacParams
The WebCrypto spec was updated to rename the KMAC algorithm
parameter from length to outputLength.
2026-03-25 22:07:53 +01:00
mikiubo
be9936263f LibWeb: Re-import KMAC WPT tests 2026-03-25 22:07:53 +01:00
Shannon Booth
346fa16b1e LibWeb: Don't cancel pending navigations in navigate to a javascript URL
Other browsers appear to only do this for form submission, not for
all javascript URL navigations. Let's remove the handling in the
general javascript URL navigation handling so that our behaviour
diference to other browsers is limited specifically to form
elements, instead of the general case.

Unfortunately this does (expectedly) cause the test added in
3e0ea4f62 to start timing out, so that test is marked as skipped.
2026-03-25 22:05:25 +01:00
Shannon Booth
633b684d76 Tests/LibWeb: Handle synchronous iframe processing in CloseWatcher test
If we conform with the HTML specification by processing the iframe
synchronously as part of the iframe post connection steps, this test
will time out as the load event is fired in the appendChild call.

Create the promise for the load event before performing the load event
to handle this situation, which also allows the test to pass in
chromium.
2026-03-25 14:49:36 +01:00
Shannon Booth
d330171be3 Tests/LibWeb: Import WPT test for iframe insertion/removing steps
The failing test is because we are not invoking 'process the iframe
attributes' synchronously in the <iframe> post connection /
insertion steps.
2026-03-25 14:49:36 +01:00
Luke Wilde
102c0232ac LibWeb: Add FACEs to disabled form control checks 2026-03-25 13:18:15 +00:00
Luke Wilde
ad653da637 LibWeb: Implement ElementInternals#validationMessage 2026-03-25 13:18:15 +00:00
Luke Wilde
dfb7e51218 LibWeb: Implement ElementInternals#setValidity 2026-03-25 13:18:15 +00:00
Luke Wilde
4daa2b33f1 LibWeb: Implement ElementInternals#labels 2026-03-25 13:18:15 +00:00
Luke Wilde
297110ffb1 LibWeb: Implement ElementInternals#form 2026-03-25 13:18:15 +00:00
Luke Wilde
05c7ba2282 LibWeb: Implement ElementInternals#willValidate 2026-03-25 13:18:15 +00:00
Luke Wilde
9af3e34875 LibWeb: Return FACEs from HTML{FieldSet,Form}Element#elements 2026-03-25 13:18:15 +00:00
Luke Wilde
80302feec7 LibWeb: Implement reset algorithm for FACEs 2026-03-25 13:18:15 +00:00
Luke Wilde
4cea5d43e6 LibWeb: Queue form{Associated,Disabled}Callback where appropriate 2026-03-25 13:18:15 +00:00
Luke Wilde
6a812cf919 Tests/LibWeb: Import form-associated custom elements WPT tests
These will be worked on in future commits.
2026-03-25 13:18:15 +00:00
Luke Wilde
cfd795f907 LibWeb+IDLGenerators: Support nullable union types 2026-03-25 13:18:15 +00:00
Callum Law
500ca417ce LibWeb: Map logical aliases at compute rather than cascade time
This requires us to front load computation of writing-mode and direction
before we encounter any logical aliases or their physical counterparts
so that we can create a mapping context.

Doing this at compute rather than cascade time achieves a few things:
 1) Brings us into line with the spec
 2) Avoids the double cascade that was previously required to compute
    mapping contexts
 3) We now compute values of logical aliases, while
    `style_value_for_computed_property` maps logical aliases to their
    physical counterparts, this didn't account for all cases (i.e. if
    there was no layout node, Typed OM, etc).
 4) Removes a hurdle to moving other upstream processes (i.e. arbitrary
    substitution function resolution, custom property computation) to
    compute time as the spec requires.
2026-03-25 12:53:22 +00:00
Jelle Raaijmakers
16dffe39a0 LibWeb: Invalidate pseudo-elements on hover even when not yet created
The hover invalidation code only tried matching ::before/::after
selectors when has_pseudo_element() returned true, which requires an
existing layout node. A pseudo-element that doesn't exist yet (because
its content is only set by a hover rule) has no layout node, so the
match was skipped and hovering never triggered a style recompute.
Always try ::before/::after selectors during hover invalidation.
2026-03-24 10:23:35 -04:00
Callum Law
02db1b942b LibWeb: Improve handling of calculated values in <ratio>
We no longer try to resolve calculated values at parse time which means
we support relative lengths.

We now clamp negative values rather than rejecting them at parse time.

Parsing has been inlined into `parse_ratio_value` and `parse_ratio` has
been removed since `parse_ratio_value` was the only caller
2026-03-24 14:00:01 +00:00
aguiarcode
49d66867bd LibWeb: Invalidate inline paint caches when text selection state changes 2026-03-24 13:06:15 +00:00
Jelle Raaijmakers
fead8b92f9 LibWeb: Use correct scrollability check for autoscrolling
We only checked if the paintable box had scrollable overflow, but that
was too simple - we now use the same logic that checks whether a box can
be scrolled by a mousewheel event.

The autoscrolling test was updated as well to use rAF+rAF+timeout
instead of a fixed 1000ms timeout, which is prone to flakiness.
2026-03-24 13:55:37 +01:00
Rob Ryan
281c2ce545 LibWeb: Seed ancestor context for computing style with no layout node 2026-03-24 05:02:48 +01:00
Shannon Booth
a0878ec057 LibWeb/HTML: Teach MessageEvent to work with origins
Corresponds to whatwg/html@748b068c7c

Which fixes the Origin.from() handling for MessageEvent's.
2026-03-23 22:32:43 +01:00
Shannon Booth
fa1c046e68 Tests/LibWeb: Import some MessageEvent Origin API tests 2026-03-23 22:32:43 +01:00
Shannon Booth
ba79535d94 Tests/LibWeb: Support absolute paths for WPT files in HTTP test server
Imported WPT tests often load resources using canonical absolute paths,
for example:

/html/browsers/windows/resources/message-parent.html

Our usual strategy is to rewrite such URLs to relative paths during
import so they resolve from the importing test HTML file (which also
allows for loading this HTML as a file://).

That works for same-origin relative loading with the echo server, but it
breaks down when a test constructs a cross-origin URL from an absolute
path, for example:

get_host_info().REMOTE_ORIGIN + "/some/wpt/path.html"

In that case the resource still needs to be fetched at its canonical
absolute path, so rewriting it relative to the importing document is no
longer sufficient.

Update the HTTP test server so /static/ continues to serve from the
general test root, other non-echo requests are served from the imported
WPT tree, and dynamically registered echo responses live under /echo/
to avoid path conflicts.
2026-03-23 22:32:43 +01:00
Shannon Booth
8d6ce39a9b Tests/LibWeb: Support test-web echo server in get-host-info.sub.js
Make some local file edits to get-host-info.sub.js such that
get_host_info() refers to the echo server through localhost,
and the cross origin server through 127.0.0.1.

This allows many imported WPT tests using this function work
correctly (if loaded from the echo HTTP server).
2026-03-23 22:32:43 +01:00
Shannon Booth
093ad69f5b Tests/LibWeb: Do not hardcode URL path for echo server tests
Instead, use the URL used by the echo server.
2026-03-23 22:32:43 +01:00
Shannon Booth
b8a9288602 Tests/LibWeb: Use localhost for echo server URL
A test configured under LoadFromHttpServer is loaded over localhost
rather than 127.0.0.1, causing the echo server to be accessed
across origins. In general, the behavior being tested is intended
for same-origin scenarios, so update the echo server URL to use
localhost.
2026-03-23 22:32:43 +01:00
Shannon Booth
45a87b1dbe LibWeb: Update document URL to the entry document URL in document.open()
When document.open() is called from another window, the opened
document's URL should be updated to match the calling document's URL.
2026-03-23 09:00:39 +01:00
Glenn Skrzypczak
406a32c366 LibWeb/HTML: Make more events trusted
The beforeunload, promiserejection, beforetoggle and toggle events were
previously not tagged as trusted. This commit properly tags the event
so that we match the behaviour implemented by other browsers.
2026-03-23 02:33:56 +01:00
Glenn Skrzypczak
c6bd3173ef LibWeb/HTML: Make form submit event trusted
The form submit event was previously not tagged as trusted. This commit
properly tags the event so that we match the behaviour implemented by
other browsers and expected by WPT.
2026-03-23 02:33:56 +01:00
Andreas Kling
bf15a35ae2 LibWeb: Fix precision loss in CSSPixelFraction::to_float/to_double
CSSPixelFraction::to_float() and to_double() were converting to
CSSPixels (6-bit fixed-point) before converting to float/double,
which truncated the result to 1/64 precision. For example, 500/2500
(= 0.2) became 12/64 (= 0.1875).

Fix by dividing the numerator and denominator as floats/doubles
directly, which is what every other browser engine does when
converting layout units to floating-point ratios.

This was an oversight in the original CSSPixelFraction implementation
(commit 8cd1f65507). The class was designed for lossless comparison
and multiply-then-divide operations (which stay in CSSPixels land),
and the to_float/to_double methods were convenience additions that
took the easy path through CSSPixels conversion without considering
the precision loss.
2026-03-22 14:09:22 -05:00
Andreas Kling
9abb7e4517 LibWeb: Apply scroll margin in IntersectionObserver compute_intersection
Per the spec, the observer's [[scrollMargin]] should be applied to
each scroll container's scrollport when walking the containing block
chain. This expands the effective clip rect, allowing targets to be
detected as intersecting before they actually enter the visible area
of the scroll container.

Add a scroll_margin_values() accessor to IntersectionObserver so the
raw LengthPercentage values can be used during intersection computation.
The scroll margin is applied by inflating the scroll container's
padding box rect before clipping the intersection rect against it.
2026-03-22 14:09:22 -05:00
Andreas Kling
c871c56178 Tests: Add IntersectionObserver test for scroll margin
Add a test that creates two observers watching the same target inside
an overflow:hidden container: one without scroll margin and one with
scrollMargin "50px". The target is partially visible (10px out of 50px).

Without scroll margin, the ratio is ~0.19 (10px visible / 50px target).
With scroll margin, the expanded scrollport should make the full target
visible (ratio=1), but currently both report the same ratio because
scroll margin is not yet applied in compute_intersection.
2026-03-22 14:09:22 -05:00
Andreas Kling
229eba9a06 LibWeb: Clip against scroll containers in IntersectionObserver
Implement the containing block chain traversal in compute_intersection
(steps 2-3 of the spec algorithm). Walk from the target's paintable box
up through the containing block chain, clipping the intersection rect
against each ancestor that has a content clip (overflow != visible).

This fixes the case where a target is inside an overflow:hidden or
overflow:clip container and pushed below the visible area. Previously,
the intersection ratio was incorrectly non-zero because we only
intersected with the root bounds (viewport), not intermediate
scroll containers.

Also update the scroll container clipping tests to verify the
intersection ratio (which is what compute_intersection affects)
rather than isIntersecting (which per spec is based on targetRect
vs rootBounds, not the clipped intersection rect).
2026-03-22 14:09:22 -05:00
Andreas Kling
d1b485e6d6 Tests: Add IntersectionObserver tests for scroll container clipping
Add tests for the implicit root case where targets are inside scroll
containers with various overflow types:

- overflow:hidden container with target pushed below visible area:
  should NOT be intersecting (currently wrong, shows intersecting).
- overflow:clip container with target pushed below visible area:
  should NOT be intersecting (currently wrong, shows intersecting).
- overflow:hidden container with target at top (visible):
  should be intersecting (correct).

The two failing tests currently reflect wrong behavior because
compute_intersection does not clip against intermediate scroll
containers when walking the containing block chain.
2026-03-22 14:09:22 -05:00
Andreas Kling
bbadb38881 LibWeb: Fix IntersectionObserver skip condition for explicit roots
The boolean logic in steps 2-3 of "run the update intersection
observations steps" was incorrect. The code used || between the two
negated skip conditions instead of &&, and the first sub-expression
had its negation inverted.

This caused intersection geometry to be computed (and callbacks fired)
for targets that are not descendants of an explicit element root,
as long as they spatially overlapped the root's bounding rect.

The spec says:
- Step 2: Skip if root is not implicit AND target not in same document.
- Step 3: Skip if root is Element AND target not descendant of root.

The enter condition is NOT(skip2) AND NOT(skip3), but we had
NOT(skip2) OR NOT(skip3) with a wrong negation in the first part.
2026-03-22 14:09:22 -05:00
Andreas Kling
5e5dbae218 Tests: Add IntersectionObserver tests for explicit element root
Add tests verifying behavior when an IntersectionObserver has an
explicit element root:

- A target that is a descendant of the root should be reported as
  intersecting when it overlaps the root.
- A target that is NOT a descendant of the root but spatially overlaps
  it should NOT be reported as intersecting per spec step 3 of "run
  the update intersection observations steps". The expected output
  currently reflects the wrong (buggy) behavior.
2026-03-22 14:09:22 -05:00
Jelle Raaijmakers
f6f7e75ac9 LibWeb: Report actual network error for failed XHRs
Seeing "NetworkError: Network error" when an XHR failed was not that
useful - use the actual error message when available.
2026-03-22 18:58:49 +01:00
mikiubo
63d8f6b4a9 LibWeb: Use outputLength instead of length in CShakeParams
The WebCrypto spec was updated to rename the CSHAKE algorithm
parameter from length to outputLength.
2026-03-22 14:13:21 +01:00
mikiubo
b7eef098ed LibWeb: ReImport cshake WPT 2026-03-22 14:13:21 +01:00
Jelle Raaijmakers
94bc00248f Tests: Fix flaky load-event-delayed-by-*-background-image tests
These tests set up a delayed echo endpoint using a synchronous XHR to
http://127.0.0.1:PORT/echo, but the page itself is served from
http://localhost:PORT. This cross-origin request triggers a CORS
preflight, which intermittently fails with a NetworkError. There's
already a FIXME in place to get rid of the spin_until() that caused this
to happen.

Use a relative URL instead, since the page is already served from the
echo server.

Fixes #8564
2026-03-22 13:42:09 +01:00
Andreas Kling
593fd69cdb Tests: Make rotation interpolation test use stable boolean checks
Avoid comparing exact matrix3d values which contain floating point
noise that could differ across platforms. Instead, check whether the
transform is or isn't the identity matrix.
2026-03-21 23:16:32 -05:00
Andreas Kling
3cda08b6bf LibWeb: Numerically interpolate rotation angles for same-axis rotations
Per the CSS Transforms spec, when interpolating rotate3d() functions
with equal normalized direction vectors (or when one angle is zero),
the rotation angle should be interpolated numerically rather than
using quaternion slerp.

Previously we always used quaternion slerp, which cannot represent
rotations beyond 360 degrees. This meant that animating from
rotateY(0deg) to rotateY(3600deg) produced no visual animation, since
both quaternions are identical (3600 mod 360 = 0).

Now we detect when axes match and interpolate the angle directly,
correctly preserving multi-turn rotations. This fixes 168 WPT tests.
2026-03-21 23:16:32 -05:00
Andreas Kling
ed4b5d7b72 Tests: Add test for rotation interpolation with same-axis transforms
When interpolating between rotateY(0deg) and rotateY(3600deg), the
angle should be interpolated numerically. Currently we use quaternion
slerp which sees these as identical rotations (3600 mod 360 = 0),
producing no visual animation. A following commit will fix this.
2026-03-21 23:16:32 -05:00
Andreas Kling
42bf301acd LibWeb: Apply animation-timing-function per keyframe interval
Per the CSS Animations spec, the animation-timing-function property
describes how the animation progresses between each pair of keyframes,
not as an overall effect-level timing function.

Previously we set it as the effect-level timing function on the
AnimationEffect, which caused easing to be applied to the global
animation progress. This made animations with multiple keyframes
"pause" at the start and end of the full animation cycle instead of
easing smoothly between each pair of keyframes.

Now we:
- Store per-keyframe easing in ResolvedKeyFrame from @keyframes rules
- Store the default easing on CSSAnimation instead of on the effect
- Apply per-keyframe easing to the interval progress during
  interpolation, falling back to the CSS animation's default easing
- Also store per-keyframe easing from JS-created KeyframeEffects to
  avoid incorrectly applying CSS default easing to replaced effects
2026-03-21 23:16:32 -05:00