mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
libservo: Add a ClipboardDelegate
and a default implementation (#35297)
Add a `ClipboardDelegate` to the `WebView` API and a default implementation in libservo for this delegate that works on Mac, Windows, and Linux. Support for Android will be added in the future. This means that embedders do not need to do anything special to get clipboard support, but can choose to override it or implement it for other platforms. In addition, this adds support for handling fetches of clipboard contents and renames things to reflect that eventually other types of clipboard content will be supported. Part of this is removing the string argument from the `ClipboardEventType::Paste` enum because script will need to get other types of content from the clipboard than just a string. It now talks to the embedder to get this information directly. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
b5b69988cc
commit
19e41ab9f9
20 changed files with 212 additions and 127 deletions
|
@ -7,11 +7,13 @@ use embedder_traits::EmbedderMsg;
|
|||
use ipc_channel::ipc::channel;
|
||||
use script_traits::{ScriptMsg, ScriptToConstellationChan};
|
||||
|
||||
/// A trait which abstracts access to the embedder's clipboard in order to allow unit
|
||||
/// testing clipboard-dependent parts of `script`.
|
||||
pub trait ClipboardProvider {
|
||||
// blocking method to get the clipboard contents
|
||||
fn clipboard_contents(&mut self) -> String;
|
||||
// blocking method to set the clipboard contents
|
||||
fn set_clipboard_contents(&mut self, _: String);
|
||||
/// Get the text content of the clipboard.
|
||||
fn get_text(&mut self) -> Result<String, String>;
|
||||
/// Set the text content of the clipboard.
|
||||
fn set_text(&mut self, _: String);
|
||||
}
|
||||
|
||||
pub(crate) struct EmbedderClipboardProvider {
|
||||
|
@ -20,20 +22,22 @@ pub(crate) struct EmbedderClipboardProvider {
|
|||
}
|
||||
|
||||
impl ClipboardProvider for EmbedderClipboardProvider {
|
||||
fn clipboard_contents(&mut self) -> String {
|
||||
fn get_text(&mut self) -> Result<String, String> {
|
||||
let (tx, rx) = channel().unwrap();
|
||||
self.constellation_sender
|
||||
.send(ScriptMsg::ForwardToEmbedder(
|
||||
EmbedderMsg::GetClipboardContents(self.webview_id, tx),
|
||||
))
|
||||
.send(ScriptMsg::ForwardToEmbedder(EmbedderMsg::GetClipboardText(
|
||||
self.webview_id,
|
||||
tx,
|
||||
)))
|
||||
.unwrap();
|
||||
rx.recv().unwrap()
|
||||
}
|
||||
fn set_clipboard_contents(&mut self, s: String) {
|
||||
fn set_text(&mut self, s: String) {
|
||||
self.constellation_sender
|
||||
.send(ScriptMsg::ForwardToEmbedder(
|
||||
EmbedderMsg::SetClipboardContents(self.webview_id, s),
|
||||
))
|
||||
.send(ScriptMsg::ForwardToEmbedder(EmbedderMsg::SetClipboardText(
|
||||
self.webview_id,
|
||||
s,
|
||||
)))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue