100 Commits
Author SHA1 Message Date
Timothy FlynnandJamie Mansfield bff7eccf6b AK: Add an option to the base64 encoder to omit padding
Will be used by an upcoming JS prototype

(cherry picked from commit 41e14e3fc3aab8417b8687df7e4242982e97ba23)

Co-authored-by: Jamie Mansfield <[email protected]>
2026-09-18 20:04:39 -04:00
Timothy Flynn 2b53409bc0 LibWeb: Remove the rebaseline-libweb-test script
This is superseded by the headless-browser --rebaseline flag.

(cherry picked from commit d33a87c8c41d77722e4a0ebb72f5bcec0f3b1c41)
2026-09-17 10:39:03 -04:00
Timothy Flynn 6ddcbc292e headless-browser: Add a flag to rebaseline executed layout / text tests
The existing rebaseline script is a bit limiting in that it can only
rebaseline a single test at a time. When making sweeping changes, this
patch will let us rebaseline any number of tests at once.

(cherry picked from commit f56b33f8d5924aceff823edc7c81e30dbaaacebf)
2026-09-17 10:39:03 -04:00
Timothy FlynnandAndreas Kling 4a813ebf30 UI/AppKit: Register socket notifiers in the common run loop mode
When the user resizes the browser window, AppKit will spin the current
run loop in the common mode. This patch allows socket events from IPC to
be processed while the resize is ongoing. This includes the WebView hook
to repaint.

(cherry-picked from commit 3bbe1b0c62c3b71fbfdd1eeb2291677e9cba1bbf)

Co-Authored-By: Andreas Kling <[email protected]>
2026-06-29 10:07:38 -04:00
Timothy Flynn aed345cae9 LibGfx: Select largest ICO image before bpp tie-break
When choosing the best image from an ICO file, prefer the entry with the
largest pixel area first, and only use bits-per-pixel as a tie-breaker.
This had regressed in commit b10fe7c136.

This fixes ICO files like Discord's favicon, where 16x16, 32x32, 48x48,
and 256x256 entries all advertise the same bpp. We were previously just
choosing whichever we saw first, which happened to be the 16x16 icon.

(cherry picked from commit b7c4cd511f0f1b02b90dc7be66333617e5a84cb3)
2026-05-28 14:15:17 +02:00
Timothy Flynn 81d31ee870 CI: Remove workaround for cross-repo file deployments
We can now use the latest checkout action. The guidance from the deploy
action is to now set persist-credentials to false during checkout for
cross-repo deployments.
2025-12-10 12:22:02 -05:00
Timothy Flynn 964627abb9 CI: Pin the checkout action to version 6.0.1
If we pin to only v6, we will have a harder time catching breakage due
to minor version updates. This happened recently with the wasm CI
workflow.
2025-12-10 12:22:02 -05:00
Timothy Flynn 6742d891bd CI: Set the Buggie token when checking out the SerenityOS repo
This is based on:
https://github.com/LadybirdBrowser/ladybird/compare/e0dd182..46ce9b0

For more info, see:
https://github.com/orgs/community/discussions/26694

Note that although we use this token when pushing to the libjs-data
repo, it needs to be set when checking out the Serenity repo, as that
is where git operations are ultimately performed with
JamesIves/github-pages-deploy-action.

It's not clear to me if the permissions added here are needed. I think
it depends on repo settings I can't access. But it's not incorrect to
add them anyways.
2025-12-04 11:37:22 -05:00
Timothy Flynn 0edcd19615 AK: Avoid copying the iterable container in AK::enumerate
There are actually a couple of issues here:

1. We are not properly perfect-forwarding the iterable to the Enumerator
   member. We are using the class template as the constructor type, but
   we would actually have to do something like this to achieve perfect
   forwarding:

   template <typname Iter = Iterable>
   Enumerator(Iter&&)

2. The begin / end methods on Enumerator (although they return by const-
   ref) are making copies during for-each loops. The compiler basically
   generates this when we call enumerate:

   for (auto it = Enumerator::begin(); it != Enumerator::end(); ++it)

   The creation of `it` above actually creates a copy of the returned
   Enumerator instance.

To avoid all of this, let's create an intermediate structure to act as
the enumerated iterator. This structure does not hold the iterable and
thus is fine to copy. We can then let the compiler handle forwarding
the iterable to the Enumerator.
2025-11-18 01:14:53 +01:00
Timothy Flynn a11169e9a6 UI/Qt: Prevent division by zero in tab width calculation
On macOS, the first time TabBar::tabSizeHint is called, the count is
reportedly zero, and results in a floating point exception on x64.

(cherry picked from commit cbf1fd3e61710d9e8069ea1480b25734fd35d26f)
2025-10-29 12:55:26 -07:00
Timothy Flynn b65336b68b LibJS: Update Intl AO spec numbers
Otherwise, upcoming AO implementations will conflict with these.

(cherry picked from commit 89aa9a3af07ec9d1e8c847b92f91227b35811085)
2025-10-24 19:10:49 -04:00
Timothy Flynn 6c122ef16f Meta: Do not pass an empty --resources flag to headless-browser
The ${resource_base_dir} no longer exists in this context. Thus LibWeb
tests were no longer actually running.

(cherry picked from commit cd581e9502dd765a61cd0a73a0c93f1ea1cb9b0f)
2025-10-24 19:10:49 -04:00
Timothy Flynn dbb028d137 Meta: Copy resources to the app bundle during create_ladybird_bundle()
For some reason, moving the UI-specific CMake to its own files prevents
resource files from being copied to the Resource directory in the macOS
application. I'm not sure what the difference here is, but doing this
step during create_ladybird_bundle() works.

(cherry picked from commit 8641e78cdce4da621251b0faee755b4040f444c9)
2025-10-24 19:10:49 -04:00
Timothy Flynn 5b32f9e172 LibCore: Awaken read notifiers when we receive POLLHUP events
POLLHUP is set when the remote end of the monitored fd is closed. There
may still be some buffered data to read from the socket, however. Some
systems do not set POLLIN in these cases. So we should just always try
to read from fds when we receive this event.

(cherry picked from commit a9f757973894e64ffd81d9baa12a361fa4d4607d,
tweaked due to additional Userland/ prefix in path)
2025-08-07 14:04:06 +02:00
Timothy Flynn b385e357cd LibCore: Always reset the polled revents field back to 0
One benefit of using `poll` over `select` is that we can re-use the poll
structure list. But there's no guarantee that the underlying system will
reset the `revents` field back to 0. So let's explicitly do so.

(cherry picked from commit f46b721c57b9ccde9ad3de3034f626e0a7607e92,
tweaked due to additional Userland/ prefix in path)
2025-08-07 14:04:06 +02:00
Timothy Flynn 601ad95fc0 LibThreading: Pass ownership of a BackgroundAction result to its caller
There is no need to create a copy of potentially expensive structures.

(cherry picked from commit 5f9ed343b3ab7b7555e822b50d78131f3563848b)
2025-02-15 18:44:52 -05:00
Timothy Flynn ec590e0472 LibThreading: Avert a reference cycle in BackgroundAction
When a BackgroundAction completes, it resolves a Promise (stored on the
BackgroundAction object) with a reference to itself. The Promise will
never unset this resolved value, thus it will hold a strong reference to
the BackgroundAction until it is destroyed. But because the Promise is
owned by the BackgroundAction itself, we have a reference cycle, and
neither object can be destroyed.

The only user of BackgroundAction is the ImageDecoder process. The
consequence was that the ImageDecoder process would never release any
image data for successfully decoded images.

To fix this, instead of storing the promise on the class itself, we can
just create it as a local variable and pass it around.

(cherry picked from commit f20aa82c2770d1cf725384f64e9990df4d44b33a)
2025-02-15 18:44:52 -05:00
Timothy Flynn 026b5e53eb LibCrypto: Protect the SignedBigInteger ctor against integer overflow
In particular, if given a value of -2147483648, we would invoke signed
integer overflow (which is UB).

(cherry picked from commit edd3b14ddf049048e5d6bd952677133237adb652)
2024-12-21 14:58:20 -05:00
Timothy Flynn e0a25b5cdd LibJS: Return the allocated dst register from deleting super properties
Even though calling delete on a super property will ultimately throw a
ReferenceError, we must return the allocated register for the result of
the delete operation (which would normally be a boolean). If the delete
operation is used in a return statement, the bytecode generator for the
return statement must be able to assume the statement had some output.

(cherry picked from commit 5947c37637f8ea3d4c323a04e5e5dfe9fad5a4d7)
2024-12-21 14:58:20 -05:00
Timothy Flynn 62ced93997 LibJS: Avoid internal assertion accessing detached TA internal slots
This defers accessing TA internal slots until we know we have a valid,
attached TA. Our implementation has assertions that guard against this.

(cherry picked from commit 962441b3cf34c1350877ac7c73351657c10f675b)
2024-12-21 14:58:20 -05:00
Timothy Flynn 4a52145f8e LibWebView: Implement drag-and-drop for OutOfProcessWebView
Almost the entirety of drag-and-drop operations are handled within
LibWeb. This patch just hooks up the UI-side operations to trigger
the events.

A FIXME is left here to open files in the browser that were not accepted
by the web page.
2024-12-04 08:00:21 -05:00
Timothy Flynn c3b1d533f6 LibWebView: Add explicit conversions between GUI and Web button codes
They happen to currently have the same values, but let's be explicit.
2024-12-04 08:00:21 -05:00
Timothy Flynn 81e469c911 LibGUI+WindowServer+Applications: Carry more data across drag events
To support drag-and-drop for LibWeb, the drag events need the full mime
data from WindowServer, not just the list of stringified mime types. We
only provided the full data in the drop events. This patch provides the
Core::MimeData type, as well as other mouse-event information needed for
LibWeb (what buttons / modifiers are pressed).

To do this, we add a specific WindowServer IPC to inform the Application
of the event. We previously tagged mouse-move events with some drag data
and formed the drag event client-side. That extra data is removed in
favor of this new IPC.
2024-12-04 08:00:21 -05:00
Timothy Flynn 091e832b48 LibIPC: Pass AK::Duration by value over IPC
AK::Duration is simply an integer, and does not need to be passed by
reference.

(cherry picked from commit 6ce473af72ba666a8bae80a7f7691d233bdd2a43)
2024-11-29 20:25:45 -05:00
Timothy Flynn 1c4996ff34 LibWeb: Move some classes from the DOM namespace to the HTML namespace
The following classes are in the HTML spec and thus belong in the HTML
namespace:

* BeforeUnloadEvent
* HTMLFormControlsCollection
* RadioNodeList

(cherry picked from commit 13b7355ec10c21be90df997c66022e246c57656d)
2024-11-28 21:31:42 -05:00
Timothy Flynn 849a3a531f LibWeb: Wait for the iframe load before completing the beforeunload test
This test caused some flakiness due to the about:blank load it triggers.
It causes headless-browser to receive a load event for about:blank. If
we have moved onto the next test before that event arrived, that test
would ultimately time out, as its own load will have been dropped while
the about:blank load is still ongoing.

This patch makes us wait for that iframe load event before completing
the test.

We may want to consider never sending subframe load events to the UI
process as well. We really only care about top-level page loads in the
receivers of that event.

(cherry picked from commit be9071834eb0c836ccd821adaa0134820e3f6297)
2024-11-28 21:31:42 -05:00
Timothy Flynn dda405e652 UI/Qt: Execute dialogs opened from the page asynchronously
Invoking exec() entirely blocks the UI application's main thread. Qt
explicitly recommends against this. In practice, it seems prevents some
IPC messages from being handled by the UI until the dialog is closed by
the user.

Instead, use open() (which is non-blocking) and set up a signal handler
to deal with the result.

(cherry picked from commit ea9abe26e1c40c0d2e96007bf7d69afb49a7052a)
2024-11-28 18:58:55 -05:00
Timothy Flynn 5fe499b493 LibWeb+WebContent+WebDriver: Asynchronously wait for dialog dismissal
There was a timing issue here where WebDriver would dismiss a dialog,
and then invoke another endpoint before the dialog was actually closed.
This is because the dismissal first has to hop over to the UI process to
close the graphical dialog, which then asynchronously informs WebContent
of the result. It's not until WebContent receives that result that the
dialog is considered closed, thus those subsequent endpoints would abort
due a dialog being "open".

We now wait for dialogs to be fully closed before returning from the
dismissal endpoints.

(cherry picked from commit 0722a3b1c091adbafc056686ebedbf5c2db84207)
2024-11-28 18:58:55 -05:00
Timothy Flynn ace8231970 WebContent+WebDriver: Asynchronously wait for navigations to complete
Similar to commit c2cf65adac78912883996153fb608dafe389b6e0, we should
avoid spinning the event loop from the WebContent-side of the WebDriver
connection. This can result in deadlocks if another component in LibWeb
also spins the event loop.

The AO to await navigations has two event loop spinners - waiting for
the navigation to complete and for the document to reach the target
readiness state. We now use NavigationObserver and DocumentObserver to
be notified when these conditions are met. And we use the same async IPC
mechanism as script execution to notify the WebDriver process when all
conditions are met (or timed out).

(cherry picked from commit bf0bc62654803565a6f39ade63d9172cc48c085a)
2024-11-28 18:58:55 -05:00
Timothy Flynn 3e9a2ef0b2 LibWeb: Move WebDriver's HeapTimer helper class to its own file
And generalize it a tiny bit to be reusable outside of ExecuteScript.

(cherry picked from commit 8598d4670dc6a5b44f2081457af10ea5b2306108)
2024-11-28 18:58:55 -05:00
Timothy Flynn 528fa3bbdb LibWeb: Add a NavigationObserver to be notified of navigable updates
This contains a hook to be notified when a navigable navigation is
complete, to be used by WebDriver.

(cherry picked from commit 74ef9dc3936d678fdf811bb3c1b39a6ffba2b106)
2024-11-28 18:58:55 -05:00
Timothy Flynn 750ef1466f LibWeb: Allow removing DocumentObserver hooks
Some callers (namely WebDriver) will want to stop receiving updates from
the DocumentObserver.

(cherry picked from commit 247307a2a28e92b20a57d127eed73a093dd4e3d3)
2024-11-28 18:58:55 -05:00
Timothy Flynn 9690784996 LibWeb: Add a DocumentObserver hook to be notified of readyState changes
(cherry picked from commit 0bbe836f8c10cd4d080927021b9b5b48f1dfc20a)
2024-11-28 18:58:55 -05:00
Timothy Flynn d992565f52 LibWeb: Update (not replace) timeout values in WebDriver's Set Timeouts
Contradictory to the spec, the Set Timeouts endpoint should update the
existing timeouts configuration in-place, rather than replacing it. WPT
expects this, and other browsers already implement this endpoint this
way.

(cherry picked from commit dae6200c1dab586258a8a970ba308c6b2f1cad9c)
2024-11-28 18:58:55 -05:00
Timothy Flynn c97e740348 LibWeb: Update WebDriver timeout parsing/serializing to the latest spec
Namely, all fields in the timeouts object may now be null. There are a
few calling AOs that we will want to bring up to date as well.

(cherry picked from commit 8396afeb76b5229c385525d307a8d91efa45d6ff)
2024-11-28 18:58:55 -05:00
Timothy Flynn d8080cf1a6 WebContent: Add a JS visitor to WebDriver's IPC connection
We've added a few JS::Handle members to this class over time. Let's
avoid creating a new GC root for each of these, and explicitly add a
visitation method.

(cherry picked from commit 048b51eb54d003af5dc202af1b16bb690b1348f9)
2024-11-28 18:58:55 -05:00
Timothy Flynn 2d24c5fbf8 LibWeb+WebContent: Rename the WebDriver get-known-element AO
The underlying concept is the same, but this method was renamed in the
spec to drop the word "connected".

(cherry picked from commit 022e2b8a94497c01138840478f76af07ddcf51da)
2024-11-28 18:58:55 -05:00
Timothy Flynn c2a4606c1f LibWeb+WebContent: Use NNGCPtr in WebDriver code where appropriate
Some of this code is older than widespread use of GCPtr. These functions
returning raw pointers has been a point of confusion at times, so lets
just indicate that they are non-null.

(cherry picked from commit a96a762305423965a9697c2b7038a229d96ac734)
2024-11-28 18:58:55 -05:00
Timothy Flynn dfa9ed08ac LibWeb+WebContent: Implement the Element Clear endpoint
(cherry picked from commit 8598ed86fe9b07e55655d36fcce7ec1dfdbc4491)
2024-11-28 18:58:55 -05:00
Timothy Flynn 47845a32c4 LibWeb: Implement the form associated element clear algorithm
This is a method defined in the WebDriver spec, but requires access to a
bunch of private fields in these classes, so this is implemented in the
same manner as the reset algorithm.

(cherry picked from commit 516f5f70081526ddef2d4a88fc5a1ae916e12fab)
2024-11-28 18:58:55 -05:00
Timothy Flynn e649cd9108 LibWeb: Begin implementing the Element Send Keys endpoint
(cherry picked from commit 23d134708c6ba20fcb6a18ee6552dc1b5ac0cd6d)
2024-11-28 18:58:55 -05:00
Timothy Flynn 6e4d7015bc WebDriver: Generalize asynchronous event handling
Instead of having N functions all implement the same practice of looping
until an async event has arrived, this templatizes the bulk of the work.

(cherry picked from commit 922837f31b4cc66f6a3acd875962b54c6d547f65)
2024-11-28 18:58:55 -05:00
Timothy Flynn 5281349590 LibWeb: Support appending files to <input type=file>
This isn't exposed to the Web, but WebDriver requires this feature.

(cherry picked from commit 63b24e38faab768799a6597e1b7703f4b62cac02)
2024-11-28 18:58:55 -05:00
Timothy Flynn fb11a8266c LibWeb: Implement dispatching WebDriver key down and key up actions
(cherry picked from commit d6a8fc00c3435bd9b4e61edeb364dec5c1bf65ea)
2024-11-28 18:58:55 -05:00
Timothy Flynn d50fb09301 LibWeb: Support non-required numpad code names
These aren't required to comply with the UIEvents spec, but they are
required by WebDriver.

(cherry picked from commit 5b2633d90f81d0098d5d7cea1274b98c91851fae;
amended to change `MOD_KEYPAD` to 32 to match serenity's `Mod_Keypad`
in Kernel/API/KeyCode.h)
2024-11-28 18:58:55 -05:00
Timothy Flynn 45f89decac LibWeb: Allow multi-byte code point events to have their key field set
Multi-byte code point presses do not have a UIEvents::KeyCode value, so
we would previously set the event's key field to "Unidentified".

(cherry picked from commit a11e5055c7f225da3b96571e892042868fd2af18)
2024-11-28 18:58:55 -05:00
Timothy Flynn 496cccab85 LibWeb: Properly handle when (shift+)tab wraps around the page
We have support for using (shift+)tab to move focus to the next/previous
element on the page. However, there were several ways for this to crash
as written. This updates our implementation to check if we did not find
a node to move focus to, and to reset focus to the first/last node in
the document.

This doesn't seem to work when wrapping around from the first to the
last node. A FIXME has been added for that, as this would already not
work before this patch (the main focus here is not crashing).

(cherry picked from commit 96b5646fc116a98dac80559b9a4be2c149f2e157)
2024-11-28 18:58:55 -05:00
Timothy Flynn 1b8ace0d25 WebContent: Wait for same-URL WebDriver navigations to complete
The spec says we don't need to await navigations if we navigate to the
same URL that we are already on, but at least in our implementation, we
should still await the page load. Otherwise, we will invoke WebDriver
endpoints on the wrong page.

(cherry picked from commit 13fe3477ab8ac253bd7346d50b3224baf891872e)
2024-11-28 18:58:55 -05:00
Timothy Flynn 5e555ee02b WebContent: Create an execution context when getting an element property
Calling Object::get requires a running execution context.

(cherry picked from commit cbf8f1495ccd553f4d9e0919ce707938912fca5f)
2024-11-28 18:58:55 -05:00
Timothy FlynnandNico Weber 965e1baa8c LibWeb+UI: Detect and handle left vs. right modifier keys
Our handling of left vs. right modifiers keys (shift, ctrl, etc.) was
largely not to spec. This patch adds explicit UIEvents::KeyCode values
for these keys, and updates the UI to match native key events to these
keys (as best as we are able).

(cherry picked from commit 4fcaeabe1a6acd9f4d5fd811a36f2e86748b2a72;
amended to make the rest of the system build and to keep `Mod_AltGr`
around in addition to adding it as a key)

Co-authored-by: Nico Weber <[email protected]>
2024-11-28 15:15:36 -05:00
Timothy Flynn 96ba151190 LibWeb: Only fire keypress events if the key press produced a character
For example, pressing just the shift key should not producde a keypress
event.

(cherry picked from commit 448754d95dc797b44d9b066c1e37dabec79d79e6;
amended to not use ICU in CharacterTypes.cpp)
2024-11-28 15:15:36 -05:00
Timothy Flynn 3e85b7bf53 LibWeb: Fire keydown and keypress events sooner
Fire the events before handling any close requests or selection changes.
Pages must have an opportunity to cancel the events.

(cherry picked from commit 3925317c118e23a9b87b65ca792c5d94a92c98a7)
2024-11-28 15:15:36 -05:00
Timothy Flynn 50fd33a531 UI/AppKit: Send keyboard events for modifier-only key presses/releases
If the user only presses the shift key, for example, we are required to
still send that event to WebContent and generate the corresponding JS
events. Unfortunately, NSApp does not inform us of these events via the
keyDown/keyUp methods. We have to implement the flagsChanged interface,
and track for ourselves what modifier keys were pressed or released.

(cherry picked from commit eabd5b0f2271e7a89727daf80dd28623711f3416)
2024-11-28 15:15:36 -05:00
Timothy Flynn bb8b24eef7 LibWeb: Move initial creation of Unicode segmenters to the Document
The expensive part of creating a segmenter is doing the locale and UCD
data lookups at creation time. Instead of doing this once per text node,
cache the segmenters on the document, and clone them as needed (cloning
is much, much cheaper).

On a profile loading Ladybird's GitHub repo, the following hot methods
changed as follows:

    ChunkIterator ctor: 6.08% -> 0.21%
    Segmenter factory:  5.86% ->    0%
    Segmenter clone:    N/A   -> 0.09%

(cherry picked from commit 5d7175874258f00763adcced230149dd1379e4a6;
mended as usual for Unicode::Segmenter -> Locale::Segmenter, and also
to resolve minor conflicts due to serenity not yet having
LadybirdBrowser/ladybird#1106. Also, due to serenity not using ICU,
this doesn't have a big performance effect over here, but it still
makes future cherry-picks easier)
2024-11-27 12:57:15 -05:00
Timothy Flynn 886f9016ab LibWeb: Iterate over text chunks using a grapheme-aware segmenter
Our current text iterator is not aware of multi-code point graphemes.
Instead of simply incrementing an iterator one code point at a time, use
our Unicode grapheme segmenter to break text into fragments.

(cherry picked from commit f0105b473b9cc3446ec36359b559db9a8e78446d;
amended as usual for Unicode::Segmenter -> Locale::Segmenter, and to
tweak expected/multi-code-point-graphemes.txt for serenity's superior
emoji glyphs)
2024-11-27 11:43:26 -05:00
Timothy Flynn b09eaa121e LibWeb: Use a Unicode text segmenter to select words on double-click
We currently use a naive word segmentation, looking for ASCII spaces to
mark a word boundary. Use LibUnicode's complete implementation instead.

(cherry picked from commit 430c9d3e3fb6ec9e2aa3d962381672b70957c395;
amended to use Locale::Segmenter instead of Unicode::Segmenter due
to LibLocale and LibUnicode being two distinct libraries in serenity)
2024-11-26 17:08:34 -05:00
Timothy Flynn 071d85e1cc LibWeb: Re-assign cmd+arrow key events to home/end keys on macOS
In text documents, pressing the left/right arrow keys with the cmd key
pressed should be treated as home/end key presses.

(cherry picked from commit bf9d05d97a570e8d4ebd83ca7e757938c2b504b3)
2024-11-26 16:03:32 -05:00
Timothy Flynn 5bc052948a LibWeb: Support jumping across word boundaries in text nodes
This also supports holding shift to modify the selection.

(cherry picked from commit a0072f422a11229d4b35308e7aa6badd23d08ba6)
2024-11-26 16:03:32 -05:00
Timothy Flynn d89c41e4ad LibWeb: Add Document helpers to move its cursor to word boundaries
This implementation is based on the same feature I added to Serenity's
TextEditor:

https://github.com/SerenityOS/serenity/pull/17477

(cherry picked from commit ecf2cc600bea8f8396061f5fe6aba8358a033bbb;
amended to change Unicode::Segmenter to Locale::Segmenter due to
LibLocale and LibUnicode being separate libraries in serenity)
2024-11-26 16:03:32 -05:00
Timothy Flynn d4c5942664 LibWeb: Rename CharacterData's segmenter indicate it is for graphemes
We will be adding a word segmenter as well, so this is to disambiguate
the two.

(cherry picked from commit eece7697fdcaf50eed98fff069c5e678ac425784;
amended to fix conflict due to Serenity's Segmenter still being in
LibLocale, while upstream combined LibLocale and LibUnicode)
2024-11-26 16:03:32 -05:00
Timothy Flynn f1ad3f7969 LibWeb: Define a helper constant for the platform word-jumping key
On Linux/Windows, the ctrl key is used in conjunction with arrow keys to
jump word-by-word in text documents. On macOS, the option key is used
(which is mapped to the alt key code).

(cherry picked from commit feecf89d65b3f76a4fe090daa01928439efb9fce;
amended to fix minor conflict)
2024-11-26 16:03:32 -05:00
Timothy Flynn 7ba0f65fe4 LibUnicode: Add code point GC queries for Punctuation and Separator
(cherry picked from commit 3e116769fb29544498633bddd41d862a917379f0;
amended to not use ICU)
2024-11-26 16:03:32 -05:00
Timothy Flynn d0e18b896b LibWeb: Support ctrl/cmd-clicking a link to open it in a new tab
The spec does not define activation behavior of ctrl/cmd clicks, so we
have to go a bit ad-hoc here. When an anchor element is clicked with the
cmd (on macOS) or ctrl (on other platforms) modifier pressed, we will
skip activation of that element and pass the event on to the chrome. We
still dispatch the event to allow scripts to cancel the event.

(cherry picked from commit 40b2d24d5585a94f09f521bb0ceb055dcae7b6e9)
2024-11-26 16:03:32 -05:00
Timothy Flynn 47a25e4f97 LibWeb: Remove debug spam when clicking a link
(cherry picked from commit c2d5e30a35d38beb53ee0ee07ab53fc59d9949e3)
2024-11-26 16:03:32 -05:00
Timothy Flynn 85c301948c LibWeb+WebContent: Add a page hook to invoke the did-click-link IPC
(cherry picked from commit facaf953eb9e4f1d48b5a156c05dc8924b688318)
2024-11-26 16:03:32 -05:00
Timothy Flynn 7b557904af WebContent: Remove unnecessary [[maybe_unused]] attributes
Noticed while copy-pasting this method to a did-click-link method.

(cherry picked from commit 3ff965d6727a1991be94e9714bc4126fa3ffa4b8)
2024-11-26 16:03:32 -05:00
Timothy Flynn 02fae575ca LibWeb: Define a helper constant for the platform ctrl-ish key
For all intents and purposes, the cmd (super) key on macOS should be
treated as the ctrl key.

(cherry picked from commit 71b25e3e5a70937f1e2031b94541c04a68d28efa;
amended to fix minor conflict)
2024-11-26 16:03:32 -05:00
Timothy FlynnandTim Flynn bf74a499a0 LibUnicode: Tweak code point general category APIs
The motivation is to have `code_point_has_*_control_general_category()`
functions, so that clients don't have to look at `GeneralCategory`
values directly and hence don't have to worry about
`code_point_has_general_category()` returning an empty Optional. This
isn't quite achieved since some code inside LibLocale still uses some of
them, but it removes uses in LibGfx and LibJS.

This kind of cherry-picks the 2nd commit of
LadybirdBrowser/ladybird#239 (aa3a30870b58c47cb37bce1418d7e6bee7af71d9):
The Lexer.cpp, RegexByteCode.cpp, CharacterTypes.h, KeyboardEvent.cpp
changes are by trflynn.

This does not (yet?) pick up the new type for `GeneralCategory`. In the
future, we might want to make the generator generate a
`GeneralCategoryEnum` type and have the
`AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL` in Forward.h, but at the moment
that makes things more complicated. (It also means we don't pick up the
RegexParser.cpp changes.)

Co-authored-by: Tim Flynn <[email protected]>
2024-11-26 13:57:13 -05:00
Timothy FlynnandTim Flynn 531189561c LibUnicode: Tweak code point property APIs
The motivation is to have `code_point_has_*_property()` functions, so
that clients don't have to look at `Property` values directly and hence
don't have to worry about `property_from_string()` returning an empty
Optional. This isn't quite achieved since some code inside LibLocale
still uses some of them, but it removes uses in LibGfx and LibJS.

This kind of cherry-picks the 1st commit of
LadybirdBrowser/ladybird#239 (aa3a30870b58c47cb37bce1418d7e6bee7af71d9):
The TextLayout.cpp, Lexer.cpp, CharacterTypes.h, Emoji.cpp changes are
by trflynn.

This does not (yet?) pick up the new type for `Property`. In the future,
we might want to make the generator generate a `PropertyEnum` type and
have the `AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL` in Forward.h, but at the
moment that makes things more complicated. (It also means we don't pick
up the RegexParser.cpp changes.)

Co-authored-by: Tim Flynn <[email protected]>
2024-11-26 13:57:13 -05:00
Timothy Flynn 4208ce6eae LibWeb: Port text segmentation to the Segmenter API
(cherry picked from commit 12f177e9e94ca71c619ec1171078e8635debde09;
amended to remove mention of ICU in commit message, and to resolve
a minor conflict in CharacterData.h due to serenity cherry-picking
LadybirdBrowser/ladybird#901 before this change)
2024-11-26 13:50:49 -05:00
Timothy Flynn e1850a0580 LibJS: Port Intl.Segmenter to the Segmenter API
(cherry picked from commit 14071c52f94e3f7149ee60325ae855afdd94d088;
amended to tweak commit message and Intl/Segmenter.h to not say
"ICU", and undid FIXME removal in Segmenter.prototype.segment.js
since these checks still fail in serenity)
2024-11-26 13:50:49 -05:00
Timothy Flynn 69ba7102a2 LibWeb: Dispatch WebDriver mouse events relative to the top-level frame
There are many WPT subtests which validate how we behave against frames
that have been removed. They do this by adding an iframe element with a
button whose click action removes the iframe element. When the click is
dispatched, the spec would have us generate a mouse event relative to
that iframe, rather than the top-level frame, thus the click would miss
the target button.

Serendipitously, a spec issue and PR were just opened to generate mouse
events relative to the top-level frame. This patch implements that PR;
it has some editorial issues to be resolved, but is a clear improvement
for these tests.

(cherry picked from commit 0042bbb68d906a557ddc614392075a961531c917)
2024-11-25 08:50:54 -05:00
Timothy Flynn 1322fed4c8 LibWeb+WebContent: Do not include DOM HTML in text test expectations
For example, in the following abbreviated test HTML:

    <span>some text</span>
    <script>println("whf")</script>

We would have to craft the expectation file to include the "some text"
segment, usually with some leading whitespace. This is a bit annoying,
and makes it difficult to manually craft expectation files.

So instead of comparing the expectation against the entire DOM inner
text, we now send the inner text of just the <pre> element containing
the test output when we invoke `internals.signalTextTestIsDone`.

(cherry picked from commit bf668696de9a68bbcd6adfeaac809a475da015dc;
amended a bit but not as much as one might think -- see PR for details)
2024-11-24 22:42:15 -05:00
Timothy Flynn 6bc2b81a9f LibWeb: Wait for the correct condition in Stream tests
We were signaling that the test is complete too early in some Stream
tests.

(cherry picked from commit f3f7f77dbc5a32f19069ef347b3ce5dc36525351)
2024-11-24 22:42:15 -05:00
Timothy Flynn 0446c98053 LibWeb: Convert some sync tests to be async
The events tested here are decidedly async. We also can't really write
sync tests of the form "test(async () => {})". Nothing will await the
async callback.

(cherry picked from commit c9cbaeb59d6f699b33bf3924688987b3ca917fee)
2024-11-24 22:42:15 -05:00
Timothy Flynn 8b4b8d914c LibWeb: Port some manually async tests to use asyncTest
These tests were mostly async tests written in a manual way. This ports
them to use the standard asyncTest() infrastructure.

This is mostly just to reduce calls to internals.signalTextTestIsDone,
which will have a required parameter in an upcoming test.

(cherry picked from commit 96082d6ae127832eb9b644d2abee892284317b6a)
2024-11-24 22:42:15 -05:00
Timothy Flynn db0a80b219 WebContent+WebDriver: Handle when new windows are immediately closed
This happens when window.close() is invoked immediately upon a window
being opened.

(cherry picked from commit ce11a907263670a326ccb4a9625bfeaa65dac937)
2024-11-24 21:30:22 -05:00
Timothy Flynn 09dfa66fe3 LibWeb: Mark a BC's navigable as destroyed if it does not exist
(cherry picked from commit 84df1bf585de217ccf3399e31708af96c95bb9fe)
2024-11-24 21:30:22 -05:00
Timothy Flynn 943697d35c LibWeb+WebDriver+WebContent: Implement the Element Click endpoint
(cherry picked from commit 5aa50bff8b2b82c34cfaa09de32f3162d36b2a24)
2024-11-24 21:30:22 -05:00
Timothy Flynn b849b99313 WebContent: Do not wait for navigations on BCs that have no navigable
This avoids a crash seen in WPT when a click event is fired on a BC that
has been removed from the document.

(cherry picked from commit 95bf6c98779bbb879b19319884389148e8cd2fd2)
2024-11-24 21:30:22 -05:00
Timothy Flynn 8da4c4db65 WebContent: Separately store the WebDriver parent and top-level BCs
We are currently trying to access the current parent and top-level
browsing contexts from the current BC itself. However, if the current BC
is closed, its association to the parent and top-level BCs is lost, and
we are no longer able to handle WebDriver endpoints involving those BCs.

Instead, let's store the parent and top-level BCs separately, and update
them in accordance with the spec.

(cherry picked from commit ab3cfd9bbb3d572d2e1ce4337e112d10ac0e94a3)
2024-11-24 21:30:22 -05:00
Timothy Flynn ec4fd77063 WebDriver: Allow deleting sessions with an invalid window handle
This case was missed in commit b5aa8f65b168c668e41ce61c966dae8198e233ed.

(cherry picked from commit 969361abdb73dce664933d0250ab90ed668bc0b6)
2024-11-24 21:30:22 -05:00
Timothy Flynn 6cbfce87bd LibWeb+LibWebView: Set the default path for invalid cookie Path values
We were missing this spec step when parsing the Path attribute.

(cherry picked from commit e74d2b17620b1d68d66d51a13831ee1657154a1c)
2024-11-24 21:30:22 -05:00
Timothy Flynn 8ada1255c3 LibWeb: Support cookie Max-Age attributes that exceed i64 limits
Attributes have a max value length of 1024. So we theoretically need to
support values in the range -${"9".repeat(1023)} to ${"9".repeat(1024)}.
These obviously do not fit in an i64, so we were previously failing to
parse the attribute.

We will now cap the parsed value to the numeric limits of an i64, after
ensuring that the attribute value is indeed a number.

(cherry picked from commit ba1189cd1c47ab0593e0c3d7eee85e7aafc3462d)
2024-11-24 21:30:22 -05:00
Timothy Flynn f77006b470 WebContent: Search all known navigables when WebDriver switches windows
We were only looking at the current top-level navigable and its children
when searching for the specified window handle. We need to search *all*
known navigables if the handle belongs to a window not in the current
tree.

(cherry picked from commit 47e9357243c5e561576d03ed8d1c444076847272)
2024-11-24 21:30:22 -05:00
Timothy Flynn be261d9978 WebContent: Implement the Release Actions endpoint
(cherry picked from commit b3f8d633724e3fc7b6d460eaab34d20939b0fa38)
2024-11-24 19:40:10 -05:00
Timothy Flynn bb58a048fc LibWeb+WebContent+WebDriver: Implement the Perform Actions endpoint
Similar to script execution, this spins the WebDriver process until the
action is complete (rather than spinning the WebContent process, which
we've seen result in deadlocks).

(cherry picked from commit 709deeb482a6433abbcb194551788bc5409166f4)
2024-11-24 19:40:10 -05:00
Timothy Flynn c5502d324c LibWeb: Implement WebDriver pointer action execution
This implements execution of the pointer up, pointer down, and pointer
move actions.

This isn't 100% complete. Pointer move actions are supposed to break
the move into iterations over the specified duration, which we currently
do not do.

(cherry picked from commit 8000837f7821fe9854156c7ae1349d37c77e89b2)
2024-11-24 19:40:10 -05:00
Timothy Flynn 612ea34f87 LibWeb: Implement WebDriver action extraction
There's a lot of parsing involved in action extraction. So this patch
implements only that - actually executing actions will be a future
patch.

(cherry picked from commit 6cf7d07a989bb6d7ddc897a444053deef7192c9c)
2024-11-24 19:40:10 -05:00
Timothy Flynn 3173273712 LibWeb: Begin implementing the WebDriver Input State and Input Source
These concepts are rather tightly coupled. This implements the types and
AOs needed to handle the Perform Actions endoint.

(cherry picked from commit 0c98c7637e1daa572a29e6cce7ca703452873264)
2024-11-24 19:40:10 -05:00
Timothy Flynn f93a00718b LibWeb+WebContent: Partially implement WebDriver's JSON deserialize AO
In particular, we need to convert web element references to the actual
element. The AO isn't fully implemented because we will need to work out
mixing JsonValue types with JS value types, which currently isn't very
straight forward with our JSON clone algorithm.

(cherry picked from commit 94c243acd6873a9fd9115f1467093326392f06c0)
2024-11-24 19:40:10 -05:00
Timothy Flynn 92c2db3690 LibWeb: Ensure numbers provided to WebDriver are "safe"
Numbers are limited to JS's Number.MAX_SAFE_INTEGER.

(cherry picked from commit 434663b1c60a125e9f29c31953339e5f90530d03)
2024-11-24 19:40:10 -05:00
Timothy Flynn 7f780adc60 LibWeb: Add a few more helpers to extract WebDriver properties
(cherry picked from commit 71c1a1d8f4d5b482f371804b852546ba9f8911c7)
2024-11-24 19:40:10 -05:00
Timothy Flynn ace5be75eb LibWeb+WebContent: Move WebDriver property extraction to a helper file
This will be needed outside of WebContent.

(cherry picked from commit 8944c6db3f84ed72f5f2f18bf39b103492a21493)
2024-11-24 19:40:10 -05:00
Timothy Flynn c5106e1531 LibWeb: Add helpers to convert a MouseButton to/from its DOM event code
Move the helper to convert MouseButton to its DOM event code to a public
header. And add a helper to convert in the opposite direction.

(cherry picked from commit 5e99715377cad26174344b9cca3e3cb8a7eb93ad)
2024-11-24 19:40:10 -05:00
Timothy Flynn b529e1a0a1 LibWeb: Form the correct representation of a WebDriver element reference
We are currently returning a JSON object of the form:

    {
        "name": "element-6066-11e4-a52e-4f735466cecf",
        "value": "foo"
    }

Instead, we are expected to return an object of the form:

    {
        "element-6066-11e4-a52e-4f735466cecf": "foo"
    }

(cherry picked from commit 157d41bb0dae1ab3b04e079a72184b99f2137c5c)
2024-11-24 19:40:10 -05:00
Timothy Flynn 44d9c5117f WebContent: Return the handle of the newly opened window from New Window
We were returning the handle of the already opened window, rather than
the handle of the window we just opened.

(cherry picked from commit 6cba55893e6cd5be39b2f8597970380e7f08b006)
2024-11-24 17:29:26 -05:00
Timothy Flynn 47497fa4fe LibWeb: Break the Window open steps into two methods for internal use
Some callers (namely WebDriver) will need access to the navigable opened
by these steps. But if the noopener parameter is set, the returned proxy
will always be null.

This splits some of the Window open steps into an internal method that
returns the chosen navigable.

(cherry picked from commit 981aaba96cd6ee752d9cf76595731612898fe05c)
2024-11-24 17:29:26 -05:00
Timothy Flynn cdb413600e LibWeb: Implement getting a known connected element closer to the spec
Namely, we must always return NoSuchError invalid element IDs, and we
must handle stale elements.

(cherry picked from commit 92a37b3b1a62cf8ed6bc942229cb77bce01ec815)
2024-11-24 17:29:26 -05:00
Timothy Flynn cc36dfb039 WebContent: Create a temporary execution context to parse WebDriver JSON
(cherry picked from commit 264b2827cd024752c11f0d955cfdcae4cd1674c7)
2024-11-24 17:29:26 -05:00