Bring back clipboard support

This commit is contained in:
est31 2017-05-28 03:09:33 +02:00
parent 433d68955b
commit 28b854d724
7 changed files with 113 additions and 6 deletions

74
Cargo.lock generated
View file

@ -387,6 +387,28 @@ dependencies = [
"vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "clipboard"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clipboard-win 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"x11-clipboard 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "clipboard-win"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.22" version = "0.1.22"
@ -459,6 +481,7 @@ dependencies = [
"bluetooth_traits 0.0.1", "bluetooth_traits 0.0.1",
"canvas 0.0.1", "canvas 0.0.1",
"canvas_traits 0.0.1", "canvas_traits 0.0.1",
"clipboard 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"compositing 0.0.1", "compositing 0.0.1",
"debugger 0.0.1", "debugger 0.0.1",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
@ -854,6 +877,14 @@ name = "error-chain"
version = "0.7.2" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "error-chain"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "euclid" name = "euclid"
version = "0.11.3" version = "0.11.3"
@ -1883,6 +1914,24 @@ dependencies = [
"malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "objc-foundation"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "objc_id"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "odds" name = "odds"
version = "0.2.25" version = "0.2.25"
@ -3383,6 +3432,15 @@ dependencies = [
"metadeps 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "metadeps 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "x11-clipboard"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"xcb 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "x11-dl" name = "x11-dl"
version = "2.14.0" version = "2.14.0"
@ -3393,6 +3451,15 @@ dependencies = [
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "xcb"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "xdg" name = "xdg"
version = "2.1.0" version = "2.1.0"
@ -3464,6 +3531,8 @@ dependencies = [
"checksum cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86765cb42c2a2c497e142af72517c1b4d7ae5bb2f25dfa77a5c69642f2342d89" "checksum cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86765cb42c2a2c497e142af72517c1b4d7ae5bb2f25dfa77a5c69642f2342d89"
"checksum clang-sys 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff7c2d1502c65748c7221f43ce670b3ba5c697acebfeb85a580827daca6975fc" "checksum clang-sys 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff7c2d1502c65748c7221f43ce670b3ba5c697acebfeb85a580827daca6975fc"
"checksum clap 2.20.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7db281b0520e97fbd15cd615dcd8f8bcad0c26f5f7d5effe705f090f39e9a758" "checksum clap 2.20.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7db281b0520e97fbd15cd615dcd8f8bcad0c26f5f7d5effe705f090f39e9a758"
"checksum clipboard 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "564a8fdbec95bd0a02df93018ed8f55ecf62449a40f731d54caf8c3a84e3e1e6"
"checksum clipboard-win 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "693b1280c514045382dfdbb78d1594b1b03cdb66320aeb7ebd2bd38d49bae959"
"checksum cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "d18d68987ed4c516dcc3e7913659bfa4076f5182eea4a7e0038bb060953e76ac" "checksum cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "d18d68987ed4c516dcc3e7913659bfa4076f5182eea4a7e0038bb060953e76ac"
"checksum cocoa 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a5d0bcb4d345adf9b4ada6c5bb3e2b87c8150b79c46f3f26446de5f4d48de4b" "checksum cocoa 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a5d0bcb4d345adf9b4ada6c5bb3e2b87c8150b79c46f3f26446de5f4d48de4b"
"checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d" "checksum color_quant 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a475fc4af42d83d28adf72968d9bcfaf035a1a9381642d8e85d8a04957767b0d"
@ -3499,6 +3568,7 @@ dependencies = [
"checksum energymon-sys 0.3.0 (git+https://github.com/energymon/energymon-sys.git)" = "<none>" "checksum energymon-sys 0.3.0 (git+https://github.com/energymon/energymon-sys.git)" = "<none>"
"checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180" "checksum enum_primitive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be4551092f4d519593039259a9ed8daedf0da12e5109c5280338073eaeb81180"
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
"checksum error-chain 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8"
"checksum error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "318cb3c71ee4cdea69fdc9e15c173b245ed6063e1709029e8fd32525a881120f" "checksum error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "318cb3c71ee4cdea69fdc9e15c173b245ed6063e1709029e8fd32525a881120f"
"checksum euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f5517462c626a893f3b027615e88d7102cc6dd3f7f1bcb90c7220fb1da4970b5" "checksum euclid 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f5517462c626a893f3b027615e88d7102cc6dd3f7f1bcb90c7220fb1da4970b5"
"checksum expat-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cef36cd1a8a02d28b91d97347c63247b9e4cb8a8e36df36f8201dc87a1c0859c" "checksum expat-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cef36cd1a8a02d28b91d97347c63247b9e4cb8a8e36df36f8201dc87a1c0859c"
@ -3577,6 +3647,8 @@ dependencies = [
"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99" "checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99"
"checksum num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca313f1862c7ec3e0dfe8ace9fa91b1d9cb5c84ace3d00f5ec4216238e93c167" "checksum num_cpus 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca313f1862c7ec3e0dfe8ace9fa91b1d9cb5c84ace3d00f5ec4216238e93c167"
"checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e" "checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e"
"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
"checksum objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4730aa1c64d722db45f7ccc4113a3e2c465d018de6db4d3e7dfe031e8c8a297"
"checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba" "checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba"
"checksum offscreen_gl_context 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3cadec7378139fd7e48badba0d59cbb6312c7e0eca9b5e3b8ec7a78fc0c6cb28" "checksum offscreen_gl_context 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3cadec7378139fd7e48badba0d59cbb6312c7e0eca9b5e3b8ec7a78fc0c6cb28"
"checksum ogg 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "013b78ceb7fb82555a2f8a95d8e40866fe64a5d15b83c51b3e1fdd40cd903ed3" "checksum ogg 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "013b78ceb7fb82555a2f8a95d8e40866fe64a5d15b83c51b3e1fdd40cd903ed3"
@ -3693,7 +3765,9 @@ dependencies = [
"checksum ws 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04614a58714f3fd4a8b1da4bcae9f031c532d35988c3d39627619248113f8be8" "checksum ws 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04614a58714f3fd4a8b1da4bcae9f031c532d35988c3d39627619248113f8be8"
"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e"
"checksum x11 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db27c597c187da52194a4b8232e7d869503911aab9ff726fefb76d7a830f78ed" "checksum x11 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db27c597c187da52194a4b8232e7d869503911aab9ff726fefb76d7a830f78ed"
"checksum x11-clipboard 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "731230b8edcbb9d99247105e4c9ec0a538594d50ad68d2afa8662195f9db2973"
"checksum x11-dl 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "326c500cdc166fd7c70dd8c8a829cd5c0ce7be5a5d98c25817de2b9bdc67faf8" "checksum x11-dl 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "326c500cdc166fd7c70dd8c8a829cd5c0ce7be5a5d98c25817de2b9bdc67faf8"
"checksum xcb 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "63e3a849b73e4e1905e4f4d48f1750429bc86ea9f473632ab382a6f69ecb6b33"
"checksum xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a66b7c2281ebde13cf4391d70d4c7e5946c3c25e72a7b859ca8f677dcd0b0c61" "checksum xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a66b7c2281ebde13cf4391d70d4c7e5946c3c25e72a7b859ca8f677dcd0b0c61"
"checksum xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12ea8eda4b1eb72f02d148402e23832d56a33f55d8c1b2d5bcdde91d79d47cb1" "checksum xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12ea8eda4b1eb72f02d148402e23832d56a33f55d8c1b2d5bcdde91d79d47cb1"
"checksum xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b15eed12692bd59d15e98ee7f8dc8408465b992d8ddb4d1672c24865132ec7" "checksum xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b15eed12692bd59d15e98ee7f8dc8408465b992d8ddb4d1672c24865132ec7"

View file

@ -13,6 +13,7 @@ path = "lib.rs"
backtrace = "0.3" backtrace = "0.3"
bluetooth_traits = { path = "../bluetooth_traits" } bluetooth_traits = { path = "../bluetooth_traits" }
canvas = {path = "../canvas"} canvas = {path = "../canvas"}
clipboard = "0.3"
canvas_traits = {path = "../canvas_traits"} canvas_traits = {path = "../canvas_traits"}
compositing = {path = "../compositing"} compositing = {path = "../compositing"}
debugger = {path = "../debugger"} debugger = {path = "../debugger"}

View file

@ -71,6 +71,7 @@ use browsingcontext::{FullyActiveBrowsingContextsIterator, AllBrowsingContextsIt
use canvas::canvas_paint_thread::CanvasPaintThread; use canvas::canvas_paint_thread::CanvasPaintThread;
use canvas::webgl_paint_thread::WebGLPaintThread; use canvas::webgl_paint_thread::WebGLPaintThread;
use canvas_traits::CanvasMsg; use canvas_traits::CanvasMsg;
use clipboard::{ClipboardContext, ClipboardProvider};
use compositing::SendableFrameTree; use compositing::SendableFrameTree;
use compositing::compositor_thread::CompositorProxy; use compositing::compositor_thread::CompositorProxy;
use compositing::compositor_thread::Msg as ToCompositorMsg; use compositing::compositor_thread::Msg as ToCompositorMsg;
@ -263,6 +264,9 @@ pub struct Constellation<Message, LTF, STF> {
/// The size of the top-level window. /// The size of the top-level window.
window_size: WindowSizeData, window_size: WindowSizeData,
/// Means of accessing the clipboard
clipboard_ctx: Option<ClipboardContext>,
/// Bits of state used to interact with the webdriver implementation /// Bits of state used to interact with the webdriver implementation
webdriver: WebDriverData, webdriver: WebDriverData,
@ -535,6 +539,17 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)), ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)),
}, },
phantom: PhantomData, phantom: PhantomData,
clipboard_ctx: if state.supports_clipboard {
match ClipboardContext::new() {
Ok(c) => Some(c),
Err(e) => {
warn!("Error creating clipboard context ({})", e);
None
},
}
} else {
None
},
webdriver: WebDriverData::new(), webdriver: WebDriverData::new(),
scheduler_chan: TimerScheduler::start(), scheduler_chan: TimerScheduler::start(),
document_states: HashMap::new(), document_states: HashMap::new(),
@ -1019,11 +1034,26 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
} }
} }
FromScriptMsg::GetClipboardContents(sender) => { FromScriptMsg::GetClipboardContents(sender) => {
if let Err(e) = sender.send("".to_owned()) { let contents = match self.clipboard_ctx {
Some(ref mut ctx) => match ctx.get_contents() {
Ok(c) => c,
Err(e) => {
warn!("Error getting clipboard contents ({}), defaulting to empty string", e);
"".to_owned()
},
},
None => "".to_owned(),
};
if let Err(e) = sender.send(contents.to_owned()) {
warn!("Failed to send clipboard ({})", e); warn!("Failed to send clipboard ({})", e);
} }
} }
FromScriptMsg::SetClipboardContents(_) => { FromScriptMsg::SetClipboardContents(s) => {
if let Some(ref mut ctx) = self.clipboard_ctx {
if let Err(e) = ctx.set_contents(s) {
warn!("Error setting clipboard contents ({})", e);
}
}
} }
FromScriptMsg::SetVisible(pipeline_id, visible) => { FromScriptMsg::SetVisible(pipeline_id, visible) => {
debug!("constellation got set visible messsage"); debug!("constellation got set visible messsage");

View file

@ -11,6 +11,7 @@ extern crate backtrace;
extern crate bluetooth_traits; extern crate bluetooth_traits;
extern crate canvas; extern crate canvas;
extern crate canvas_traits; extern crate canvas_traits;
extern crate clipboard;
extern crate compositing; extern crate compositing;
extern crate debugger; extern crate debugger;
extern crate devtools_traits; extern crate devtools_traits;

View file

@ -613,17 +613,17 @@ impl<T: ClipboardProvider> TextInput<T> {
self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select); self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select);
KeyReaction::RedrawSelection KeyReaction::RedrawSelection
}, },
(Some('a'), _) if is_control_key(mods) => { (_, Key::A) if is_control_key(mods) => {
self.select_all(); self.select_all();
KeyReaction::RedrawSelection KeyReaction::RedrawSelection
}, },
(Some('c'), _) if is_control_key(mods) => { (_, Key::C) if is_control_key(mods) => {
if let Some(text) = self.get_selection_text() { if let Some(text) = self.get_selection_text() {
self.clipboard_provider.set_clipboard_contents(text); self.clipboard_provider.set_clipboard_contents(text);
} }
KeyReaction::DispatchInput KeyReaction::DispatchInput
}, },
(Some('v'), _) if is_control_key(mods) => { (_, Key::V) if is_control_key(mods) => {
let contents = self.clipboard_provider.clipboard_contents(); let contents = self.clipboard_provider.clipboard_contents();
self.insert_string(contents); self.insert_string(contents);
KeyReaction::DispatchInput KeyReaction::DispatchInput

View file

@ -1285,7 +1285,7 @@ impl WindowMethods for Window {
} }
fn supports_clipboard(&self) -> bool { fn supports_clipboard(&self) -> bool {
false true
} }
} }

View file

@ -33,6 +33,7 @@ num = []
[ignore] [ignore]
# Ignored packages with duplicated versions # Ignored packages with duplicated versions
packages = [ packages = [
"error-chain",
"bitflags", "bitflags",
"libloading", # Conflicting version is only used at build-time by geckolib. "libloading", # Conflicting version is only used at build-time by geckolib.
] ]