mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Implement X11 clipboard integration (Issue #5376).
This commit is contained in:
parent
e4b620ea54
commit
ba4c455438
4 changed files with 30 additions and 1 deletions
|
@ -69,6 +69,12 @@ git = "https://github.com/servo/string-cache"
|
||||||
[dependencies.string_cache_plugin]
|
[dependencies.string_cache_plugin]
|
||||||
git = "https://github.com/servo/string-cache"
|
git = "https://github.com/servo/string-cache"
|
||||||
|
|
||||||
|
[dependencies.xlib]
|
||||||
|
git = "https://github.com/servo/rust-xlib"
|
||||||
|
|
||||||
|
[dependencies.clipboard]
|
||||||
|
git = "https://github.com/aweinstock314/rust-x11-clipboard"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
url = "0.2.16"
|
url = "0.2.16"
|
||||||
|
|
|
@ -52,6 +52,7 @@ extern crate style;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
extern crate string_cache;
|
extern crate string_cache;
|
||||||
|
extern crate clipboard;
|
||||||
|
|
||||||
pub mod cors;
|
pub mod cors;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ use std::cmp::{min, max};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::num::SignedInt;
|
use std::num::SignedInt;
|
||||||
|
|
||||||
|
use clipboard::ClipboardContext;
|
||||||
|
|
||||||
#[derive(Copy, PartialEq)]
|
#[derive(Copy, PartialEq)]
|
||||||
pub enum Selection {
|
pub enum Selection {
|
||||||
Selected,
|
Selected,
|
||||||
|
@ -29,6 +31,8 @@ pub struct TextPoint {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
no_jsmanaged_fields!(ClipboardContext);
|
||||||
|
|
||||||
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
|
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
|
||||||
#[jstraceable]
|
#[jstraceable]
|
||||||
pub struct TextInput {
|
pub struct TextInput {
|
||||||
|
@ -40,6 +44,8 @@ pub struct TextInput {
|
||||||
selection_begin: Option<TextPoint>,
|
selection_begin: Option<TextPoint>,
|
||||||
/// Is this a multiline input?
|
/// Is this a multiline input?
|
||||||
multiline: bool,
|
multiline: bool,
|
||||||
|
/// Means of accessing the clipboard
|
||||||
|
clipboard_ctx: ClipboardContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resulting action to be taken by the owner of a text input that is handling an event.
|
/// Resulting action to be taken by the owner of a text input that is handling an event.
|
||||||
|
@ -93,6 +99,7 @@ impl TextInput {
|
||||||
edit_point: Default::default(),
|
edit_point: Default::default(),
|
||||||
selection_begin: None,
|
selection_begin: None,
|
||||||
multiline: lines == Lines::Multiple,
|
multiline: lines == Lines::Multiple,
|
||||||
|
clipboard_ctx: ClipboardContext::new().unwrap(),
|
||||||
};
|
};
|
||||||
i.set_content(initial);
|
i.set_content(initial);
|
||||||
i
|
i
|
||||||
|
@ -118,6 +125,15 @@ impl TextInput {
|
||||||
self.replace_selection(ch.to_string());
|
self.replace_selection(ch.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Insert a string at the current editing point
|
||||||
|
fn insert_string(&mut self, s: &str) {
|
||||||
|
// it looks like this could be made performant by avoiding some redundant
|
||||||
|
// selection-related checks, but use the simple implementation for now
|
||||||
|
for ch in s.chars() {
|
||||||
|
self.insert_char(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
|
pub fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
|
||||||
let begin = self.selection_begin.unwrap();
|
let begin = self.selection_begin.unwrap();
|
||||||
let end = self.edit_point;
|
let end = self.edit_point;
|
||||||
|
@ -282,10 +298,15 @@ impl TextInput {
|
||||||
self.select_all();
|
self.select_all();
|
||||||
KeyReaction::Nothing
|
KeyReaction::Nothing
|
||||||
},
|
},
|
||||||
|
"v" if is_control_key(event) => {
|
||||||
|
let contents = self.clipboard_ctx.get_contents().unwrap();
|
||||||
|
self.insert_string(contents.as_slice());
|
||||||
|
KeyReaction::DispatchInput
|
||||||
|
},
|
||||||
// printable characters have single-character key values
|
// printable characters have single-character key values
|
||||||
c if c.len() == 1 => {
|
c if c.len() == 1 => {
|
||||||
self.insert_char(c.char_at(0));
|
self.insert_char(c.char_at(0));
|
||||||
return KeyReaction::DispatchInput;
|
KeyReaction::DispatchInput
|
||||||
}
|
}
|
||||||
"Space" => {
|
"Space" => {
|
||||||
self.insert_char(' ');
|
self.insert_char(' ');
|
||||||
|
|
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -822,6 +822,7 @@ dependencies = [
|
||||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
"uuid 0.1.11 (git+https://github.com/rust-lang/uuid)",
|
"uuid 0.1.11 (git+https://github.com/rust-lang/uuid)",
|
||||||
|
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue