Commit graph

126 commits

Author SHA1 Message Date
Jelle Raaijmakers
2a2f8ef90b LibWeb+UI: Support triple clicking and dragging paragraphs
When triple clicking on text, we should select the entire paragraph, or
entire line in <input>s and <textarea>s. If the mouse button is held
down and the user starts dragging, the selection expands with additional
paragraphs or lines.

This expands on the work of Kai Wildberger (PR #7681) but was adjusted
for the work that happened previously to support double click + drag
moves and includes triple click support for our Qt UI.

Co-authored-by: Kai Wildberger <kiawildberger@gmail.com>
2026-02-06 14:18:10 +00:00
Jelle Raaijmakers
7f8d052b7e LibWeb: Support double click word selection dragging
In EventHandler, we now keep track of a mouse selection mode which is
either None, Character or Word. By double clicking a word and
immediately dragging, you can now extend the selection word by word
instead of by character.
2026-02-06 14:18:10 +00:00
Aliaksandr Kalenik
2738f6c9c6 LibWeb: Fix double-inversion of visual viewport transform
The AccumulatedVisualContext tree already handles the visual viewport
transform for hit testing (via transform_point_for_hit_test) and offset
computation (via inverse_transform_point). Passing viewport_position
(which has map_to_layout_viewport already applied) to these functions
caused a double-inversion during pinch-to-zoom.
2026-01-31 19:20:09 +01:00
Aliaksandr Kalenik
24c08b7d42 LibWeb: Fix mouse event offset computation with nested CSS transforms
compute_mouse_event_offset() only inverted the target element's own CSS
transform, ignoring ancestor transforms. This caused incorrect offsetX/
offsetY values when elements were nested inside transformed parents.

Use AccumulatedVisualContext::inverse_transform_point() to invert the
full ancestor transform chain instead.
2026-01-31 16:56:05 +01:00
Tim Ledbetter
74ca89017c LibWeb: Use insertLineBreak input type for form controls on Enter key
This matches the behavior of other engines.
2026-01-31 13:30:33 +01:00
Jelle Raaijmakers
e05503dbcb LibWeb: Send InputEvent with right .inputType on insert and delete
Applies to `<input>` and `<textarea>`. Editing commands in
`contenteditable` already sent the right events and input types.

Fixes #7668
2026-01-29 15:08:06 +01:00
Tim Ledbetter
e04446802f LibWeb: Implement label activation behavior in the DOM layer
Previously, click handling for labels was handled in layout and
painting code. This change implements activation_behavior on
HTMLLabelElement, which clicks and focuses the element.
2026-01-27 18:35:38 +01:00
Jelle Raaijmakers
746362e5de LibWeb: Handle WebDriver special keys and Mod_Keypad in keyboard events
Add webdriver_key_to_key_code() in Internals.cpp to properly translate
WebDriver special key codes (0xE000-0xE05D) to KeyCode values with
appropriate modifiers. This ensures keys like Enter, Backspace, and
arrow keys are handled correctly when sent via Internals::send_text().

In EventHandler::handle_keydown(), strip Mod_Keypad when determining
Enter key behavior since it only indicates key location (numpad vs
standard keyboard), not a behavior change. The modifier is still passed
through to KeyboardEvent for the location property.

This gains us 656 WPT subtest passes in `editing`.
2026-01-23 14:21:35 +01:00
Jelle Raaijmakers
da01b0c389 LibWeb: Insert newlines for line breaks in preformatted white-space
When inserting a line break in a contenteditable with preformatted
white-space (pre, pre-line, pre-wrap), insert a newline character (\n)
instead of a <br> element. Use <br> only for padding at end of line to
ensure the cursor can be placed on the new line.
2026-01-23 14:21:35 +01:00
Tim Ledbetter
f8d6314db6 LibWeb: Account for scroll offset in iframe mouse event coordinates
When delegating mouse events to iframes, coordinate transformations
were not accounting for scroll offsets. This caused clicks inside
iframes to be incorrectly positioned when the parent page was scrolled.
2026-01-19 06:22:18 +01:00
Gingeh
37c33c8215 LibWeb: Don't crash when clicking on display: contents element 2026-01-16 10:11:07 +01:00
Jonathan Gamble
8f1cb4cbb0 LibWeb: Implement resizing for eligible elements and update scrollbars
Add ElementResizeAction to Page (maybe there's a better place). It's
just a mousemove delegate that updates styles on the target element.

Add ChromeMetrics for zoom-invariant chrome like scrollbar thumb
thickness, resize gripper size, paddings, etc. It's not user-stylable
but separates basic concerns in a way that a visually gifted
designer unlike myself can adjust to taste.

These values are pre-divided by zoom factor so that PaintableBox can
continue using device_pixels_per_css_pixel calls as normal.

The adjusted metrics are computed on demand from Page multiple times
per paint cycle, which is not ideal but avoids lifetime management and
atomics. Maybe someone with more surety about the painting flow control
can improve this, but it won't be a huge win. If profiling shows
this slowing paints, then Ladybird is in good shape.

Update PaintableBox to draw the resize gripper and deconflict
the scrollbars. Set apropriate cursors for scrollbars and gripper in
mousemove. We override EventHandler's cursor handling because nothing
should ever come between a man and his resize gripper.

Chrome metrics use the CSSPixels class. This is good because it's
broadly compatible but bad because they're actually different units
when zoom is not 1.0. If that's a problem, we could make a new type
or just use double.
2026-01-12 11:00:14 +00:00
Jonathan Gamble
f84e6f8acf LibWeb: Make input controls relinquish focus on outside clicks
Model "viewport focus" with Document::focused_area == nullptr.

Focus.cpp:
  When a blur occurs, remove the document entry from the old chain
  before running the focusing steps. This ensures the document atop the
  new chain is not discarded. Focus::run_focus_update_steps will then
  set focused_area to nullptr, indicating viewport focus.

EventHandler.cpp:
  Split hit testing in handle_mousedown. Use an exact hit test for
  focus/blur decisions, and a subsequent cursor hit test for
  selection/caret.
2026-01-09 18:09:09 +01:00
Jonathan Gamble
ed568fcada LibWeb: Reduce nesting in handle_mousedown. No functional changes 2026-01-09 18:09:09 +01:00
Sam Atkins
8a0ba904b9 LibWeb/HTML: Return Promises from Window scroll methods
A version of this was added in a610639119
and reverted in 70671b4c11. The bugs
there (confusing scroll-to-position and scroll-by-delta, and not having
an execution context in some cases) have been fixed in this version.
2026-01-08 14:50:09 +00:00
Andreas Kling
a9cc425cde LibJS+LibWeb: Add missing GC marking visits
This adds visit_edges(Cell::Visitor&) methods to various helper structs
that contain GC pointers, and makes sure they are called from owning
GC-heap-allocated objects as needed.

These were found by our Clang plugin after expanding its capabilities.
The added rules will be enforced by CI going forward.
2026-01-07 12:48:58 +01:00
Tim Ledbetter
70671b4c11 Revert "LibWeb/HTML: Return Promises from Window scroll methods"
This reverts commit a610639119.
2025-12-26 19:33:51 +01:00
Aliaksandr Kalenik
8af78cff30 LibWeb: Skip scroll promise allocation in mouse event handling
Fixes crashing introduced in a610639 when `scroll_viewport_by_delta()`
is called from `EventHandler::handle_mousewheel()` and there's no
running execution context to grab current realm from to allocate a
promise.
2025-12-23 17:36:48 +01:00
Sam Atkins
a610639119 LibWeb/HTML: Return Promises from Window scroll methods
Corresponds to part of:
c548a9a1d4
2025-12-23 14:24:28 +01:00
Timothy Flynn
96806a3f90 LibWeb: Update cursor and tooltip UI state regardless of event handlers
If a script on the page cancels a mousemove event, we would return early
and neglect to update the cursor. This is seen regularly on "Diablo Web"
where they set the cursor to "none" on the main canvas, and also cancel
mousemove events.
2025-12-03 12:23:56 +01:00
InvalidUsernameException
28ba610f32 Everywhere: Avoid large rebuilds when editing (Immutable)Bitmap headers
This reduces the number of recompiled files as follow:
- Bitmap.h: 1309 -> 101
- ImmutableBitmap.h: 1218 -> 75
2025-11-28 18:32:48 +01:00
Aliaksandr Kalenik
2a18b6b802 LibWeb: Prevent default on pointerdown/mousedown should skip focus steps
Fixes a bug in the ChatGPT model dropdown where clicking it immediately
closes the menu because focus is being stolen.
2025-11-21 08:30:32 +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
Timothy Flynn
2a68087dfc LibWeb: Do not assume hovered URLs are valid
Let's just not display any tooltip for invalid URLs. This matches how
Firefox behaves.
2025-10-27 14:15:03 +00:00
Luke Wilde
eeb5446c1b LibWeb: Avoid including Navigable.h in headers
This greatly reduces how much is recompiled when changing Navigable.h,
from >1000 to 82.
2025-10-20 10:16:55 +01:00
Aliaksandr Kalenik
9862d8b4a6 LibWeb: Implement pinch-to-zoom support
Adds pinch event handling that adjusts the VisualViewport scale and
offset. VisualViewport's (offset, scale) is then used to construct a
transformation matrix which is applied before display list execution.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
b477c6bfc4 LibWeb: Implement VisualViewport aware viewport scrolling
Implements spec algorithm for viewport scrolling that first checks if
it's possible to use delta to move the visual viewport before falling
back to scrolling the layout viewport. This is a part of pinch-to-zoom
support.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
83fb690bce LibWeb: Remove usage of layout_node() in dom_node_for_event_dispatch
No need to go through layout node when paintable has a direct pointer to
the DOM node.
2025-10-10 09:03:39 +02:00
Luke Wilde
f44e42d27c LibWeb: Don't drop mouse wheel events sent to subframes unless handled
Otherwise scrolling gets stuck when you scroll over a non-scrollable
subframe.
2025-10-07 19:43:07 +02:00
Aliaksandr Kalenik
c5da92f664 LibWeb: Try to dispatch wheel event on hit-testing target first
...before falling back to containing block. Fixes a bug when we can't
scroll innermost scrollable element, because wheel event dispatching
immediately falls back to containing block.
2025-10-03 19:34:20 +02:00
Timothy Flynn
efa9311527 LibWeb+WebContent+UI: Port text pasting to UTF-16 2025-09-19 06:38:52 -04:00
Louis Dalibard
660bcfa2cd LibGfx+LibWeb+UI: Add OpenHand cursor for CSS grab property 2025-09-13 14:27:18 +02:00
Jelle Raaijmakers
d1076c1e6e LibWeb: Remove text storage from TextPaintable
Instead of copying the layout node's text, retrieve the text from the
layout node directly.
2025-09-12 15:34:09 -04:00
ayeteadoe
454e6a6f7f LibWeb/Gamepad: Forward declare SDL components to fix Windows build
We have to prevent from including any SDL headers in LibWeb headers.
Otherwise there will be transitive Windows.h includes that will
re-declare some of our existing forward decls/defines in
LibCore/SocketAddressWindows.h
2025-09-02 11:11:12 +01:00
Luke Wilde
74e0483ea5 LibWeb: Implement the Gamepad API with SDL3 2025-09-01 21:10:47 +02:00
Luke Wilde
b17783bb10 Everywhere: Change west consts caught by clang-format-21 to east consts 2025-08-29 18:18:55 +01:00
Jelle Raaijmakers
518c048eb4 LibWeb+WebContent: Rename Document::focused_element to ::focused_area
And make it a DOM::Node, not DOM::Element. This makes everything flow
much better, such as spec texts that explicitly mention "focused area"
as the fact that we don't necessarily need to traverse a tree of
elements, since a Node can be focusable as well.

Eventually this will need to be a struct with a separate "focused area"
and "DOM anchor", but this change will make it easier to achieve that.
2025-08-26 10:25:59 +02:00
Tim Ledbetter
83b1ead1e7 LibWeb: Ensure UIEventInit.view is set for mouse and pointer events 2025-08-20 09:13:32 +02:00
mikiubo
23aadc02ca LibWeb: Implement up/down arrow navigation in textarea 2025-08-15 06:32:11 -04:00
Timothy Flynn
76bab90812 LibWeb: Use rendered text to find word boundaries when double-clicking
This effectively reverts da26941b50.

When the user double-clicks a word on screen, they are interacting with
the rendered text, which has e.g. whitespace collapsing applied. If we
acquire word boundaries from the raw text, the resulting selection is
not right.

We still have issues with acquiring the right selection via APIs such as
`document.getSelection`. The offsets computed here are effectively then
applied to the raw text. But this issue is present all over EventHandler
and this patch at least makes the selection visually accurate.
2025-08-14 19:36:38 +02:00
Timothy Flynn
57b5df21c7 LibWeb: Select the entire input when double clicking password fields
This matches the behavior of other browsers, and hides any indication
of word boundaries in the password.
2025-08-10 11:05:49 +02:00
Andreas Kling
74722cc499 LibWeb: Use the soon-to-be hovered element for tooltip notifications
Instead of the currently hovered element.
2025-08-06 17:26:18 +01:00
Andreas Kling
b60d465029 LibWeb: Defer updating hovered node until end of mouse event handling
Updating the hovered node may fire events, and so we can't assume the
layout and paintable nodes we've found via hit testing will be valid
after doing it.
2025-08-05 11:29:45 +02:00
Andreas Kling
7e06906157 LibWeb: Use GC::Ptr more instead of raw pointers in EventHandler
Gives us nicer stack traces in debug builds.
2025-08-05 11:29:45 +02:00
Tim Ledbetter
4a1740f299 LibWeb: Ensure image context menu uses the correct image source
Previously, the value of the `src` tag would always be used as the
image source URL when requesting an image context menu, which may not
be correct if an image uses a `srcset` or has a parent picture tag.
2025-08-03 17:33:06 +02:00
Jelle Raaijmakers
0cab272f7f LibWeb: Change Editing::editing_host_of_node() to Node::editing_host()
No functional changes.
2025-08-01 10:09:26 +02:00
Timothy Flynn
67cc02ab59 LibWeb+UI: Add an explicit IPC to handle mouse leave events
The faux position we created here is adjusted by the device pixel ratio
later on, which would invoke integer overflow on screens with a DPR
greater than 1.

Instead of creating special data for a mouse move event, let's just add
an explicit leave event handler.
2025-07-28 21:26:33 +02:00
Timothy Flynn
2da615ed31 LibWeb: Port document.execCommand and InputEvent to UTF-16 2025-07-26 00:40:06 +02:00
Timothy Flynn
017a6cc687 LibWeb+WebContent: Port FormAssociatedTextControlElement APIs to UTF-16 2025-07-26 00:40:06 +02:00
Luke Wilde
a2f3a5a6ce LibWeb: Send a beforeinput event for pasting
This allows us to paste text into Discord.
2025-07-23 22:04:45 +02:00