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

fixup! Moved clipboard integration from textinput to constellation, t…

…o facilitate sandboxing.
  • Loading branch information
aweinstock314 committed Apr 2, 2015
commit 49d4a30fee63f6fc0eafe6ddf1b3d397a1697151
@@ -389,7 +389,14 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
event);
}
ConstellationMsg::GetClipboardContents(sender) => {
sender.send(self.clipboard_ctx.get_contents().unwrap()).unwrap();
let result = match self.clipboard_ctx.get_contents() {
Ok(s) => s,
Err(e) => {
debug!("Error getting clipboard contents ({}), defaulting to empty string", e);
"".to_string()
},
};
sender.send(result).unwrap();
}
}
true
@@ -29,6 +29,7 @@ use dom::htmlformelement::{SubmittedFrom, ResetFrom};
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId};
use dom::node::{document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use textinput::TextInput;
use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing};
use textinput::Lines::Single;
@@ -116,7 +117,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(), document)),
textinput: DOMRefCell::new(TextInput::new(Single, "".to_owned(), document.window().root().r().constellation_chan())),
activation_state: DOMRefCell::new(InputActivationState::new())
}
}
@@ -27,6 +27,7 @@ use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId}
use dom::node::{document_from_node, window_from_node};
use textinput::{TextInput, Lines, KeyReaction};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use script_task::{ScriptMsg, Runnable};

use util::str::DOMString;
@@ -92,7 +93,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(), document)),
textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, "".to_owned(), document.window().root().r().constellation_chan())),
cols: Cell::new(DEFAULT_COLS),
rows: Cell::new(DEFAULT_ROWS),
value_changed: Cell::new(false),
@@ -5,9 +5,8 @@
//! Common handling of keyboard input and state management for text input controls

use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
use dom::document::{Document, DocumentHelpers};
use dom::window::WindowHelpers;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::JSRef;
use msg::constellation_msg::ConstellationChan;
use msg::constellation_msg::Msg as ConstellationMsg;
use dom::keyboardevent::KeyboardEvent;
use util::str::DOMString;
@@ -34,7 +33,6 @@ struct TextPoint {
}

/// 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'
@@ -45,7 +43,7 @@ pub struct TextInput {
selection_begin: Option<TextPoint>,
/// Is this a multiline input?
multiline: bool,
document: JS<Document>,
constellation_channel: ConstellationChan
}

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

impl TextInput {
/// Instantiate a new text input control
#[allow(unrooted_must_root)]
pub fn new(lines: Lines, initial: DOMString, document: JSRef<Document>) -> TextInput {
pub fn new(lines: Lines, initial: DOMString, cc: ConstellationChan) -> TextInput {
let mut i = TextInput {
lines: vec!(),
edit_point: Default::default(),
selection_begin: None,
multiline: lines == Lines::Multiple,
document: document.unrooted()
constellation_channel: cc,
};
i.set_content(initial);
i
@@ -301,8 +298,7 @@ impl TextInput {
},
"v" if is_control_key(event) => {
let (tx, rx) = channel();
self.document.root().r().window().root().r().constellation_chan().0
.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
self.constellation_channel.0.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
let contents = rx.recv().unwrap();
self.insert_string(contents.as_slice());
KeyReaction::DispatchInput
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.