Commit Graph

40 Commits

Author SHA1 Message Date
webbeef
295e019d00 script: pointer events: pointerenter, pointerout, pointerleave, pointerover (#42736)
Adds support for more pointer events: pointerenter, pointerout,
pointerleave, pointerover
Also add global event handlers that were missing.

Testing: WPT expectations are updated.

cc @yezhizhen

Signed-off-by: webbeef <me@webbeef.org>
2026-03-03 08:27:53 +00:00
Martin Robinson
1d9d440b22 script: Add basic support for tab navigation (#42952)
This change adds very basic support for tab navigation, but without
support for focus scopes. Followup changes will refine the behavior of
this implementation to follow the specification around focus scopes,
shadow DOM, and slots. In particular `delegatesFocus` is not supported
here yet.

Testing: This causes quite a few WPT tests to start passing.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2026-03-02 20:42:25 +00:00
webbeef
4487e0222a script: Mark disabled elements pointed at and elements targets of touch events as :active (#42935)
This implements the "If the element is [being actively pointed
at](https://html.spec.whatwg.org/multipage/semantics-other.html#being-actively-pointed-at)"
part of
https://html.spec.whatwg.org/multipage/semantics-other.html#selector-active

Also added support for activation of controls tied to a `<label
for=...>` element as this is part of the same
`/html/semantics/selectors/pseudo-classes/active-disabled.html` WPT
test. We still fail the `<input disabled>` one because the hit test ends
up in a `<div>` of the input shadow DOM.

Testing: New WPT tests are passing
Fixes: Partial fix for https://github.com/servo/servo/issues/7333 and
https://github.com/servo/servo/issues/20284 (I think we still lack
support for the focusable elements).

---------

Signed-off-by: webbeef <me@webbeef.org>
2026-03-02 09:17:52 +00:00
Steven Novaryo
d70ab4e1c0 script: Merge ScrollEvent with SetScrollStates messages (#42834)
Remove embedder defined `ScrollEvent` and merge the payload of it to the
`SetScrollStates` message which tell the `ScriptThread` to update the
scroll state.

In the past, `ScrollEvent` is defined as a embedder's `InputEvent` and
being used only to forward the external scroll node id for a node that
is considered scrolled. This make us sends an additional message to
constellation and additionally, `ScrollEvent` went through lengthy
pipelines as it was deemed as an embedder input event, albeit being a
synthetic input fired by `WebviewRenderer`.

Subsequently, we could introduce a flag to detect whether the scrolling
is still ongoing or not (like whether it is still flinging) for
`scrollend` event.

Testing: No WPT changes

---------

Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2026-02-26 07:36:55 +00:00
Euclid Ye
75418e7ace script: Rectify update_active_touch_points_when_early_return (#42733)
- Use `FxHashMap` for `active_pointer_ids`
- Refactor and fix logging message for touch, especially
`update_active_touch_points_when_early_return`
- Randomly fix some typos

Testing: This changes logging message but no other observable
behaviours. The logging should be more accurate, but I didn't test.

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-02-22 13:08:19 +00:00
Euclid Ye
e98e4c9d30 script: Use touchstart element as event target for touchmove/touchend/touchcancel (#42654)
[Spec](https://w3c.github.io/touch-events/#dfn-touchend:~:text=screen%2E-,The,element,-%2E)
for touchmove/touchend/touchcancel:
> The target of this event must be the same Element on which the [touch
point](https://w3c.github.io/touch-events/#dfn-touch-point) started when
it was first placed on the surface, even if the [touch
point](https://w3c.github.io/touch-events/#dfn-touch-point) has since
moved outside the interactive area of the target element.

Also, previously `touchend` can be fired after `touchcancel`, which was
wrong and fixed in this PR.

Testing: Fully passes `/touch-events/multi-touch-interfaces.html` (511
subtests) and new passes in
`pointerevents\compat\pointerevent_touch_target_after_pointerdown_target_removed.tentative.html`.

We also take the chance to update `pointercancel` related tests
introduced in https://github.com/servo/servo/pull/41937: `touchcancel`
should not be followed by `touchend` according to
[spec](https://w3c.github.io/touch-events/#dfn-touchcancel).

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-02-20 09:42:43 +00:00
webbeef
39d946b01d script: Implement pointer events (#41290)
Remaining failures are due to the missing implementation of the pointer
capture and pointer lock APIs, as well as:

Requires User Activation support:
/html/user-activation/activation-trigger-pointerevent.html?mouse

Blocked on https://github.com/servo/servo/issues/41227 :
/pointerevents/compat/pointerevent_mouse-pointer-on-scrollbar.html

Requires persistentDeviceId:

/pointerevents/persistentDeviceId/get-persistendeviceid-from-pointer-event.tentative.html
/pointerevents/persistentDeviceId/get-persistendeviceid-from-pointer-mouse-event.tentative.html

Requires pointerenter, pointerover, pointerout, pointerleave events:
/pointerevents/pointerevent_pointerId_scope.html

Requires pointerrawupdate event:
/pointerevents/pointerevent_pointerrawupdate.html
/pointerevents/pointerevent_pointerrawupdate.https.html

Consider implementing non-standard attributes toElement and fromElement:
See https://w3c.github.io/pointerevents/#attributes-and-default-actions

Fails because the pointerId is always 0 for pointermove, maybe caused by
commit 7b00b54ee8 :
/pointerevents/pointerevent_pointermove_isprimary_same_as_pointerdown.html?touch
https://github.com/servo/servo/issues/41250


Testing: Updated wpt expectations
Fixes: https://github.com/servo/servo/issues/38435

Signed-off-by: webbeef <me@webbeef.org>
2026-02-10 07:44:59 +00:00
Euclid Ye
03d8d16748 paint: Track TouchId in PendingTouchInputEvent (#42468)
As you can tell from branch name, the initial goal is to add multi-touch
support for touchmove.
But things get too messy, so I decide to split into two PRs.

This PR
- Track `TouchId` in `PendingTouchInputEvent`
- Rename `id` to `touch_id` for `TouchId`. This is to make distinction
from `id: InputEventId`,
which became very confusing while implementing the initial goal.

Testing: No behaviour change.
Part of #41923

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2026-02-09 08:49:38 +00:00
Martin Robinson
983482b5f3 script: Ignore platform mouse move events that do not change the cursor location (#42034)
winit on macOS seems to send a mousemove event right before mouse button
up events. This interferes with interactive use of text boxes -- for
instance double-clicking to select the hovered word. This change makes
it so
that mouse move events that do not change the cursor location are
ignored.

Testing: This change adds a Servo-specific WPT-style test.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-01-20 18:30:59 +00:00
Martin Robinson
8e7249b625 script: Set MouseEvent properties according to the UI Events specification (#42013)
The UI Events specification has a table of UIEvents which describes the
properties that they must have. Importantly, this includes whether the
event should bubble, be cancelable, and be composed. The code was not
following this specification, so this changes centralizes where they are
set.

In addition, it makes the code that finds the event target consistent
with whether or not it is `ShadowIncluding`.

Finally the `MouseEvent` constructors are renamed so that it is clear
what they are used for.

Testing: This change causes one WPT test to start passing.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-01-19 21:17:04 +00:00
Martin Robinson
3cda70dbbb script: Include click count as the detail of mouseup and mousedown events (#41833)
This change improves the counting of clicks for mouse button events by
ensuring that `detail` property of those events includes the click
count. This `detail` differs from that of `dblclick` events where the
`detail` is always 2. In addition, it ensures that the click count can
increase for mouse buttons that do not cause `click` and `dblclick`
events (such as the right mouse button).

Testing: This change adds two Servo-specific WPT-style tests. While this
behavior is specified a bit, the details are implementation specific.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-01-12 08:47:20 +00:00
Narfinger
46011ff50c Script: Convert routed_promise to GenericCallback (#41380)
This changes routed_promise to use the GenericCallback functionality.
This mostly effected WebGPU but also Clipboard and Memory Reporting.

We also added a GenericCallback::new_blocking() functionality which
produces a callback and a channel
which then can be blocked on. This was used a couple of times in the
code.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: This should not change functionality.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2026-01-09 10:09:45 +00:00
WaterWhisperer
6623cc1dbb feat: gamepad feature flag (#41451)
Put the Gamepad API and its supporting infrastructure behind a `gamepad`
feature flag. This allows embedders to opt-out of gamepad support at
compile time to save on binary size and reduce dependencies.

Testing:
1. `./mach build -d` (Gamepad enabled by default)
2. `cargo build -p servoshell --no-default-features --features
"libservo/clipboard,js_jit,max_log_level,webgpu"` (Gamepad Disabled)
3. `cargo build -p servoshell --features "gamepad,webxr,..."` (Gamepad &
WebXR Enabled)

Fixes: #40897

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-12-21 13:18:06 +00:00
Taym Haddadi
25a626cf3d script: retarget dblclick from input UA shadow DOM to host (#41319)
dblclick on text inputs was being dispatched to an internal element used
for the input, not to the <input> itself. As a result, page scripts
listening for dblclick on the input never received the event.

Testing: tested manually.
Fixes: #41303

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-12-18 13:09:35 +00:00
Martin Robinson
824f551f03 Rename IOCompositor to Paint (#41176)
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.

`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.

Testing: This just renames types and updates comments, so no new tests
are necessary.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-12-10 15:09:49 +00:00
Martin Robinson
5494995e01 libservo: Add ContextMenuElementInformation to for the context menu API (#40607)
This new data structure allows passing more information when popping up
context menus. It's possible in the future that it will be adapted into
a more generic "hit test result" type API ala WebKit, but for now, this
is probably
enough.

Testing: This change includes new API test assertions.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-17 15:53:43 +00:00
Simon Wülker
a1269e809d Replace calls to ".filter_map()" followed by ".next()" with ".find_map()" (#40612)
The two are semantically equivalent, but `find_map` is more concise.

Testing: Covered by existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-13 14:53:57 +00:00
Martin Robinson
1e4feeaa0d script: Add context-based context menu options (#40501)
Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.

Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2025-11-11 11:03:41 +00:00
WaterWhisperer
158bf97e30 script/dom/: Change some #[allow]s to #[expect]s (#40454)
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.

Testing: Refactor
Part of: #40383

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-06 11:06:03 +00:00
Martin Robinson
2c77d9d8a1 libservo: Integrate context menu into the show_embedder_control API (#40402)
This PR integrates showing context menus into the
`WebViewDelegate::show_embedder_control` API. In addition,
`ContextMenuItem` and `ContextMenuAction` data types are exposed which
abstract away the different components of the context menu. Later
changes will implement this API for servoshell as well as add
element-specific actions such as "Select All" and "Copy Image URL".

Testing: This change adds a WebView API test.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: atbrakhi <atbrakhi@igalia.com>
2025-11-04 21:08:04 +00:00
Martin Robinson
4551e9dfe3 script: Have the renderer process root viewport handle keyboard scrolling (#40108)
When scrolling the root viewport of a WebView (the top level frame),
ask the renderer to process that event. This allows keyboard scrolling
to pan the pinch zoom viewport. This is important for moving around a
pinch zoomed WebView via the keyboard.

Testing: The changes this makes to panning are hard to test, since we
have no way of retrieving the pinch zoom viewport values from Servo,
but the normal scrolling is tested by a servodriver test which is still
passing with these changes.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
2025-10-24 12:28:50 +00:00
Narfinger
18cac42406 Script: len,is_empty and match for DOMString (#39866)
This replaces the implementation of is_empty and len with more efficient
representation without conversion
and allocation based on the underlying bytes.
For this we use a new view, EncodedBytesView.
Additionally, we implement a new macro `match_domstring_ascii!` which
allows simple match clauses
matching ascii strings with DOMStrings without conversion/allocation.
The macro will panic in debug builds if the strings are non-ascii but
will not match all DOMStrings correctly.
We replaced the usage of `DOMString::str()` in many places with this
macro.


Testing: len and is_empty were already covered by tests.
match_domstring_ascii! has more unit tests added with this PR.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-10-23 14:02:28 +00:00
Martin Robinson
f004e69cd9 compositor: Remove the CompositorMsg::TouchEventProcessed message (#39811)
The renderer needs needs to know when touch events processing has
finished in the DOM in order to properly handle them. This was
previously done using the `CompositorMsg::TouchEventProcessed` message.
This message is now redudant with the general-purpose
`EmbedderMsg::InputEventHandled` message.

This change removes the former message and instead, has the
`TouchHandler` keep a `HashMap` of pending touch events which is uses to
finish their processing when they come back from script. The goal here
is reduce the number of messages sent and to keep the complexity of
touch handling more centered in the `TouchHandler`.

Testing: This should not change observable behavior, so is covered by
existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-17 13:51:04 +00:00
Martin Robinson
3721fbd0fe script: Combine all Event flags into a single bitflags (#39740)
This makes the management of flags conceptually simpler and reduces the
number of instance variables in the `Event` data structure.

Testing: This should not change behavior so should be covered by
existing tests.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-11 10:27:23 +00:00
Martin Robinson
12e5d1b05e libservo: Unify notifications to the embedder that input events are handled (#39720)
Servo currently has three ways of notifying the embedder that input
events have been processed.

1. `WebViewDelegate::notify_keyboard_event`: This is used to implement
   overridable keybindings in servoshell. It notifies the embedder when
   a keyboard event has been processed, but not "handled" by the engine.
2. WebDriver's command message senders and receivers, this is used to
   let WebDriver wait until events have been handled to continue with
   script execution.
3. Touch event processing notifications: This is used to serialize touch
   event processing.

This change unifies the first two things with a new
`WebViewDelegate::notify_input_event_handled` API. This API informs the
embedder (via a generated id) that an input event has finished
processing and what the result of the processing was.

This allows embedders to do other things with events once they have been
processed. For example, embedders might want to chain unconsumed events
up to parent widgets or to add support for overridable keybindings.

As part of this the `canceled` flag in script's `Event` data structure
is turned into a `bitflags` mirror of the new API type to describe the
result of event handling.

Testing: This shouldn't change observable behavior and is thus covered
by existing tests.
The new API is consumed by servoshell, which uses it for tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-10 07:48:06 +00:00
Narfinger
423800eec4 Script: Lazily transform the DOMString into Rust String instead of immediately. (#39509)
This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.

We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.

Testing: WPT tests still seem to work, so this should test this
functionality.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-10-09 18:18:03 +00:00
Martin Robinson
fbbdce2e59 libservo: Remove MouseButtonAction::Click from the API (#39705)
The embedder should never be responsible for triggering click events, so
this change removes that possibility from the API. In addition,
triggering of click events is simplified by moving the logic to the
`DocumentEventHandler`. This has the benefit of making behavior
consistent between in-process and out-of-process `<iframe>`s. Now click
events are never triggered when the button up and down cross frame
boundaries.

Testing: This should be covered by existing tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-10-07 13:08:20 +00:00
Martin Robinson
ffdb7d3663 script: Chain up keyboard scrolling to parent <iframe>s (#39469)
When an `<iframe>` cannot scroll because the size of the frame is
greater than or
equal to the size of page contents, chain up the keyboard scroll
operation to the parent frame.

Testing: A new Servo-only WPT tests is added, though needs to be
manually
run with `--product servodriver`.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Delan Azabani <dazabani@igalia.com>
2025-09-25 11:16:41 +00:00
shuppy
ac8895c3ae script: Move keyboard scrolling to script (#39371)
Instead of having every single embedder implement keyboard scrolling,
handle it in script in the default key event handler. This allows
properly targeting the scroll events to their scroll containers as well
as appropriately sizing "page up" and "page down" scroll deltas.

This change means that when you use the keyboard to scroll, the focused
or most recently clicked `<iframe>` or overflow scroll container is
scrolled, rather than the main frame.

In addition, when a particular scroll frame is larger than its content
in the axis of the scroll, the scrolling operation is chained to
the parent (as in other browsers). One exception is for `<iframe>`s,
which will be implemented in a followup change.

Testing: automated tests runnable locally with `mach test-wpt --product
servodriver`

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-09-23 20:35:08 +00:00
Jo Steven Novaryo
b1ab72e589 Set composed flag for TouchEvent (#39138)
Following the definition of `TouchEvent` in
https://w3c.github.io/touch-events/#list-of-touchevent-types, all
`TouchEvent` should have its `composed` flag set to be able to propagate
past a shadow root layer.

Part of #35997
Testing: Would require a testdriver.

Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
2025-09-15 08:50:16 +00:00
Jonathan Schwender
f4dd2960b8 Add direct script to embedder channel (#39039)
This PR **removes** `ScriptToConstellationMessage::ForwardToEmbedder`,
and replaces it with an explicit `ScriptToEmbedderChannel`. This new
channel is based on `GenericCallback` and in single-process mode will
directly send the message the to the embedder and wake it. In
multi-process mode, the message is routed via the ROUTER, since waking
is only possible from the same process currently. This means in
multi-process mode there are likely no direct perf benefits, since we
still need to hop the message over the ROUTER (instead of over the
constellation).
In single-process mode we can directly send the message to the embedder,
which should provide a noticable latency improvement in all cases where
script is blocked waiting on the embedder to reply.

This does not change the way the embedder receives messages - the
receiving end is unchanged.

## How was sending messages to the embedder working before?

1. Script wraps it's message to the embedder in
`ScriptToConstellationMessage::ForwardToEmbedder` and sends it to
constellation.
2. The [constellation event loop] receives the message in
[handle_request]
3. If deserialization fails, [an error is logged and the message is
ignored]
4. Since our message came from script, it is handle in
[handle_request_from_script]
5. The message is logged with trace log level
6. If the pipeline is closed, [a warning is logged and the message
ignored]
7. The wrapped `EmbedderMsg` [is forwarded to the embedder]. Sending the
message also invokes `wake()` on the embedder eventloop waker.

[constellation event loop]:
2e1b2e7260/components/constellation/constellation.rs (L755)

[handle request]:
2e1b2e7260/components/constellation/constellation.rs (L1182)

[an error is logged and the message is ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1252)

[handle_request_from_script]:
https://github.com/servo/servo/blob/main/components/constellation/constellation.rs#L1590
 
[a warning is logged and the message ignored]:
2e1b2e7260/components/constellation/constellation.rs (L1599)

[is forwarded to the embedder]:
2e1b2e7260/components/constellation/constellation.rs (L1701)

Testing: Communication between Script and Embedder is extensive, so this
should be covered by existing tests.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-09-02 06:33:44 +00:00
Jonathan Schwender
66d9f957e6 EmbedderMsg: port reply channels to GenericChannel (#39018)
This change ports all `EmbedderMsg` reply channels that don't use the
`ROUTER` to GenericChannel.
The remaining reply channels that use the router are blocked until
#38973 is merged.
This is a breaking change in the API between libservo and embedders.

Future work: A lot of the reply channels in this PR look like they
conceptually should be oneshot ipc channels. It might make sense to
provide a `OneshotGenericChannel` abstraction that encodes this.

Testing: No functional changes - covered by existing tests. None of the
channels changed here uses the Router
Part of #38912

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-08-29 12:44:21 +00:00
Ashwin Naren
461ff26812 script: Move gamepad DOM interfaces to script/dom/gamepad/ (#38900)
Moves interfaces defined by the gamepad spec to the
`script/dom/gamepad/` module from `script/dom/`.

Testing: Just a refactor shouldn't need any testing
Fixes: N/A

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-08-27 18:39:27 +00:00
Martin Robinson
4784ff0375 script: Ensure that leaving the WebView sets the cursor back to the default cursor (#38759)
This changes makes a variety of changes to ensure that the cursor is set
back to the default cursor when it leaves the `WebView`:

1. Display list updates can come after a mouse leaves the `WebView`, so
   when refreshing the cursor after the update, base the updated cursor
   on the last hovered location in the `DocumentEventHandler`, rather
   than the compositor. This allows us to catch when the last hovered
   position is `None` (ie the cursor has left the `WebView`).
2. When handling `MouseLeftViewport` events for the cursor leaving the
   entire WebView, properly set the
   MouseLeftViewport::focus_moving_to_another_iframe` on the input event
   passed to the script thread.
3. When moving out of the `WebView` entirely, explicitly ask the
   embedder to set the cursor back to the default.

Testing: This change adds a unit test verifying this behavior.
Fixes: #38710.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-08-22 07:49:56 +00:00
Martin Robinson
8743a11ba4 tidy: Add a rule ensuring that // comments are followed by a space in Rust (#38698)
This shows up sometimes in code reviews, so it makes sense that tidy
enforces it. `rustfmt` supports this via comment normalization, but it
does many other things and is still an unstable feature (with bugs).

Testing: There are new tidy tests for this change.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-08-18 12:09:09 +00:00
Euclid Ye
494493ceb7 Rename InputEvent::MouseLeave to InputEvent::MouseLeftViewport (#38695)
1. `InputEvent::MouseLeave` indicates that mouse has left the viewport
(fired by embedder) or iframe (synthesized in Constellation
f24f225db8/components/constellation/constellation_webview.rs (L119-L122)).
Its handler in script is named as `handle_mouse_leave_event`, which is
very misleading as we have DOM event
[mouseleave](https://w3c.github.io/uievents/#event-type-mouseleave). I
rename it to `MouseLeftViewport` to be consistent with
`WindowEvent::CursorLeft`:
f24f225db8/ports/servoshell/desktop/headed_window.rs (L632-L638)
2. Add doc and rename function, such as `handle_mouse_move_event` to
`handle_native_mouse_move_event` to be closer to
[spec](https://w3c.github.io/uievents/#handle-native-mouse-move).

Testing: Just renaming + skipping unnecessary hit-test in simple case.
Fixes: Nothing but preparing for #38670 and #38435.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
2025-08-15 09:54:54 +00:00
Euclid Ye
dafb0abf31 script: Stop handling native mousedown and mouseup for disabled elements (#38671)
According to spec of
[hit-test](https://w3c.github.io/uievents/#hit-test) for native mouse
event, mousedown/mouseup should also be excluded when interacting with
disabled element, even tho it may be the frontmost of
[elementFromPoint](https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint).

Testing: Now it matches the behaviour of other browsers in #38670 for
disabled element. Also testdriver test:
`tests\wpt\tests\html\semantics\disabled-elements\disabled-event-dispatch.tentative.html`
has 4 more passing tests.
Fixes: Part of #38670.

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
2025-08-15 01:24:47 +00:00
Euclid Ye
cd3d982a2a script: Remove duplicate context menu trigger (#38669)
#38584 moves input event handling to new `DocumentEventHandler`, but
probably reintroduced some removed code when resolving conflict with
#38589.

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
2025-08-14 03:47:15 +00:00
Martin Robinson
069ad40872 script: Move the majority of the input event handling code to DocumentEventHandler (#38584)
This moves the majority of the input event handler code to the
`DocumentEventHandler` helper structure. It better encapsulates event
handling, hiding most of the details from both `ScriptThread` and
`Document`. The benefit here is that the majority of the functions can
become private and `Document` is over 1000 lines shorter.

Testing: This should not change any behavior so is covered by existing
WPT tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-08-13 09:38:58 +00:00
Martin Robinson
b75c3feb97 script/compositor: Send mouseleave events when cursor moves between <iframe>s (#38539)
Properly send `mouseleave` events when the cursor moves between
`<iframe>`s. This allows a better handling of cursor changes and status
text updates. Specifically, we do not need to continuously update the
cursor and the value can be cached in the `Document`. In addition,
status updates can now be sent properly when moving focus between
`<iframe>`s.

Note that style updates for `:hover` values are still broken, but less
so than before. Now the hover state on the `Node` is updated, but for
some
reason the restyle isn't taking place properly. This maintains the
status quo as far as behavior goes when hover moves between `<iframe>`s.

This change also adds a helper data structure to `Document` which will
eventually be responsible for event handling.

Testing: Cursor and status change are currently very hard to test as
the API test harness makes this difficult at the moment.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-08-11 12:31:54 +00:00