libservo: Expose a single InputEvent type and pass it to script (#35430)

This change exposes a single `InputEvent` type and now there is only a
single delegate method for this `WebViewDelegate::notify_input_event`.

- Clipboard events are now handled as `EditingAction` inpute events. In
  the future this can include things like "Select All", etc.

In addition, many parts of the dance to pass these events can now be
simplified due to this abstraction.

- All forwarded events are handled the same way in the `Constellation`,
  though they may carry an optional hit test (for events that have a
  `point`) which affects which `Pipeline` they are sent to.
- In the `ScriptThread` we now accept these `InputEvents` and use them
  everywhere. Now all "compositor events" are "input events".
- This allows removing several data structures which are no longer
  necessary.
- We no longer inform the embedder when an event was handled by a
  WebView as that was only important for a MDI feature that will
  no longer be so important the full-featured `WebView` API.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Martin Robinson 2025-02-12 18:07:15 +01:00 committed by GitHub
parent b7b8619e87
commit 0908a47780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 921 additions and 1200 deletions

View file

@ -31,17 +31,14 @@ use bluetooth_traits::BluetoothRequest;
use canvas_traits::webgl::WebGLPipeline;
use crossbeam_channel::{RecvTimeoutError, Sender};
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg, WorkerId};
use embedder_traits::{
ClipboardEventType, CompositorEventVariant, GamepadEvent, MediaSessionActionType, MouseButton,
MouseEventType, Theme, TouchEventType, TouchId, WheelDelta,
};
use euclid::default::Point2D;
use embedder_traits::input_events::InputEvent;
use embedder_traits::{MediaSessionActionType, MouseButton, MouseButtonAction, Theme};
use euclid::{Rect, Scale, Size2D, UnknownUnit, Vector2D};
use http::{HeaderMap, Method};
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use ipc_channel::Error as IpcError;
use keyboard_types::webdriver::Event as WebDriverInputEvent;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use keyboard_types::KeyboardEvent;
use libc::c_void;
use log::warn;
use malloc_size_of::malloc_size_of_is_0;
@ -62,7 +59,8 @@ use webgpu::WebGPUMsg;
use webrender_api::units::{DeviceIntSize, DevicePixel, LayoutPixel};
use webrender_api::{DocumentId, ExternalScrollId, ImageKey};
use webrender_traits::{
CrossProcessCompositorApi, UntrustedNodeAddress as WebRenderUntrustedNodeAddress,
CompositorHitTestResult, CrossProcessCompositorApi,
UntrustedNodeAddress as WebRenderUntrustedNodeAddress,
};
pub use crate::script_msg::{
@ -315,7 +313,7 @@ pub enum ScriptThreadMessage {
/// Notifies the script that the whole thread should be closed.
ExitScriptThread,
/// Sends a DOM event.
SendEvent(PipelineId, CompositorEvent),
SendInputEvent(PipelineId, ConstellationInputEvent),
/// Notifies script of the viewport.
Viewport(PipelineId, Rect<f32, UnknownUnit>),
/// Requests that the script thread immediately send the constellation the title of a pipeline.
@ -422,7 +420,7 @@ impl fmt::Debug for ScriptThreadMessage {
UnloadDocument(..) => "UnloadDocument",
ExitPipeline(..) => "ExitPipeline",
ExitScriptThread => "ExitScriptThread",
SendEvent(..) => "SendEvent",
SendInputEvent(..) => "SendInputEvent",
Viewport(..) => "Viewport",
GetTitle(..) => "GetTitle",
SetDocumentActivity(..) => "SetDocumentActivity",
@ -476,64 +474,16 @@ pub enum AnimationState {
NoAnimationCallbacksPresent,
}
/// Events from the compositor that the script thread needs to know about
/// Input events from the embedder that are sent via the `Constellation`` to the `ScriptThread`.
#[derive(Debug, Deserialize, Serialize)]
pub enum CompositorEvent {
/// The window was resized.
ResizeEvent(WindowSizeData, WindowSizeType),
/// A mouse button state changed.
MouseButtonEvent(
MouseEventType,
MouseButton,
Point2D<f32>,
Option<UntrustedNodeAddress>,
Option<Point2D<f32>>,
// Bitmask of MouseButton values representing the currently pressed buttons
u16,
),
/// The mouse was moved over a point (or was moved out of the recognizable region).
MouseMoveEvent(
Point2D<f32>,
Option<UntrustedNodeAddress>,
// Bitmask of MouseButton values representing the currently pressed buttons
u16,
),
/// A touch event was generated with a touch ID and location.
TouchEvent(
TouchEventType,
TouchId,
Point2D<f32>,
Option<UntrustedNodeAddress>,
),
/// A wheel event was generated with a delta in the X, Y, and/or Z directions
WheelEvent(WheelDelta, Point2D<f32>, Option<UntrustedNodeAddress>),
/// A key was pressed.
KeyboardEvent(KeyboardEvent),
/// An event from the IME is dispatched.
CompositionEvent(CompositionEvent),
/// Virtual keyboard was dismissed
IMEDismissedEvent,
/// Connected gamepad state updated
GamepadEvent(GamepadEvent),
/// A clipboard action was requested
ClipboardEvent(ClipboardEventType),
}
impl From<&CompositorEvent> for CompositorEventVariant {
fn from(value: &CompositorEvent) -> Self {
match value {
CompositorEvent::ResizeEvent(..) => CompositorEventVariant::ResizeEvent,
CompositorEvent::MouseButtonEvent(..) => CompositorEventVariant::MouseButtonEvent,
CompositorEvent::MouseMoveEvent(..) => CompositorEventVariant::MouseMoveEvent,
CompositorEvent::TouchEvent(..) => CompositorEventVariant::TouchEvent,
CompositorEvent::WheelEvent(..) => CompositorEventVariant::WheelEvent,
CompositorEvent::KeyboardEvent(..) => CompositorEventVariant::KeyboardEvent,
CompositorEvent::CompositionEvent(..) => CompositorEventVariant::CompositionEvent,
CompositorEvent::IMEDismissedEvent => CompositorEventVariant::IMEDismissedEvent,
CompositorEvent::GamepadEvent(..) => CompositorEventVariant::GamepadEvent,
CompositorEvent::ClipboardEvent(..) => CompositorEventVariant::ClipboardEvent,
}
}
pub struct ConstellationInputEvent {
/// The hit test result of this input event, if any.
pub hit_test_result: Option<CompositorHitTestResult>,
/// The pressed mouse button state of the constellation when this input
/// event was triggered.
pub pressed_mouse_buttons: u16,
/// The [`InputEvent`] itself.
pub event: InputEvent,
}
/// Data needed to construct a script thread.
@ -717,7 +667,7 @@ pub enum WebDriverCommandMsg {
/// Act as if keys were pressed or release in the browsing context with the given ID.
KeyboardAction(BrowsingContextId, KeyboardEvent),
/// Act as if the mouse was clicked in the browsing context with the given ID.
MouseButtonAction(MouseEventType, MouseButton, f32, f32),
MouseButtonAction(MouseButtonAction, MouseButton, f32, f32),
/// Act as if the mouse was moved in the browsing context with the given ID.
MouseMoveAction(f32, f32),
/// Set the window size.