Commit graph

1227 commits

Author SHA1 Message Date
Jelle Raaijmakers
b3c186ce64 LibWeb: Add spec steps to prescan a byte stream algorithm
Fix up the implementation as we go. Also change `ByteBuffer const&` into
`ReadonlyBytes` everywhere, so we don't accidentally copy bytes.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
f52632d48a LibWeb: Skip right amount of characters during encoding detection
When detecting an element's opening tag, the spec asks us to skip ahead
to the first whitespace or end chevron character before trying to read
attributes. Instead, we were always skipping 2 positions ahead and then
ignoring all whitespace characters and slashes, which was clearly wrong.

Theoretically this could have caused some weird behaviors if part of the
opening tag matched an expected attribute name, but it's very unlikely
to see that in the wild.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
4bcf988e46 LibWeb: Use FlyString attribute name comparisons in encoding detection
Prevent some unnecessary work by performing pointer comparisons.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
4ebbbdfef1 LibWeb: Advance position at attribute end quote in encoding detection
This did not cause any immediate issues except generating instances of
`Attr` with useless values which caused some unnecessary work during
encoding detection.
2025-11-21 17:43:08 +01:00
Sam Atkins
6e17503423 LibWeb: Add and remove MutationObservers at specified times
In the current spec, MutationObservers are explicitly added to the
pending mutation observers list, and they are removed when that list is
cleared in the "notify mutation observers" microtask.

This solves some issues with slotchange events.

As noted, we delay actually emptying the list of pending mutation
observers until after we're finished with the "clone", because we can't
actually copy or move the intrusive list. As far as I am aware, this
should not affect behaviour because only one microtask can run at once.
2025-11-21 16:19:57 +01:00
Estefania
8f15565967 LibWeb: Add stub implementation for Navigator.getBattery()
Adds a stub that returns a cached rejected promise with a
not yet implemented error. This converts
battery-status/battery-promise-window.https.html from timeout
to pass. Full implementation still needed.
2025-11-21 10:53:01 +01:00
Aliaksandr Kalenik
0eb28a1a54 LibWeb: Delete unused BufferPolicy from fetch Request
This is no longer needed since all requests are unbuffered.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
f942fef39b LibWeb: Allow microtasks to run if document has been destroyed
187f8c54 made `HTML::Task` runnable for destroyed documents, and this
change aligns microtask behavior with that. This is required for an
upcoming change that switches Fetch to be unbuffered by default. During
navigation, fetching the new document is initiated by the previous
document, which means we need to allow microtasks created in the
previous document's realm to run even after that document has been
destroyed.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
fa46efae48 LibWeb: Exit process_stylesheet_resource if document isn't fully active
This change is required to fix crashing in `link-re-enable-crash.html`
that is going to be introduced by switching to unbuffered fetching.
2025-11-20 06:29:13 -05:00
Jelle Raaijmakers
41eb7251e4 LibWeb: Convert Ladybird notes in spec steps to // NB: ...
We have a couple of ways to designate spec notes and (our) developer
notes in comments, but we never really settled on a single approach. As
a result, we have a bit of a mixed bag of note comments on our hands.

To the extent that I could find them, I changed developer notes to
`// NB: ...` and changed spec notes to `// NOTE: ...`. The rationale for
this is that in most web specs, notes are prefixed by `NOTE: ...` so
this makes it easier to copy paste verbatim. The choice for `NB: ...` is
pretty arbitrary, but it makes it stand out from the regular spec notes
and it was already in wide use in our codebase.
2025-11-18 09:07:37 -05:00
Tim Ledbetter
fdd3975104 LibWeb: Don't run update_the_image_data() algorithm if already started
This ensures that events are not fired if the image source is updated
while it is being fetched.
2025-11-15 12:39:37 +01:00
Psychpsyo
6951ef4ee3 Meta: Validate proper formatting for FIXMEs and AD-HOCs 2025-11-13 15:56:04 +01:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Jelle Raaijmakers
3f6cbeb87e LibGfx+LibWeb: Use mipmaps for downscaling images
This changes Gfx::ScalingMode to reflect the three modes of scaling we
support using Skia, which makes it a bit easier to reason about the mode
to select. New is ::BilinearMipmap, which uses linear interpolation
between mipmap levels to produce higher quality downscaled images.

The cubic resampling options Mitchell and its sibling CatmullRom both
produced weird artifacts or resulted in a worse quality than
BilinearMipmap when downscaling. We might not have been using these
correctly, but the new ::BilinearMipmap method seems to mirror what
Chrome uses for downscaled images.
2025-11-12 15:59:01 +01:00
Lorenz A
bd56fdc57b LibWeb: Allow focusable for the first summary child of a detail element 2025-11-12 13:57:05 +01:00
Lorenz A
8ca59e7c7e LibWeb: AnchorElement should be focusable with tabindex 2025-11-12 13:57:05 +01:00
Lorenz A
3bc061d028 LibWeb: Allow all elements with tabindex attribute to be focusable 2025-11-12 13:57:05 +01:00
Tim Ledbetter
154e9db033 LibWeb: Cache the value of Element::lang()
This reduces the time spent in
`SelectorEngine::matches_lang_pseudo_class()` from 1.9% to 0.41% on
https://cloudflare.com
2025-11-12 12:36:16 +01:00
Lorenz A
f8330a2ec5 LibWeb: Do not execute unclosed SVG script tags 2025-11-09 01:43:46 +01:00
Jelle Raaijmakers
02611c9c12 LibWeb: Shave 16 bytes off of each HTMLElement 2025-11-07 16:59:26 +01:00
Luke Wilde
7f7babe735 LibWeb: Remove spin_until from create_navigation_params_by_fetching
This is in similar fashion and reason to e095bf3
2025-11-07 04:08:30 +01:00
Aliaksandr Kalenik
ed9c0c1e09 LibWeb: Don't visit registered NavigationObserver from Navigable
NavigationObserver register itself in Navigable from constructor and
unregister itself from `finalize()`. The problem is that `finalize()`
won't be invoked for as long as NavigationObserver is visited by
Navigable, leading to GC leaks.
2025-11-07 04:08:30 +01:00
Luke Wilde
167de08c81 LibWeb: Remove exception throwing from Fetch
These were only here to manage OOMs, but there's not really any way to
recover from small OOMs in Fetch especially with its async nature.
2025-11-07 04:08:30 +01:00
Daniel Price
3a70a4735a LibWeb: Create an execution context before registering import map
Fixes #6297
2025-11-06 17:07:22 -05:00
Tim Ledbetter
f6f238d15c ImageDecoder+LibWeb: Perform initial alpha conversion in ImageDecoder
This change moves the initial alpha premultiplication step for all
decoded images from WebContent to the ImageDecoder process. This
doesn't reduce the overall amount of work, but it can make sites with a
lot of images more responsive.
2025-11-06 17:56:29 +01:00
Luke Wilde
82bd3d3891 LibWeb: Avoid invoking Trusted Types where avoidable
Prevents observably calling Trusted Types, which can run arbitrary JS,
cause crashes due to use of MUST and allow arbitrary JS to modify
internal elements.
2025-11-06 11:43:06 -05:00
Luke Wilde
fb9406ddcd LibWeb: Make Trusted Types injection sink names more readable
No functional change.
2025-11-06 11:43:06 -05:00
Luke Wilde
d211df8118 LibWeb: Implement Trusted Types for HTMLIFrameElement#srcdoc 2025-11-06 11:43:06 -05:00
Tim Ledbetter
478cf4f42c LibWeb: Explicitly disallow skipping 0 characters in HTML tokenizer
Previously, this caused the source position of an ambiguous ampersand
to be incorrect.
2025-11-06 10:59:54 +01:00
Timothy Flynn
6057719f63 LibWeb: Use fetch to retrieve all HTMLLinkElement resources
HTMLLinkElement is the final user of Resource/ResourceClient (used for
preloads and icons). This ports these link types to use fetch according
to the spec.

Preloads were particularly goofy because they would be stored in the
ResourceLoader's ad-hoc cache. But this cache was never consulted for
organic loads, thus were never used. There is more work to be done to
use these preloads within fetch, but for now they at least are stored
in fetch's HTTP cache for re-use.
2025-11-05 18:27:36 +01:00
Timothy Flynn
c61fa1d7aa LibWeb: Pass the HTMLLinkElement fetched resource around as a ByteBuffer
Instead of passing around a large variant, which can only contain a
ByteBuffer, let's extract the ByteBuffer ahead of time and pass that
around.
2025-11-05 18:27:36 +01:00
Timothy Flynn
523433d57d LibWeb: Organize HTMLLinkElement more consistently with other IDL types
We don't typically put spec links for methods in both the .h and .cpp
(we just put them in the .cpp).

Let's also generally organize the methods in spec-order, which for
HTMLLinkElement generally goes: init fetch -> fetch -> process data.
Makes it a bit easier to scroll through the spec and the code at the
same time.
2025-11-05 18:27:36 +01:00
Andreas Kling
4c2a02370d LibWeb: Add API to allow DecodedImageData to paint itself directly
Instead of painting DecodedImageData by first asking it for a bitmap
and then painting that, this commit adds two new APIs:

- frame_rect(frame_index):

    Gets the size of the animation frame at the given index.

- paint(context, ...):

    Paints the DecodedImageData into a DisplayListRecordingContext.

The main powerful thing here is that this allows SVGDecodedImageData
to render itself using the GPU when available.
2025-11-05 09:11:49 +01:00
Andreas Kling
cebd4cc10d LibWeb: Add ImageProvider virtual to access the DecodedImageData
...and also the current frame index, in case of animations.
2025-11-05 09:11:49 +01:00
norbiros
3829a85fde LibWeb: Add basic variable font support
Integrates the new `FontVariationSettings` from LibGfx into LibWeb to
enable initial variable font functionality. Currently, only the `wght`
(weight) axis is fully supported and tested. This update also introduces
support for the CSS `font-variation-settings` property.
2025-11-04 21:44:32 +01:00
Lorenz A
f54793315c LibWeb: Adjust buttons computed display style 2025-11-01 13:02:44 +00:00
Andreas Kling
e1344afff3 LibJS: Move ExecutionContext::context_owner to rare data
This is only used by ExecutionContexts owned by an HTML::ESO.
2025-11-01 08:40:32 +01:00
Andreas Kling
59ce6c9b41 LibJS: Shrink two u64 fields in ExecutionContext to u32
To shrink ExecutionContext, these two fields are made 32-bit:

- skip_when_determining_incumbent_counter
- program_counter
2025-10-29 21:20:10 +01:00
Zaggy1024
418f1575b0 LibWeb: Stop returning the value in HTMLMediaElement::set_current_time
This wasn't actually affecting the result in a script assigning a
variable to the result of an expression assigning to currentTime.
2025-10-29 06:22:48 +00:00
Luke Wilde
d2b2d57387 LibWeb: Set attribute value directly in HTMLScriptElement::set_src
Otherwise we'll try to use the Utf16String that has already been
through Trusted Types and put it through again. That can also fail if
there's no default policy and there's a `require-trusted-types-for
'script'` directive.

Fixes Outlook failing to load.
2025-10-28 11:05:09 -07:00
Luke Wilde
498e59f71d LibWeb: Set width/height of ImageBitmap when deserializing or receiving 2025-10-28 10:05:56 -07:00
Adrian Kiezik
823deacc27 LibWeb: Implement CanvasRenderingContext2D direction property
When direction is 'rtl':
  - textAlign='start' now aligns text to the right
  - textAlign='end' now aligns text to the left

Fixes the FIXME at CanvasRenderingContext2D.cpp:283
2025-10-27 22:03:26 -07:00
Zaggy1024
93fde59892 LibWeb: Make the value of assignment to media currentTime the rhs value
In cases where a script assigns `x = video.currentTime = y`, we are
expected to have a result of `x === y`, even if the video's duration
is less than y.

According to the spec, this happens because the official playback
position is set to `y` in this case, but since we are following
implementations in making `currentTime` immediately return the position
on the valid media timeline, we have to specifically return the
unchanged value from the setter.

See: https://github.com/whatwg/html/issues/11773
2025-10-27 17:28:49 -07:00
Zaggy1024
9e4c87ab85 LibWeb: Ensure that media elements can seek to the duration
Due to the round trip of Duration -> double -> Duration, seeking to the
end of some media can sometimes result in the seek being resolved close
to the end but not quite there. This is a little bit of a hack to make
that work, but may be necessary depending on how the spec changes with
regard to the value returned by currentTime after a seek begins.
2025-10-27 17:28:49 -07:00
Zaggy1024
cb1719aa81 LibWeb: Don't loop the media element when paused
We should be able to seek to the end of the media without looping if
we're paused.

See: https://github.com/whatwg/html/issues/11774
2025-10-27 17:28:49 -07:00
Zaggy1024
4471e8c0ec LibWeb: Consider playback ended when loop is set after ending playback
This allows playback to restart when playing is requested after the end
of playback was reached while loop was disabled, regardless of whether
loop is then subsequently enabled.

This matches other browsers' implementations, but differs from the spec
in how the ended attribute is handled.

See: https://github.com/whatwg/html/issues/11775
2025-10-27 17:28:49 -07:00
Zaggy1024
3be6b957f8 LibWeb: Add the concept of direction of playback in HTMLMediaElement 2025-10-27 17:28:49 -07:00
Zaggy1024
45727d7a58 LibWeb: Fire the media element ended event inside a task
The spec changed in this regard, and this change ensures that once the
ended attribute is updated only during event loop step 1, ended event
handlers will see the ended attribute set to true.
2025-10-27 17:28:49 -07:00
Zaggy1024
412467cc70 LibWeb: Add a hook in EventLoop to call a task when reaching step 1 2025-10-27 17:28:49 -07:00
Zaggy1024
e81fece123 LibWeb: Abort media element resource selection upon loading a source
This fixes a crash when playing video on The Cutting Room Floor.

Without aborting the resource selection algorithm, two resource
selection algorithms could be running at once, resulting in the
element requesting removal of a track from the PlaybackManager
immediately after it had been replaced with a different instance.
PlaybackManager asserts that removal of a track is valid, so this was
causing a WebContent crash.
2025-10-27 17:28:49 -07:00