diff --git a/Cargo.lock b/Cargo.lock index 3087df489c611..4fb92f7ec9f70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -387,6 +387,28 @@ dependencies = [ "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]] name = "cmake" version = "0.1.22" @@ -459,6 +481,7 @@ dependencies = [ "bluetooth_traits 0.0.1", "canvas 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", "debugger 0.0.1", "devtools_traits 0.0.1", @@ -854,6 +877,14 @@ name = "error-chain" version = "0.7.2" 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]] name = "euclid" version = "0.11.3" @@ -1882,6 +1913,24 @@ dependencies = [ "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]] name = "odds" version = "0.2.25" @@ -3382,6 +3431,15 @@ dependencies = [ "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]] name = "x11-dl" version = "2.14.0" @@ -3392,6 +3450,15 @@ dependencies = [ "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]] name = "xdg" version = "2.1.0" @@ -3463,6 +3530,8 @@ dependencies = [ "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 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 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" @@ -3498,6 +3567,7 @@ dependencies = [ "checksum energymon-sys 0.3.0 (git+https://github.com/energymon/energymon-sys.git)" = "" "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 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 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" @@ -3576,6 +3646,8 @@ dependencies = [ "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 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 offscreen_gl_context 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3cadec7378139fd7e48badba0d59cbb6312c7e0eca9b5e3b8ec7a78fc0c6cb28" "checksum ogg 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7137bf02687385302f4c0aecd77cfce052b69f5b4ee937be778e125c62f67e30" @@ -3692,7 +3764,9 @@ dependencies = [ "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 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 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 xi-unicode 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "12ea8eda4b1eb72f02d148402e23832d56a33f55d8c1b2d5bcdde91d79d47cb1" "checksum xml-rs 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7ec6c39eaa68382c8e31e35239402c0a9489d4141a8ceb0c716099a0b515b562" diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index e6b8bfebeb32f..cbc2e1f904050 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -13,6 +13,7 @@ path = "lib.rs" backtrace = "0.3" bluetooth_traits = { path = "../bluetooth_traits" } canvas = {path = "../canvas"} +clipboard = "0.3" canvas_traits = {path = "../canvas_traits"} compositing = {path = "../compositing"} debugger = {path = "../debugger"} diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 07ace83d561e8..7c0edc090d462 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -71,6 +71,7 @@ use browsingcontext::{FullyActiveBrowsingContextsIterator, AllBrowsingContextsIt use canvas::canvas_paint_thread::CanvasPaintThread; use canvas::webgl_paint_thread::WebGLPaintThread; use canvas_traits::CanvasMsg; +use clipboard::{ClipboardContext, ClipboardProvider}; use compositing::SendableFrameTree; use compositing::compositor_thread::CompositorProxy; use compositing::compositor_thread::Msg as ToCompositorMsg; @@ -263,6 +264,9 @@ pub struct Constellation { /// The size of the top-level window. window_size: WindowSizeData, + /// Means of accessing the clipboard + clipboard_ctx: Option, + /// Bits of state used to interact with the webdriver implementation webdriver: WebDriverData, @@ -535,6 +539,17 @@ impl Constellation ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)), }, 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(), scheduler_chan: TimerScheduler::start(), document_states: HashMap::new(), @@ -1019,11 +1034,26 @@ impl Constellation } } 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); } } - 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) => { debug!("constellation got set visible messsage"); diff --git a/components/constellation/lib.rs b/components/constellation/lib.rs index 6958a5b7c39d6..293de5c854fde 100644 --- a/components/constellation/lib.rs +++ b/components/constellation/lib.rs @@ -11,6 +11,7 @@ extern crate backtrace; extern crate bluetooth_traits; extern crate canvas; extern crate canvas_traits; +extern crate clipboard; extern crate compositing; extern crate debugger; extern crate devtools_traits; diff --git a/components/script/textinput.rs b/components/script/textinput.rs index b508ba2806c02..d1c473f5ad875 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -613,17 +613,17 @@ impl TextInput { self.adjust_horizontal_to_line_end(Direction::Forward, maybe_select); KeyReaction::RedrawSelection }, - (Some('a'), _) if is_control_key(mods) => { + (_, Key::A) if is_control_key(mods) => { self.select_all(); KeyReaction::RedrawSelection }, - (Some('c'), _) if is_control_key(mods) => { + (_, Key::C) if is_control_key(mods) => { if let Some(text) = self.get_selection_text() { self.clipboard_provider.set_clipboard_contents(text); } KeyReaction::DispatchInput }, - (Some('v'), _) if is_control_key(mods) => { + (_, Key::V) if is_control_key(mods) => { let contents = self.clipboard_provider.clipboard_contents(); self.insert_string(contents); KeyReaction::DispatchInput diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index ddd53988452d9..6bb6a59006a38 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -1285,7 +1285,7 @@ impl WindowMethods for Window { } fn supports_clipboard(&self) -> bool { - false + true } } diff --git a/servo-tidy.toml b/servo-tidy.toml index 55357dfe1ce2f..65690061677af 100644 --- a/servo-tidy.toml +++ b/servo-tidy.toml @@ -33,6 +33,7 @@ num = [] [ignore] # Ignored packages with duplicated versions packages = [ + "error-chain", "bitflags", "libloading", # Conflicting version is only used at build-time by geckolib. ]