mirror of
https://github.com/servo/servo.git
synced 2025-08-15 10:25:32 +01:00
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:
parent
cd9e831e91
commit
d470f219b1
24 changed files with 581 additions and 26 deletions
|
@ -156,6 +156,7 @@ mod from_servo {
|
|||
Self::WebViewBlurred => target!("WebViewBlurred"),
|
||||
Self::AllowUnload(..) => target!("AllowUnload"),
|
||||
Self::Keyboard(..) => target!("Keyboard"),
|
||||
Self::ClearClipboardContents => target!("ClearClipboardContents"),
|
||||
Self::GetClipboardContents(..) => target!("GetClipboardContents"),
|
||||
Self::SetClipboardContents(..) => target!("SetClipboardContents"),
|
||||
Self::SetCursor(..) => target!("SetCursor"),
|
||||
|
@ -236,6 +237,7 @@ mod to_servo {
|
|||
Self::ReplaceNativeSurface(..) => target!("ReplaceNativeSurface"),
|
||||
Self::Gamepad(..) => target!("Gamepad"),
|
||||
Self::Vsync => target!("Vsync"),
|
||||
Self::ClipboardAction(..) => target!("ClipboardAction"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ use servo::embedder_traits::{
|
|||
};
|
||||
use servo::ipc_channel::ipc::IpcSender;
|
||||
use servo::script_traits::{
|
||||
GamepadEvent, GamepadIndex, GamepadInputBounds, GamepadSupportedHapticEffects,
|
||||
GamepadUpdateType, TouchEventType, TraversalDirection,
|
||||
ClipboardEventType, GamepadEvent, GamepadIndex, GamepadInputBounds,
|
||||
GamepadSupportedHapticEffects, GamepadUpdateType, TouchEventType, TraversalDirection,
|
||||
};
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_api::units::DeviceRect;
|
||||
|
@ -483,6 +483,23 @@ where
|
|||
Duration::from_secs(duration),
|
||||
))
|
||||
})
|
||||
.shortcut(CMD_OR_CONTROL, 'X', || {
|
||||
Some(EmbedderEvent::ClipboardAction(ClipboardEventType::Cut))
|
||||
})
|
||||
.shortcut(CMD_OR_CONTROL, 'C', || {
|
||||
Some(EmbedderEvent::ClipboardAction(ClipboardEventType::Copy))
|
||||
})
|
||||
.shortcut(CMD_OR_CONTROL, 'V', || {
|
||||
Some(EmbedderEvent::ClipboardAction(ClipboardEventType::Paste(
|
||||
self.clipboard
|
||||
.as_mut()
|
||||
.and_then(|clipboard| clipboard.get_text().ok())
|
||||
.unwrap_or_else(|| {
|
||||
warn!("Error getting clipboard text. Returning empty string.");
|
||||
String::new()
|
||||
}),
|
||||
)))
|
||||
})
|
||||
.shortcut(Modifiers::CONTROL, Key::F9, || {
|
||||
Some(EmbedderEvent::CaptureWebRender)
|
||||
})
|
||||
|
@ -850,6 +867,11 @@ where
|
|||
EmbedderMsg::Keyboard(key_event) => {
|
||||
self.handle_key_from_servo(webview_id, key_event);
|
||||
},
|
||||
EmbedderMsg::ClearClipboardContents => {
|
||||
self.clipboard
|
||||
.as_mut()
|
||||
.and_then(|clipboard| clipboard.clear().ok());
|
||||
},
|
||||
EmbedderMsg::GetClipboardContents(sender) => {
|
||||
let contents = self
|
||||
.clipboard
|
||||
|
|
|
@ -644,7 +644,8 @@ impl ServoGlue {
|
|||
EmbedderMsg::ReportProfile(..) |
|
||||
EmbedderMsg::EventDelivered(..) |
|
||||
EmbedderMsg::PlayGamepadHapticEffect(..) |
|
||||
EmbedderMsg::StopGamepadHapticEffect(..) => {},
|
||||
EmbedderMsg::StopGamepadHapticEffect(..) |
|
||||
EmbedderMsg::ClearClipboardContents => {},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue