Commit Graph

354 Commits

Author SHA1 Message Date
Andrew Kaster
d90a9ab70c LibWeb: Add Web::UIEvents::KeyCode and KeyModifier enums, drop Kernel
This was the last Kernel header we had. Move the definitions we need
into a UIEvents header similar to MouseButton.
2024-06-07 09:44:41 +02:00
Tim Ledbetter
c79041344d LibWeb: Ensure anchor node is not null when extending selection
Previously, clicking while holding shift without having previously made
any text selection would cause a crash.
2024-06-05 13:57:01 -04:00
Tim Ledbetter
f721230456 LibWeb: Extend text selection when left clicking and holding shift 2024-06-05 11:51:41 -04:00
Aliaksandr Kalenik
94eacf6da7 LibWeb: Remove did_request_scroll_to IPC call
No longer used after moving scrollbar painting into WebContent.
2024-06-05 07:03:42 +02:00
Aliaksandr Kalenik
cc3d95a356 LibWeb: Remove did_request_scroll IPC call
No longer used after moving scrollbar painting into WebContent.
2024-06-05 07:03:42 +02:00
Aliaksandr Kalenik
5285e22f2a LibWeb+WebContent: Move scrollbar painting into WebContent
The main intention of this change is to have a consistent look and
behavior across all scrollbars, including elements with
`overflow: scroll` and `overflow: auto`, iframes, and a page.

Before:
- Page's scrollbar is painted by Browser (Qt/AppKit) using the
  corresponding UI framework style,
- Both WebContent and Browser know the scroll position offset.
- WebContent uses did_request_scroll_to() IPC call to send updates.
- Browser uses set_viewport_rect() to send updates.

After:
- Page's scrollbar is painted on WebContent side using the same style as
  currently used for elements with `overflow: scroll` and
  `overflow: auto`. A nice side effects: scrollbars are now painted for
  iframes, and page's scrollbar respects scrollbar-width CSS property.
- Only WebContent knows scroll position offset.
- did_request_scroll_to() is no longer used.
- set_viewport_rect() is changed to set_viewport_size().
2024-06-05 07:03:42 +02:00
Andreas Kling
09980af4ea LibWeb: Add Web::UIEvents::MouseButton enum, drop dependency on LibGUI
This was the only thing LibWeb needed from LibGUI, and we can just
duplicate the enum in LibWeb and get rid of a bogus dependency.
2024-06-02 20:24:42 +02:00
Timothy Flynn
b01e810a89 LibWeb+LibWebView+WebContent: Support case-insensitive find-in-page
This allows searching for text with case-insensitivity. As this is
probably what most users expect, the default behavior is changes to
perform case-insensitive lookups. Chromes may add UI to change the
behavior as they see fit.
2024-06-01 07:37:54 +02:00
Tim Ledbetter
7aea87c9df LibWeb+LibWebView+WebContent: Add basic find in page functionality
This allows the browser to send a query to the WebContent process,
which will search the page for the given string and highlight any
occurrences of that string.
2024-05-30 16:30:11 +02:00
Aliaksandr Kalenik
b8d18ebcf7 LibWeb+WebContent: Change event loop to synchronously paint next frame
...instead of scheduling repaint timer in PageClient.

This change fixes flickering on Discord that happened because:
- Event loop schedules repainting by activating repaint timer
- `Document::tear_down_layout_tree()` destroys paintable tree
- Repaint timer invokes callback and renders an empty frame because
  paintable tree was destroyed
2024-05-28 18:21:18 +02:00
Andreas Kling
3945e1a82a LibJS: Make JS::Cell a Weakable
This makes things easier downstream of Cell, and is preparation for
using weak pointers in prototype chain property caches.
2024-05-04 21:42:59 +02:00
Andreas Kling
0ebfc0a4c4 LibWeb: Move event handling & cursor from BrowsingContext to Navigable
This was a long standing FIXME since the introduction of navigables.
2024-04-26 20:01:58 +02:00
Timothy Flynn
c4750f6eec LibWeb: Run page activation behavior when skipping context menu events
We partially supported this feature, but not enough for the chrome's
context menu to open. We now propagate the event back to the chrome.
2024-04-26 09:50:48 +02:00
Andrew Kaster
5e1d678bae Ladybird+Userland: Remove use of unnecessary fd passing socket concept
Now that LibIPC is using SCM_RIGHTS properly, we can go back to only
having one socket laying around when needing to transfer fds to peers.
2024-04-19 16:38:55 -04:00
Andrew Kaster
6d4ba21832 LibIPC+Userland: Make IPC::File always own its file descriptor
Add factory functions to distinguish between when the owner of the File
wants to transfer ownership to the new IPC object (adopt) or to send a
copy of the same fd to the IPC peer (clone).

This behavior is more intuitive than the previous behavior. Previously,
an IPC::File would default to a shallow clone of the file descriptor,
only *actually* calling dup(2) for the fd when encoding or it into an
IPC MessageBuffer. Now the dup(2) for the fd is explicit in the clone_fd
factory function.
2024-04-19 06:34:07 -04:00
Timothy Flynn
9c608b46fd LibWeb+LibWebView+WebContent: Remove now-unused history change IPC 2024-04-14 18:53:58 -07:00
Aliaksandr Kalenik
c96fc902ff LibWeb+LibWebView+WebContent: Add did_change_url() IPC call 2024-04-14 02:42:53 -07:00
Aliaksandr Kalenik
a8cf1aca7c LibWeb: Rename did_update_url() to did_history_api_push_or_replace()
The previous name was extremely misleading, because the call is used for
pushing or replacing new session history entry on chrome side instead of
only changing URL.
2024-04-14 02:42:53 -07:00
Aliaksandr Kalenik
461184d964 LibWeb+LibWebView+WebContent: Add did_update_navigation_buttons_state()
It is going to be used to communicate whether it is possible to navigate
back or forward after session history stored on browser side will no
longer be used to driver navigation.
2024-04-14 02:42:53 -07:00
Aliaksandr Kalenik
0c839f0421 LibWeb+LibWebView+WebContent: Add traverse_history_by_delta() IPC call 2024-04-14 02:42:53 -07:00
Aliaksandr Kalenik
bfef08177e LibWeb+LibWebView+WebContent: Add an IPC call for Navigable::reload() 2024-04-14 02:42:53 -07:00
Aliaksandr Kalenik
649f70db65 LibWeb+WebContent: Initialise JS console from Document::initialize()
Before this change JS console was initialise from
activate_history_entry() which is too late for about:blank documents
that are ready to run scripts immediately after creation.
2024-04-11 18:41:20 +02:00
Andrew Kaster
29b12cb449 LibWeb: Add a workaround for excessive memory usage in Page::load_html 2024-04-10 17:17:58 -06:00
Matthew Olsson
31341b280a LibWeb: Add calls to JS_{DECLARE,DEFINE}_ALLOCATOR() 2024-04-09 09:13:06 +02:00
Bastiaan van der Plaat
4408581ee0 LibWeb: Refactor SelectItem to allow selecting options without value
Currently the `<select>` dropdown IPC uses the option value attr to
find which option is selected. This won't work when options don't
have values or when multiple options have the same value. Also the
`SelectItem` contained so weird recursive structures that are
impossible to create with HTML. So I refactored `SelectItem` as a
variant, and gave the options a unique id. The id is send back to
`HTMLSelectElement` so it can find out exactly which option element
is selected.
2024-04-08 17:24:48 -04:00
Timothy Flynn
f61f55d397 LibWeb+LibWebView+WebContent: Support muting an entire page
This adds an IPC for chromes to mute a tab. When muted, we trigger an
internal volume change notification and indicate that the user agent has
overriden the media volume.
2024-03-30 19:28:20 +01:00
Timothy Flynn
7c31343df0 LibWeb: Store the ID of all media elements on a page
This will be used to inform the media elements when the user has muted
the page.
2024-03-30 19:28:20 +01:00
Timothy Flynn
8b1ad5c496 LibWeb+LibWebView+WebContent: Add a new IPC for modifying history state
Let's not re-invoke the "page did start loading" IPC when the history
state is pushed/replaced. It's a bit misleading (the change does not
actually load the new URL), but also the chromes may do more work than
we want when we change the URL.

Instead, add a new IPC for the history object to invoke.
2024-03-29 08:52:01 -04:00
Timothy Flynn
1767f405dc LibWeb+LibWebView+WebContent: Convert URL declarations to east-const 2024-03-29 08:52:01 -04:00
Timothy Flynn
40c0dd81d2 LibWeb+LibWebView+WebContent: Inform chromes when audio is played/paused
Most browsers have some indicator when audio is playing in a tab, which
makes it easier to find that tab and mute unwanted audio. This adds an
IPC to allow the Ladybird chromes to do something similar.
2024-03-28 21:08:23 +01:00
Timothy Flynn
5424135d81 LibWeb: Remove unnecessary trailing semi-colons from Page.h
These should be caught by clang-format (via the RemoveSemicolon option),
but it does not seem to get these.
2024-03-28 21:08:23 +01:00
Aliaksandr Kalenik
561e011e07 LibWeb+WebContent+Ladybird: Add ability to paste text from clipboard
Text can be pasted by pressing Ctrl/Cmd+V or by using button in the
context menu. For now only the Qt client is supported.
2024-03-22 15:47:33 -04:00
Aliaksandr Kalenik
e3e6af39bc LibWeb: Add basic implementation of has_a_rendering_opportunity()
Return true only if we are ready to repaint. This fixes the issue where
requestAnimationFrame() was invoked more than once between repaints.
2024-03-19 07:54:14 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling
dd8504c68d LibWeb: Store "text for rendering" in TextPaintable
Instead of TextPaintable fragments being an offset+length view into the
layout node, they are now a view into the paintable instead.

This removes an awkward time window where we'd have bogus state in text
fragments after layout invalidation but before relayout. It also makes
the code slightly nicer in general, since there's less mixing of layout
and painting concepts.
2024-03-18 13:42:16 +01:00
Andreas Kling
a7d7c5b7b4 LibWeb: Don't force relayout after every keyboard input event
Instead, just rely on the invalidation and lazy relayout that happens as
a consequence of mutating the DOM.

This allows multiple keystrokes to coalesce into a single relayout if
necessary, dramatically improving performance when typing text into
form fields on complex pages.
2024-03-18 13:42:16 +01:00
Aliaksandr Kalenik
0afbd827e0 LibWeb: Skip page scrolling for wheel events consumed by scrollable box
Leftover from 90879a07ba
2024-03-17 09:33:16 +01:00
Timothy Flynn
a386ebde02 LibWeb: Do not return after ignoring a key event on an editable node
We do not want to blindly say we handled the key event. Otherwise, the
chrome is unable to handle shortcuts while an editable node is focused.
2024-03-17 09:32:37 +01:00
Timothy Flynn
4a476c3dd5 LibWeb: Ignore key presses when the OS super key is also pressed
Most shortcuts on macOS are activated with the super (command) key. For
now, we should ignore these like we ignore ctrl key modifiers.
2024-03-17 09:32:37 +01:00
Timothy Flynn
6760d236e4 Ladybird+LibWeb+WebContent: Parse the <input type=file> accept attribute
This parses the accept attribute value for file input types and passes
it along to the browser chromes.
2024-03-16 08:42:33 +01:00
Timothy Flynn
baf359354b LibWebView+WebContent: Use Web::InputEvent for WebContent input IPC
Now that all input events are handled by LibWebView, replace the IPCs
which send the fields of Web::KeyEvent / Web::MouseEvent individually
with one IPC per event type (key or mouse).

We can also replace the ad-hoc queued input structure with a smaller
struct that simply holds the tranferred Web::KeyEvent / Web::MouseEvent.

In the future, we can also adapt Web::EventHandler to use these structs.
2024-03-06 07:46:18 +01:00
Timothy Flynn
ea682207d0 LibWeb+LibWebView: Migrate Browser's input event handling to LibWebView
The Serenity chrome is the only chrome thus far that sends all input key
and mouse events to WebContent, including shortcut activations. This is
necessary for all chromes - we must give web pages a chance to intercept
input events before handling them ourselves.

To make this easier for other chromes, this patch moves Serenity's input
event handling to LibWebView. To do so, we add the Web::InputEvent type,
which models the event data we need within LibWeb. Chromes will then be
responsible for converting between this type and their native events.

This class lives in LibWeb (rather than LibWebView) because the plan is
to use it wholesale throughout the Page's event handler and across IPC.
Right now, we still send the individual fields of the event over IPC,
but it will be an easy refactor to send the event itself. We just can't
do this until all chromes have been ported to this event queueing.

Also note that we now only handle key input events back in the chrome.
WebContent handles all mouse events that it possibly can. If it was not
able to handle a mouse event, there's nothing for the chrome to do (i.e.
there is no clicking, scrolling, etc. the chrome is able to do if the
WebContent couldn't).
2024-03-06 07:46:18 +01:00
Bastiaan van der Plaat
a2f101c10b LibWeb: Add input and textarea minlength and maxlength support 2024-03-03 10:02:30 -05:00
circl
3e3a200eee LibWeb: Do not issue change event for every update of color input
Per spec, the change event shall only be issued once the change is
finally committed by the user, IE by closing the color picker window.
2024-03-03 08:42:41 +01:00
Andreas Kling
d1b5f55f91 LibWeb: Make Paintable::containing_block() return a PaintableBox*
Every single client of this function was immediately calling paintable()
on the result anyway, so there was no need to return a layout node!

This automatically leverages the cached containing block pointer we
already have in Paintable, which melts away a bunch of unnecessary
traversal in hit testing and painting. :^)
2024-03-01 17:57:10 +01:00
Aliaksandr Kalenik
90879a07ba LibWeb: Skip page scrolling for wheel events consumed by scrollable box
Fixes the bug when we scroll both scrollable box and page.
2024-02-29 13:18:57 +01:00
Timothy Flynn
108521a566 LibWeb+LibWebView+WebContent: Implement more <input type=file> behavior
We had previous implemented some plumbing for file input elements in
commit 636602a54e.

This implements the return path for chromes to inform WebContent of the
file(s) the user selected. This patch includes a dummy implementation
for headless-browser to enable testing.
2024-02-26 14:18:49 +01:00
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Aliaksandr Kalenik
d3f8d24abb LibWeb+WebContent: Remove PageClient::page_did_invalidate()
...and schedule repainting directly from Navigable::set_needs_display()
bypassing PageClient.
2024-02-24 16:54:55 +01:00
Aliaksandr Kalenik
906ac71eca LibWeb: Fix crashing after input into empty contenteditable
Change `EventHandler::handle_keydown()` to no longer assume the cursor
position's node is always a `DOM::Text`. While this assumption holds
for `HTMLInputElement` that has a shadow DOM with a text node, an empty
`contenteditable` might not have any children. With this change,
`handle_keydown()` creates a new text node if the cursor position's
node is not a text node.
2024-02-24 08:09:01 +01:00