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

@ -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",
}
}
}