77352 Commits

Author SHA1 Message Date
Zaggy1024
22c1b72588 LibWeb: Prevent dragstart after a prevented mousedown or dragstart
Also, explicitly prevent drag events from firing when the context menu
opens. This will only be the case on macOS, since its context menu is
opened by Ctrl+mousedown. This replaces the prior exception preventing
drag events when Ctrl is held during mousedown.

Fixes #9018 and #9019
2026-04-22 07:34:18 -04:00
Zaggy1024
ccd9bdac56 Tests: Make each drag-and-drop-element.html subtest stateless
The event handler captures shouldn't be necessary here, we can just
print the events that are relevant to each testcase element.
2026-04-22 07:34:18 -04:00
Andreas Kling
a6b9548b93 AK: Switch AllocatingMemoryStream to a singly-linked chunk list
The old implementation stored chunks in a Vector, which meant every
discard() had to call Vector::remove(0, N) to drop the consumed chunks
from the front, shifting every remaining chunk down. For a stream used
as a back-pressure queue, draining it by discarding one chunk at a time
was quadratic in the queued chunk count: in RequestServer that cost
about a second of CPU per large response.

Replace it with a singly-linked list of chunks (head, tail, head read
offset, tail write offset) so push-back and pop-front are both O(1)
and no shifting ever happens. Each chunk now holds its CHUNK_SIZE byte
array inline rather than a separately-allocated ByteBuffer, which also
halves the per-chunk allocations. Teardown unlinks iteratively to avoid
recursive OwnPtr destructors on very long chains.
2026-04-22 13:32:07 +02:00
Andreas Kling
f0765e80f3 RequestServer: Avoid O(N^2) copy when draining response buffer
write_queued_bytes_without_blocking() used to allocate a Vector sized
to the entire queued response buffer and memcpy every queued byte into
it, on every curl on_data_received callback. When the client pipe was
slower than the network, the buffer grew, and each arriving chunk
triggered a full copy of everything still queued. With enough pending
data this added up to tens of gigabytes of memcpy per request and
stalled RequestServer for tens of seconds.

Drain the stream in a loop using peek_some_contiguous() + send()
directly from the underlying chunk, and discard exactly what the
socket accepted. No intermediate buffer, no copy. The loop exits on
EAGAIN and enables the writer notifier, matching the previous
back-pressure behavior.
2026-04-22 13:32:07 +02:00
Andreas Kling
612c61cc16 AK: Add AllocatingMemoryStream::peek_some_contiguous()
Expose the next contiguous range of readable bytes at the current read
offset without copying. This lets callers hand the underlying chunk
straight to write/send without round-tripping through a user-space
buffer, which is important when the stream is used as a back-pressure
queue and the total queued size can grow to many megabytes.
2026-04-22 13:32:07 +02:00
Shannon Booth
25254d5a20 LibWeb/Bindings: Move parsed IDL entities into Context
Start making IDL::Context represent the shared IDL world used during
code generation.

Move globally visible parsed IDL such as dictionaries, enums,
typedefs, callbacks, mixins, and partial declarations out of individual
Interface objects and into Context.

The main goal of this change is a step towards invoking the IDL
generator on every IDL file at once, rather than per interface.

In the meantime as standalone improvements, this lets code generation
resolve imported IDL types through the shared Context without copying
imported declarations onto each Interface. It also makes duplicate
local declarations unnecessary for imported shared types, since an
interface can reference an enum or dictionary owned by another
parsed IDL module without re-emitting it itself.
2026-04-22 13:26:01 +02:00
Shannon Booth
442a0e2e64 LibIDL+LibWeb: Move IDL interface dump into LibIDL 2026-04-22 13:26:01 +02:00
Shannon Booth
db41fde06a LibWeb/Bindings: Factor write_if_changed into standalone function 2026-04-22 13:26:01 +02:00
Shannon Booth
31a4093c86 LibWeb/Bindings: Factor out function for generating depfiles 2026-04-22 13:26:01 +02:00
Shannon Booth
0ec82fac38 LibWeb/Bindings: Convert file paths over to ByteString 2026-04-22 13:26:01 +02:00
Timothy Flynn
ab6f8d67e9 Meta: Update flatpak commit for Skia
The M144 tag was updated:
https://skia.googlesource.com/skia/+/3dde9e726a05abcd66e0ccafc4397b7b045213bd
2026-04-22 07:05:19 -04:00
Tim Ledbetter
882bd57b83 LibWeb: Drop unnecessary ColorFunctionStyleValue constructor 2026-04-22 11:52:56 +01:00
Tim Ledbetter
8d4f8a2d7f LibWeb: Route lch()/oklch() through unified ColorFunctionStyleValue 2026-04-22 11:52:56 +01:00
Tim Ledbetter
43ba21a45b LibWeb: Route lab()/oklab() through unified ColorFunctionStyleValue 2026-04-22 11:52:56 +01:00
Tim Ledbetter
e358cf1f0d LibWeb: Route hwb() through unified ColorFunctionStyleValue 2026-04-22 11:52:56 +01:00
Tim Ledbetter
ebe12a8766 LibWeb: Route hsl()/hsla() through unified ColorFunctionStyleValue 2026-04-22 11:52:56 +01:00
Tim Ledbetter
9ea880dcf0 LibWeb: Route rgb()/rgba() through unified ColorFunctionStyleValue 2026-04-22 11:52:56 +01:00
Tim Ledbetter
53a0991ff5 LibWeb: Remove LightDark and ColorMix from the ColorType enum 2026-04-22 11:52:56 +01:00
Tim Ledbetter
e4c29811be LibWeb: Generalize ColorFunctionStyleValue to cover every color space
Introduce a descriptor table keyed by `ColorType` that encodes
per-space metadata: channel kind, percent reference value, clamp
bounds, function name and serialization behavior.

This descriptor table is then used so that a single class can back
every CSS color type. Resolution, serialization, and absolutization
are driven by the descriptor.
2026-04-22 11:52:56 +01:00
Tim Ledbetter
06ee7bc532 LibWeb: Skip unstyled descendants in animation updates
Animation updates propagate inherited animated values by walking the
animated target's subtree and calling `recompute_inherited_style()` on
each element. Elements inserted during the same rendering update may
not have computed properties yet, which violates an existing assertion,
causing a crash.

Fix this by skipping unstyled descendants during this walk. The
subsequent recursive style update computes their style from scratch.
2026-04-22 10:14:47 +02:00
Timothy Flynn
f426f021ef Meta: Don't use enum.StrEnum for GUI framework
This was added in Python 3.11, whereas the default macOS version is
still 3.9.
2026-04-21 18:48:42 -06:00
Zaggy1024
296216714a LibWeb: Handle object-fit in VideoPaintable 2026-04-21 19:11:24 -05:00
Zaggy1024
51aae8b3b0 LibGfx: Allow creation of ImmutableBitmaps from const Bitmaps 2026-04-21 19:11:24 -05:00
Zaggy1024
a2bd655b1a LibWeb: Use CSSPixelFraction to calculate painted image sizes
The round trip to float here isn't necessary.
2026-04-21 19:11:24 -05:00
Zaggy1024
b20312efd4 LibWeb: Factor out replaced element sizing to its own file 2026-04-21 19:11:24 -05:00
Zaggy1024
04cc5bced9 LibWeb: Update video elements' natural dimensions during playback
This tightens the implementation of video element sizing to the spec by
implementing two spec concepts:
- The media resource's natural width and height, and
- The video element's natural width and height.
The element's natural dimensions change based on the representation,
which has many inputs, so update checks are triggered from many
locations.

The resize event is fired when the media resource's natural dimensions
change, and the layout is invalidated if the element's natural
dimensions change.

Tests for a few important resize triggers have been added.
2026-04-21 19:11:24 -05:00
Zaggy1024
938c254d6f LibWeb: Remove VideoTrack's list reference when it is removed from it 2026-04-21 19:11:24 -05:00
Zaggy1024
2420e87be9 LibWeb: Simplify video element's first poster representation condition
The HAVE_METADATA check was redundant.
2026-04-21 19:11:24 -05:00
Zaggy1024
f3d3c1f421 LibWeb: Don't clear video posters before the fetch and decode complete
Also, make all the callbacks capture the element weakly. No reason to
keep it alive here.
2026-04-21 19:11:24 -05:00
Zaggy1024
c198df4967 Tests: Add a simple video element screenshot test 2026-04-21 19:11:24 -05:00
Zaggy1024
08faa83340 LibMedia+LibWeb: Add an initial Starting state to PlaybackManager
This state will indicate to the media element that it's not guaranteed
to have a frame yet, for the purposes of determining the ready state.
JavaScript should be sure that video elements with a ready state of
HAVE_CURRENT_DATA or greater represent the current video frame already.

To allow the state to be exited if audio is disabled, audio tracks are
now only added to the buffering set on enable if the audio sink exists,
since without the sink starting the data provider, it will never be
removed.

This is a step towards making video ref tests.
2026-04-21 19:11:24 -05:00
Zaggy1024
e1e752cc28 LibMedia+LibWeb: Indicate playback states' available data with an enum
This allows us to differentiate between having no data available yet,
having current data, and having future data. The main purpose of this
is to allow a new starting state to explicitly force HAVE_METADATA
instead of >= HAVE_CURRENT_DATA.

Note that the SeekingStateHandler returns Current instead of None. This
is deliberate, since the buffered ranges from the demuxer(s) can be
used to inform whether the possibly-current data is actually available
at the seek target.
2026-04-21 19:11:24 -05:00
Zaggy1024
bedcccbdb9 LibMedia: Simplify starting/stopping buffering
The check for the previous state isn't really necessary, states that
don't care about buffering can just make this a no-op.
2026-04-21 19:11:24 -05:00
Zaggy1024
9494f4e8c5 LibWeb: Relayout video elements when setting the initial size
A while ago, we removed the relayout upon rendering a new frame. In
doing so, it became possible for the layout to remain stale after the
video metadata had loaded, leaving the video drawn in a 0x0 box.
2026-04-21 19:11:24 -05:00
Zaggy1024
29d9667511 LibWeb: Always close remote media resource streams on a request error
Otherwise, the PlaybackManager may get stuck waiting for enough data to
read the metadata and call on_metadata_parsed.

This is unfortunately difficult to test without direct control over the
fetching process, but it could cause flakes in tests that wait for
loadeddata.
2026-04-21 19:11:24 -05:00
Zaggy1024
973d3da0e7 LibWeb: Correct the MediaCapture bindings include paths
Regressed in baefb519
2026-04-22 00:41:29 +02:00
Tim Ledbetter
e5d615cb11 LibWeb: Implement autofocus candidate processing
This change implements the algorithms necessary to focus elements with
the autofocus attribute on page load.
2026-04-21 23:47:05 +02:00
Jonathan Gamble
baefb51902 LibWeb: Add Media Capture and Stream APIs 2026-04-21 16:40:46 -05:00
Jonathan Gamble
d388502a3a LibWeb: Add placeholders for mic/camera perms 2026-04-21 16:40:46 -05:00
Jonathan Gamble
736ee40db0 test-web: Dont leak captured fds when a helper process dies 2026-04-21 20:01:41 +02:00
InvalidUsernameException
06a7723ee3 LibWeb: Convert early return into assertions
When we are recomputing inherited styles, we should already have
computed style for that element at least once, so cascaded and computed
properties should exist at that point. So make the invariant explicit.
2026-04-21 18:39:00 +02:00
InvalidUsernameException
67e3b2d446 LibWeb: Recompute inherited style even if there is no layout node
`recompute_inherited_style()` assumed that there is no work to do if the
element has no layout node. This however is not necessarily true.

In particular, the following can happen:
1. The element in question is a descendant at least two layers below an
   element that has `display: none`, i.e. with at least one other
   element between them. (If it is a direct child, a full style
   recomputation will be forced for unrelated reasons).
2. TreeBuilder decides to skip creating layout nodes for the `display:
   none` element and all its descendants.
3. Due to some change on the ancestor (e.g. class added, id changed),
   the value of a property that can be inherited changes on the
   ancestor.
4. The property value of the descendant now also needs to change.

In that scenario, we won't compute the entire style of the descendant,
since that already happened. But we do need to update its inherited
properties because the old ones are now stale. At that point we still
don't have a layout node for the element since it will only be created
after this style update.

Instead of skipping the update for inherited properties, simply allow
`recompute_inherited_style()` to run even in absence of a layout node.
And then apply the style to the layout node only if one exists. If none
exists, the style will be applied later if and when a corresponding
layout node is created.

This partially fixes the blank main navigation menus on
https://bleepingcomputer.com.
2026-04-21 18:39:00 +02:00
InvalidUsernameException
059a5a245a Tests/LibWeb: Add regression test for stale inherited style
The tested behavior will be fixed by the next commit.
2026-04-21 18:39:00 +02:00
Tim Ledbetter
df34c626d8 AK: Avoid UAF for consecutive SinglyLinkedList removals
The iterator returned by SinglyLinkedList::remove() left `m_prev`
default-initialized to `nullptr`. If the caller removed another element
without first advancing, the previous node's next pointer was left
dangling to the freed node.

This caused a UAF in FinalizationRegistry's `remove_by_token()` when
two consecutive records shared an unregister token.
2026-04-21 18:09:29 +02:00
Johan Dahlin
75ae9abe7a LibGfx: Re-enable tech(variations) font support 2026-04-21 16:40:43 +02:00
Aliaksandr Kalenik
7685a5e14a LibRegex: Inline \w and \d ranges in legacy positive char classes
Previously, a character class containing any builtin (\d, \w, \s)
forced the compiler down the slow "complex class" path, which emits
a disjunction of alternatives and backtracks at runtime.

For non-unicode, non-unicode-sets, non-negated classes, \w and \d
can be inlined as their raw ASCII code-point ranges. The resulting
class stays on the fast path and compiles into a single sorted
CharClass instruction.

The unicode/unicode_sets and negation guards are required for
correctness: with the /u + /i flags, \w gains non-ASCII members
via case folding (e.g. U+017F, U+212A), and negated classes have
a separate, smarter compilation path.
2026-04-21 16:36:38 +02:00
Aliaksandr Kalenik
8c4870f207 RequestServer: Disable curl socket notifiers when no longer needed
When curl invokes the socket callback to tell us it only wants one
polling direction (e.g. CURL_POLL_IN without CURL_POLL_OUT, or vice
versa), we previously had no way to disable the other direction's
notifier. Once created, a notifier stayed enabled and kept firing
curl_multi_socket_action() for events curl was no longer interested in.

Merge the read and write branches into a single helper that also
disables the notifier for a direction when its CURL_POLL_* flag is
absent from the mask. This measurably improves performance by avoiding
redundant curl_multi_socket_action() calls on sockets curl has asked
us to stop watching in a given direction.
2026-04-21 15:45:41 +02:00
Jelle Raaijmakers
6171cb7bbf LibWeb: Override HTMLFormElement::is_supported_property_name()
By implementing this method ourselves, we no longer go through
::supported_property_names() and skip both the vector allocation and
sorting, which we don't need to determine if a property name is present.
2026-04-21 14:02:54 +01:00
Jelle Raaijmakers
e63af74dda LibWeb: Use tree order in HTMLFormElement::supported_property_names()
Calling into ::compare_document_position() for each node comparison
inside quick_sort() is quite expensive - it calculates more than we need
and allocates. Replace it with TreeNode::is_before() which does not, and
gives us the required positional info.
2026-04-21 14:02:54 +01:00
Jelle Raaijmakers
bf414f5d8f LibWeb: Simplify result in HTMLFormElement::supported_property_names()
We were doing the exact same thing as HashTable::values(). No functional
changes.
2026-04-21 14:02:54 +01:00