Auto merge of #17067 - est31:master, r=jdm

Bring back clipboard support

Brings back clipboard support.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #17065
- [x] These changes fix #12805

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
- [x] Testing these chances would require a full integration-style test suite, which servo currently lacks.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17067)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-01 10:07:16 -07:00 committed by GitHub
commit 12de616532
7 changed files with 113 additions and 6 deletions

View file

@ -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"}

View file

@ -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<Message, LTF, STF> {
/// The size of the top-level window.
window_size: WindowSizeData,
/// Means of accessing the clipboard
clipboard_ctx: Option<ClipboardContext>,
/// Bits of state used to interact with the webdriver implementation
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)),
},
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<Message, LTF, STF> Constellation<Message, LTF, STF>
}
}
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");

View file

@ -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;

View file

@ -613,17 +613,17 @@ impl<T: ClipboardProvider> TextInput<T> {
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