Skip to content

Commit

Permalink
Auto merge of #17067 - est31:master, r=jdm
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Jun 1, 2017
2 parents 6a63887 + 28b854d commit 9e82b31
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 6 deletions.
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/constellation/Cargo.toml
Expand Up @@ -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"}
Expand Down
34 changes: 32 additions & 2 deletions components/constellation/constellation.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions components/constellation/lib.rs
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions components/script/textinput.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/glutin/window.rs
Expand Up @@ -1285,7 +1285,7 @@ impl WindowMethods for Window {
}

fn supports_clipboard(&self) -> bool {
false
true
}
}

Expand Down
1 change: 1 addition & 0 deletions servo-tidy.toml
Expand Up @@ -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.
]
Expand Down

0 comments on commit 9e82b31

Please sign in to comment.