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

@ -20,7 +20,6 @@ pub enum ScriptHangAnnotation {
ConstellationMsg,
DevtoolsMsg,
DocumentEvent,
DomEvent,
FileRead,
FormPlannedNavigation,
ImageCacheMsg,

View file

@ -8,16 +8,13 @@ use std::time::Duration;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::Epoch;
use embedder_traits::{
ClipboardEventType, Cursor, GamepadEvent, MediaSessionActionType, Theme, TraversalDirection,
};
use embedder_traits::{Cursor, InputEvent, MediaSessionActionType, Theme, TraversalDirection};
use ipc_channel::ipc::IpcSender;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use script_traits::{
AnimationTickType, CompositorEvent, LogEntry, WebDriverCommandMsg, WindowSizeData,
WindowSizeType,
AnimationTickType, LogEntry, WebDriverCommandMsg, WindowSizeData, WindowSizeType,
};
use servo_url::ServoUrl;
use webrender_traits::CompositorHitTestResult;
/// Messages to the constellation.
pub enum ConstellationMsg {
@ -34,10 +31,6 @@ pub enum ConstellationMsg {
GetFocusTopLevelBrowsingContext(IpcSender<Option<TopLevelBrowsingContextId>>),
/// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
/// Inform the constellation of a key event.
Keyboard(WebViewId, KeyboardEvent),
/// Inform the constellation of a composition event (IME).
IMECompositionEvent(CompositionEvent),
/// Whether to allow script to navigate.
AllowNavigationResponse(PipelineId, bool),
/// Request to load a page.
@ -70,8 +63,8 @@ pub enum ConstellationMsg {
FocusWebView(TopLevelBrowsingContextId),
/// Make none of the webviews focused.
BlurWebView,
/// Forward an event to the script task of the given pipeline.
ForwardEvent(PipelineId, CompositorEvent),
/// Forward an input event to an appropriate ScriptTask.
ForwardInputEvent(InputEvent, Option<CompositorHitTestResult>),
/// Requesting a change to the onscreen cursor.
SetCursor(WebViewId, Cursor),
/// Enable the sampling profiler, with a given sampling rate and max total sampling duration.
@ -82,12 +75,6 @@ pub enum ConstellationMsg {
MediaSessionAction(MediaSessionActionType),
/// Set whether to use less resources, by stopping animations and running timers at a heavily limited rate.
SetWebViewThrottled(TopLevelBrowsingContextId, bool),
/// Virtual keyboard was dismissed
IMEDismissed,
/// Gamepad state has changed
Gamepad(GamepadEvent),
/// Inform the constellation of a clipboard event.
Clipboard(ClipboardEventType),
}
impl fmt::Debug for ConstellationMsg {
@ -106,8 +93,6 @@ impl ConstellationMsg {
GetPipeline(..) => "GetPipeline",
GetFocusTopLevelBrowsingContext(..) => "GetFocusTopLevelBrowsingContext",
IsReadyToSaveImage(..) => "IsReadyToSaveImage",
Keyboard(..) => "Keyboard",
IMECompositionEvent(..) => "IMECompositionEvent",
AllowNavigationResponse(..) => "AllowNavigationResponse",
LoadUrl(..) => "LoadUrl",
TraverseHistory(..) => "TraverseHistory",
@ -123,16 +108,13 @@ impl ConstellationMsg {
FocusWebView(..) => "FocusWebView",
BlurWebView => "BlurWebView",
SendError(..) => "SendError",
ForwardEvent(..) => "ForwardEvent",
ForwardInputEvent(..) => "ForwardEvent",
SetCursor(..) => "SetCursor",
ToggleProfiler(..) => "EnableProfiler",
ExitFullScreen(..) => "ExitFullScreen",
MediaSessionAction(..) => "MediaSessionAction",
SetWebViewThrottled(..) => "SetWebViewThrottled",
IMEDismissed => "IMEDismissed",
ClearCache => "ClearCache",
Gamepad(..) => "Gamepad",
Clipboard(..) => "Clipboard",
}
}
}

View file

@ -12,7 +12,7 @@ use base::id::{PipelineId, TopLevelBrowsingContextId};
use base::Epoch;
pub use constellation_msg::ConstellationMsg;
use crossbeam_channel::{Receiver, Sender};
use embedder_traits::{EventLoopWaker, MouseButton, MouseEventType};
use embedder_traits::{EventLoopWaker, MouseButton, MouseButtonAction};
use euclid::Rect;
use ipc_channel::ipc::IpcSender;
use log::warn;
@ -93,7 +93,7 @@ pub enum CompositorMsg {
/// The load of a page has completed
LoadComplete(TopLevelBrowsingContextId),
/// WebDriver mouse button event
WebDriverMouseButtonEvent(MouseEventType, MouseButton, f32, f32),
WebDriverMouseButtonEvent(MouseButtonAction, MouseButton, f32, f32),
/// WebDriver mouse move event
WebDriverMouseMoveEvent(f32, f32),

View file

@ -0,0 +1,219 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use keyboard_types::{CompositionEvent, KeyboardEvent};
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
pub use webrender_api::units::DevicePoint;
/// An input event that is sent from the embedder to Servo.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum InputEvent {
EditingAction(EditingActionEvent),
Gamepad(GamepadEvent),
Ime(ImeEvent),
Keyboard(KeyboardEvent),
MouseButton(MouseButtonEvent),
MouseMove(MouseMoveEvent),
Touch(TouchEvent),
Wheel(WheelEvent),
}
/// An editing action that should be performed on a `WebView`.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum EditingActionEvent {
Copy,
Cut,
Paste,
}
impl InputEvent {
pub fn point(&self) -> Option<DevicePoint> {
match self {
InputEvent::EditingAction(..) => None,
InputEvent::Gamepad(..) => None,
InputEvent::Ime(..) => None,
InputEvent::Keyboard(..) => None,
InputEvent::MouseButton(event) => Some(event.point),
InputEvent::MouseMove(event) => Some(event.point),
InputEvent::Touch(event) => Some(event.point),
InputEvent::Wheel(event) => Some(event.point),
}
}
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct MouseButtonEvent {
pub action: MouseButtonAction,
pub button: MouseButton,
pub point: DevicePoint,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum MouseButton {
Left,
Middle,
Right,
Back,
Forward,
Other(u16),
}
impl From<u16> for MouseButton {
fn from(value: u16) -> Self {
match value {
0 => MouseButton::Left,
1 => MouseButton::Middle,
2 => MouseButton::Right,
3 => MouseButton::Back,
4 => MouseButton::Forward,
_ => MouseButton::Other(value),
}
}
}
impl From<MouseButton> for i16 {
fn from(value: MouseButton) -> Self {
match value {
MouseButton::Left => 0,
MouseButton::Middle => 1,
MouseButton::Right => 2,
MouseButton::Back => 3,
MouseButton::Forward => 4,
MouseButton::Other(value) => value as i16,
}
}
}
/// The types of mouse events
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize)]
pub enum MouseButtonAction {
/// Mouse button clicked
Click,
/// Mouse button down
Down,
/// Mouse button up
Up,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct MouseMoveEvent {
pub point: DevicePoint,
}
/// The type of input represented by a multi-touch event.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum TouchEventAction {
/// A new touch point came in contact with the screen.
Down,
/// An existing touch point changed location.
Move,
/// A touch point was removed from the screen.
Up,
/// The system stopped tracking a touch point.
Cancel,
}
/// An opaque identifier for a touch point.
///
/// <http://w3c.github.io/touch-events/#widl-Touch-identifier>
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TouchId(pub i32);
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct TouchEvent {
pub action: TouchEventAction,
pub id: TouchId,
pub point: DevicePoint,
}
/// Mode to measure WheelDelta floats in
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum WheelMode {
/// Delta values are specified in pixels
DeltaPixel = 0x00,
/// Delta values are specified in lines
DeltaLine = 0x01,
/// Delta values are specified in pages
DeltaPage = 0x02,
}
/// The Wheel event deltas in every direction
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct WheelDelta {
/// Delta in the left/right direction
pub x: f64,
/// Delta in the up/down direction
pub y: f64,
/// Delta in the direction going into/out of the screen
pub z: f64,
/// Mode to measure the floats in
pub mode: WheelMode,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct WheelEvent {
pub delta: WheelDelta,
pub point: DevicePoint,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ImeEvent {
Composition(CompositionEvent),
Dismissed,
}
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
/// Index of gamepad in list of system's connected gamepads
pub struct GamepadIndex(pub usize);
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The minimum and maximum values that can be reported for axis or button input from this gamepad
pub struct GamepadInputBounds {
/// Minimum and maximum axis values
pub axis_bounds: (f64, f64),
/// Minimum and maximum button values
pub button_bounds: (f64, f64),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The haptic effects supported by this gamepad
pub struct GamepadSupportedHapticEffects {
/// Gamepad support for dual rumble effects
pub supports_dual_rumble: bool,
/// Gamepad support for trigger rumble effects
pub supports_trigger_rumble: bool,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The type of Gamepad event
pub enum GamepadEvent {
/// A new gamepad has been connected
/// <https://www.w3.org/TR/gamepad/#event-gamepadconnected>
Connected(
GamepadIndex,
String,
GamepadInputBounds,
GamepadSupportedHapticEffects,
),
/// An existing gamepad has been disconnected
/// <https://www.w3.org/TR/gamepad/#event-gamepaddisconnected>
Disconnected(GamepadIndex),
/// An existing gamepad has been updated
/// <https://www.w3.org/TR/gamepad/#receiving-inputs>
Updated(GamepadIndex, GamepadUpdateType),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The type of Gamepad input being updated
pub enum GamepadUpdateType {
/// Axis index and input value
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-axis>
Axis(usize, f64),
/// Button index and input value
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-button>
Button(usize, f64),
}

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
pub mod input_events;
pub mod resources;
use std::fmt::{Debug, Error, Formatter};
@ -11,7 +12,7 @@ use base::id::{PipelineId, WebViewId};
use crossbeam_channel::Sender;
use http::{HeaderMap, Method, StatusCode};
use ipc_channel::ipc::IpcSender;
use keyboard_types::KeyboardEvent;
pub use keyboard_types::{KeyboardEvent, Modifiers};
use log::warn;
use malloc_size_of_derive::MallocSizeOf;
use num_derive::FromPrimitive;
@ -19,6 +20,8 @@ use serde::{Deserialize, Serialize};
use servo_url::ServoUrl;
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
pub use crate::input_events::*;
/// A cursor for the window. This is different from a CSS cursor (see
/// `CursorKind`) in that it has no `Auto` value.
#[repr(u8)]
@ -250,29 +253,12 @@ pub enum EmbedderMsg {
OnDevtoolsStarted(Result<u16, ()>, String),
/// Ask the user to allow a devtools client to connect.
RequestDevtoolsConnection(IpcSender<AllowOrDeny>),
/// The given event was delivered to a pipeline in the given browser.
EventDelivered(WebViewId, CompositorEventVariant),
/// Request to play a haptic effect on a connected gamepad.
PlayGamepadHapticEffect(WebViewId, usize, GamepadHapticEffectType, IpcSender<bool>),
/// Request to stop a haptic effect on a connected gamepad.
StopGamepadHapticEffect(WebViewId, usize, IpcSender<bool>),
}
/// The variant of CompositorEvent that was delivered to a pipeline.
#[derive(Debug, Deserialize, Serialize)]
pub enum CompositorEventVariant {
ResizeEvent,
MouseButtonEvent,
MouseMoveEvent,
TouchEvent,
WheelEvent,
KeyboardEvent,
CompositionEvent,
IMEDismissedEvent,
GamepadEvent,
ClipboardEvent,
}
impl Debug for EmbedderMsg {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match *self {
@ -312,7 +298,6 @@ impl Debug for EmbedderMsg {
EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"),
EmbedderMsg::RequestDevtoolsConnection(..) => write!(f, "RequestDevtoolsConnection"),
EmbedderMsg::ShowContextMenu(..) => write!(f, "ShowContextMenu"),
EmbedderMsg::EventDelivered(..) => write!(f, "HitTestedEvent"),
EmbedderMsg::PlayGamepadHapticEffect(..) => write!(f, "PlayGamepadHapticEffect"),
EmbedderMsg::StopGamepadHapticEffect(..) => write!(f, "StopGamepadHapticEffect"),
}
@ -535,150 +520,6 @@ impl WebResourceResponse {
}
}
/// The type of input represented by a multi-touch event.
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum TouchEventType {
/// A new touch point came in contact with the screen.
Down,
/// An existing touch point changed location.
Move,
/// A touch point was removed from the screen.
Up,
/// The system stopped tracking a touch point.
Cancel,
}
/// An opaque identifier for a touch point.
///
/// <http://w3c.github.io/touch-events/#widl-Touch-identifier>
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TouchId(pub i32);
#[derive(
Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
/// Index of gamepad in list of system's connected gamepads
pub struct GamepadIndex(pub usize);
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The minimum and maximum values that can be reported for axis or button input from this gamepad
pub struct GamepadInputBounds {
/// Minimum and maximum axis values
pub axis_bounds: (f64, f64),
/// Minimum and maximum button values
pub button_bounds: (f64, f64),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The haptic effects supported by this gamepad
pub struct GamepadSupportedHapticEffects {
/// Gamepad support for dual rumble effects
pub supports_dual_rumble: bool,
/// Gamepad support for trigger rumble effects
pub supports_trigger_rumble: bool,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The type of Gamepad event
pub enum GamepadEvent {
/// A new gamepad has been connected
/// <https://www.w3.org/TR/gamepad/#event-gamepadconnected>
Connected(
GamepadIndex,
String,
GamepadInputBounds,
GamepadSupportedHapticEffects,
),
/// An existing gamepad has been disconnected
/// <https://www.w3.org/TR/gamepad/#event-gamepaddisconnected>
Disconnected(GamepadIndex),
/// An existing gamepad has been updated
/// <https://www.w3.org/TR/gamepad/#receiving-inputs>
Updated(GamepadIndex, GamepadUpdateType),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
/// The type of Gamepad input being updated
pub enum GamepadUpdateType {
/// Axis index and input value
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-axis>
Axis(usize, f64),
/// Button index and input value
/// <https://www.w3.org/TR/gamepad/#dfn-represents-a-standard-gamepad-button>
Button(usize, f64),
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub enum MouseButton {
/// The left mouse button.
Left = 1,
/// The right mouse button.
Right = 2,
/// The middle mouse button.
Middle = 4,
}
/// The types of mouse events
#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
pub enum MouseEventType {
/// Mouse button clicked
Click,
/// Mouse button down
MouseDown,
/// Mouse button up
MouseUp,
}
/// Mode to measure WheelDelta floats in
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub enum WheelMode {
/// Delta values are specified in pixels
DeltaPixel = 0x00,
/// Delta values are specified in lines
DeltaLine = 0x01,
/// Delta values are specified in pages
DeltaPage = 0x02,
}
/// The Wheel event deltas in every direction
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct WheelDelta {
/// Delta in the left/right direction
pub x: f64,
/// Delta in the up/down direction
pub y: f64,
/// Delta in the direction going into/out of the screen
pub z: f64,
/// Mode to measure the floats in
pub mode: WheelMode,
}
/// The mouse button involved in the event.
/// The types of clipboard events
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ClipboardEventType {
/// Contents of the system clipboard are changed
Change,
/// Copy
Copy,
/// Cut
Cut,
/// Paste
Paste,
}
impl ClipboardEventType {
/// Convert to event name
pub fn as_str(&self) -> &str {
match *self {
ClipboardEventType::Change => "clipboardchange",
ClipboardEventType::Copy => "copy",
ClipboardEventType::Cut => "cut",
ClipboardEventType::Paste => "paste",
}
}
}
/// The direction of a history traversal
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum TraversalDirection {

View file

@ -83,7 +83,6 @@ pub enum ProfilerCategory {
ScriptConstellationMsg = 0x61,
ScriptDevtoolsMsg = 0x62,
ScriptDocumentEvent = 0x63,
ScriptDomEvent = 0x64,
/// Rust tracing only: the script thread is executing a script.
/// This may include time doing layout or parse work initiated by the script.
@ -149,7 +148,6 @@ impl ProfilerCategory {
ProfilerCategory::ScriptConstellationMsg => "ScriptConstellationMsg",
ProfilerCategory::ScriptDevtoolsMsg => "ScriptDevtoolsMsg",
ProfilerCategory::ScriptDocumentEvent => "ScriptDocumentEvent",
ProfilerCategory::ScriptDomEvent => "ScriptDomEvent",
ProfilerCategory::ScriptEvaluate => "ScriptEvaluate",
ProfilerCategory::ScriptEvent => "ScriptEvent",
ProfilerCategory::ScriptFileRead => "ScriptFileRead",

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.