Implement Clipboard Event Api (#33576)

* implement ClipboardEvent interface

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* draft implementation of clipboard events

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* handle received clipboard events inside html elemtents

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* use rustdoc style

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix compilation errors due to rebase

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* update arboard crate

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* improve paste events

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* code cleanup

revert arboard crate's update, handle text only

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* restrict visibility of some methods to script crate

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* propagate CanGc argument

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* simplify handle_clipboard_msg

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* remove code duplication

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix potential borrow hazard

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* add clipboard_event pref, restore unit test code

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* retrict visibility of some document's methods

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* check if clipboardevent is trusted

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* enable clipboardevent

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix compilation for egl ports

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2025-01-15 20:45:29 +01:00 committed by GitHub
parent cd9e831e91
commit d470f219b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 581 additions and 26 deletions

View file

@ -12,8 +12,9 @@ use embedder_traits::Cursor;
use ipc_channel::ipc::IpcSender;
use keyboard_types::{CompositionEvent, KeyboardEvent};
use script_traits::{
AnimationTickType, CompositorEvent, GamepadEvent, LogEntry, MediaSessionActionType, Theme,
TraversalDirection, WebDriverCommandMsg, WindowSizeData, WindowSizeType,
AnimationTickType, ClipboardEventType, CompositorEvent, GamepadEvent, LogEntry,
MediaSessionActionType, Theme, TraversalDirection, WebDriverCommandMsg, WindowSizeData,
WindowSizeType,
};
use servo_url::ServoUrl;
@ -88,6 +89,8 @@ pub enum ConstellationMsg {
ReadyToPresent(Vec<WebViewId>),
/// Gamepad state has changed
Gamepad(GamepadEvent),
/// Inform the constellation of a clipboard event.
Clipboard(ClipboardEventType),
}
impl fmt::Debug for ConstellationMsg {
@ -134,6 +137,7 @@ impl ConstellationMsg {
ClearCache => "ClearCache",
ReadyToPresent(..) => "ReadyToPresent",
Gamepad(..) => "Gamepad",
Clipboard(..) => "Clipboard",
}
}
}

View file

@ -192,6 +192,8 @@ pub enum EmbedderMsg {
AllowUnload(IpcSender<bool>),
/// Sends an unconsumed key event back to the embedder.
Keyboard(KeyboardEvent),
/// Inform embedder to clear the clipboard
ClearClipboardContents,
/// Gets system clipboard contents
GetClipboardContents(IpcSender<String>),
/// Sets system clipboard contents
@ -256,6 +258,7 @@ pub enum CompositorEventVariant {
CompositionEvent,
IMEDismissedEvent,
GamepadEvent,
ClipboardEvent,
}
impl Debug for EmbedderMsg {
@ -269,6 +272,7 @@ impl Debug for EmbedderMsg {
EmbedderMsg::AllowUnload(..) => write!(f, "AllowUnload"),
EmbedderMsg::AllowNavigationRequest(..) => write!(f, "AllowNavigationRequest"),
EmbedderMsg::Keyboard(..) => write!(f, "Keyboard"),
EmbedderMsg::ClearClipboardContents => write!(f, "ClearClipboardContents"),
EmbedderMsg::GetClipboardContents(..) => write!(f, "GetClipboardContents"),
EmbedderMsg::SetClipboardContents(..) => write!(f, "SetClipboardContents"),
EmbedderMsg::SetCursor(..) => write!(f, "SetCursor"),

View file

@ -535,6 +535,31 @@ pub struct WheelDelta {
pub mode: WheelMode,
}
/// 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(String),
}
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",
}
}
}
/// Events from the compositor that the script thread needs to know about
#[derive(Debug, Deserialize, Serialize)]
pub enum CompositorEvent {
@ -574,6 +599,8 @@ pub enum CompositorEvent {
IMEDismissedEvent,
/// Connected gamepad state updated
GamepadEvent(GamepadEvent),
/// A clipboard action was requested
ClipboardEvent(ClipboardEventType),
}
impl From<&CompositorEvent> for CompositorEventVariant {
@ -588,6 +615,7 @@ impl From<&CompositorEvent> for CompositorEventVariant {
CompositorEvent::CompositionEvent(..) => CompositorEventVariant::CompositionEvent,
CompositorEvent::IMEDismissedEvent => CompositorEventVariant::IMEDismissedEvent,
CompositorEvent::GamepadEvent(..) => CompositorEventVariant::GamepadEvent,
CompositorEvent::ClipboardEvent(..) => CompositorEventVariant::ClipboardEvent,
}
}
}