Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 clipboard support #5479

Closed
wants to merge 10 commits into from

Moved clipboard integration from textinput to constellation, to facil…

…itate sandboxing.
  • Loading branch information
aweinstock314 committed Apr 2, 2015
commit 79236c0dd8c2e557c75cbe8f2016abc0e6727610
@@ -52,6 +52,9 @@ git = "https://github.com/servo/rust-core-text"
[dependencies.gleam]
git = "https://github.com/servo/gleam"

[dependencies.clipboard]
git = "https://github.com/aweinstock314/rust-x11-clipboard"

[dependencies]
url = "0.2.16"
time = "0.1.17"
@@ -38,6 +38,7 @@ use util::cursor::Cursor;
use util::geometry::PagePx;
use util::opts;
use util::task::spawn_named;
use clipboard::ClipboardContext;

/// Maintains the pipelines and navigation context and grants permission to composite.
pub struct Constellation<LTF, STF> {
@@ -99,6 +100,9 @@ pub struct Constellation<LTF, STF> {
phantom: PhantomData<(LTF, STF)>,

pub window_size: WindowSizeData,

/// Means of accessing the clipboard
clipboard_ctx: ClipboardContext,
}

/// Stores the navigation context for a single frame in the frame tree.
@@ -208,6 +212,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
device_pixel_ratio: ScaleFactor::new(1.0),
},
phantom: PhantomData,
clipboard_ctx: ClipboardContext::new().unwrap(),
};
constellation.run();
});
@@ -383,6 +388,9 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
subpage_id,
event);
}
ConstellationMsg::GetClipboardContents(sender) => {
sender.send(self.clipboard_ctx.get_contents().unwrap()).unwrap();
}
}
true
}
@@ -27,6 +27,7 @@ extern crate profile;
#[macro_use]
extern crate util;
extern crate gleam;
extern crate clipboard;

extern crate libc;
extern crate time;
@@ -218,6 +218,8 @@ pub enum Msg {
ChangeRunningAnimationsState(PipelineId, bool),
/// Requests that the constellation instruct layout to begin a new tick of the animation.
TickAnimation(PipelineId),
/// Requests that the constellation retrieve the current contents of the clipboard
GetClipboardContents(Sender<String>),
}

// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events
@@ -66,12 +66,6 @@ git = "https://github.com/servo/string-cache"
[dependencies.string_cache_plugin]
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]
encoding = "0.2"
url = "0.2.16"
@@ -116,7 +116,7 @@ impl HTMLInputElement {
checked_changed: Cell::new(false),
value_changed: Cell::new(false),
size: Cell::new(DEFAULT_INPUT_SIZE),
textinput: DOMRefCell::new(TextInput::new(Single, "".to_owned())),
textinput: DOMRefCell::new(TextInput::new(Single, "".to_owned(), document)),
activation_state: DOMRefCell::new(InputActivationState::new())
}
}
@@ -92,7 +92,7 @@ impl HTMLTextAreaElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLTextAreaElement {
HTMLTextAreaElement {
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLTextAreaElement, localName, prefix, document),
textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, "".to_owned())),
textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, "".to_owned(), document)),
cols: Cell::new(DEFAULT_COLS),
rows: Cell::new(DEFAULT_ROWS),
value_changed: Cell::new(false),
@@ -52,7 +52,6 @@ extern crate style;
extern crate url;
extern crate uuid;
extern crate string_cache;
extern crate clipboard;

pub mod cors;

@@ -5,16 +5,18 @@
//! Common handling of keyboard input and state management for text input controls

use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
use dom::bindings::js::JSRef;
use dom::document::{Document, DocumentHelpers};
use dom::window::WindowHelpers;
use dom::bindings::js::{JS, JSRef};
use msg::constellation_msg::Msg as ConstellationMsg;
use dom::keyboardevent::KeyboardEvent;
use util::str::DOMString;

use std::borrow::ToOwned;
use std::cmp::{min, max};
use std::default::Default;
use std::num::SignedInt;

use clipboard::ClipboardContext;
use std::sync::mpsc::channel;

#[derive(Copy, PartialEq)]
enum Selection {
@@ -31,9 +33,8 @@ struct TextPoint {
index: usize,
}

no_jsmanaged_fields!(ClipboardContext);

/// Encapsulated state for handling keyboard input in a single or multiline text input control.
#[must_root]
#[jstraceable]
pub struct TextInput {
/// Current text input content, split across lines without trailing '\n'
@@ -44,8 +45,7 @@ pub struct TextInput {
selection_begin: Option<TextPoint>,
/// Is this a multiline input?
multiline: bool,
/// Means of accessing the clipboard
clipboard_ctx: ClipboardContext,
document: JS<Document>,
}

/// Resulting action to be taken by the owner of a text input that is handling an event.
@@ -93,13 +93,14 @@ fn is_control_key(event: JSRef<KeyboardEvent>) -> bool {

impl TextInput {
/// Instantiate a new text input control
pub fn new(lines: Lines, initial: DOMString) -> TextInput {
#[allow(unrooted_must_root)]
pub fn new(lines: Lines, initial: DOMString, document: JSRef<Document>) -> TextInput {
let mut i = TextInput {
lines: vec!(),
edit_point: Default::default(),
selection_begin: None,
multiline: lines == Lines::Multiple,
clipboard_ctx: ClipboardContext::new().unwrap(),
document: document.unrooted()
};
i.set_content(initial);
i
@@ -299,7 +300,10 @@ impl TextInput {
KeyReaction::Nothing
},
"v" if is_control_key(event) => {
let contents = self.clipboard_ctx.get_contents().unwrap();
let (tx, rx) = channel();
self.document.root().r().window().root().r().constellation_chan().0
.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
let contents = rx.recv().unwrap();
self.insert_string(contents.as_slice());
KeyReaction::DispatchInput
},

Some generated files are not rendered by default. Learn more.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.