diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-02-07 11:43:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-07 10:43:46 +0000 |
commit | 19e41ab9f9b4217f5d07f8ab84a15e0454251a1a (patch) | |
tree | 4cffde4e7526bb46a4b32beb25502198017a54ba /components/script/textinput.rs | |
parent | b5b69988ccd68c70050225d75694ae9eb0bb95f7 (diff) | |
download | servo-19e41ab9f9b4217f5d07f8ab84a15e0454251a1a.tar.gz servo-19e41ab9f9b4217f5d07f8ab84a15e0454251a1a.zip |
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>
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r-- | components/script/textinput.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs index 9cffd6dede1..a2194b60751 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -890,20 +890,21 @@ impl<T: ClipboardProvider> TextInput<T> { }) .shortcut(CMD_OR_CONTROL, 'X', || { if let Some(text) = self.get_selection_text() { - self.clipboard_provider.set_clipboard_contents(text); + self.clipboard_provider.set_text(text); self.delete_char(Direction::Backward); } KeyReaction::DispatchInput }) .shortcut(CMD_OR_CONTROL, 'C', || { if let Some(text) = self.get_selection_text() { - self.clipboard_provider.set_clipboard_contents(text); + self.clipboard_provider.set_text(text); } KeyReaction::DispatchInput }) .shortcut(CMD_OR_CONTROL, 'V', || { - let contents = self.clipboard_provider.clipboard_contents(); - self.insert_string(contents); + if let Ok(text_content) = self.clipboard_provider.get_text() { + self.insert_string(text_content); + } KeyReaction::DispatchInput }) .shortcut(Modifiers::empty(), Key::Delete, || { @@ -1166,10 +1167,7 @@ pub(crate) fn handle_text_clipboard_action( // Step 3.1 Copy the selected contents, if any, to the clipboard if let Some(text) = selection { - textinput - .borrow_mut() - .clipboard_provider - .set_clipboard_contents(text); + textinput.borrow_mut().clipboard_provider.set_text(text); } // Step 3.2 Fire a clipboard event named clipboardchange @@ -1183,10 +1181,7 @@ pub(crate) fn handle_text_clipboard_action( // Step 3.1 If there is a selection in an editable context where cutting is enabled, then if let Some(text) = selection { // Step 3.1.1 Copy the selected contents, if any, to the clipboard - textinput - .borrow_mut() - .clipboard_provider - .set_clipboard_contents(text); + textinput.borrow_mut().clipboard_provider.set_text(text); // Step 3.1.2 Remove the contents of the selection from the document and collapse the selection. textinput.borrow_mut().delete_char(Direction::Backward); |