mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +01:00
Moved clipboard integration from textinput to constellation, to facilitate sandboxing.
This commit is contained in:
parent
ba4c455438
commit
503cc9e6d6
10 changed files with 46 additions and 19 deletions
|
@ -69,12 +69,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"
|
||||
|
|
|
@ -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;
|
||||
|
@ -109,6 +110,7 @@ static DEFAULT_INPUT_SIZE: u32 = 20;
|
|||
|
||||
impl HTMLInputElement {
|
||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLInputElement {
|
||||
let chan = document.window().root().r().constellation_chan();
|
||||
HTMLInputElement {
|
||||
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLInputElement, localName, prefix, document),
|
||||
input_type: Cell::new(InputType::InputText),
|
||||
|
@ -118,7 +120,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(), 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;
|
||||
|
@ -90,9 +91,10 @@ static DEFAULT_ROWS: u32 = 2;
|
|||
|
||||
impl HTMLTextAreaElement {
|
||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLTextAreaElement {
|
||||
let chan = document.window().root().r().constellation_chan();
|
||||
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(), chan)),
|
||||
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;
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
||||
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;
|
||||
|
||||
|
@ -13,8 +15,7 @@ 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)]
|
||||
pub enum Selection {
|
||||
|
@ -31,8 +32,6 @@ pub struct TextPoint {
|
|||
pub index: usize,
|
||||
}
|
||||
|
||||
no_jsmanaged_fields!(ClipboardContext);
|
||||
|
||||
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
|
||||
#[jstraceable]
|
||||
pub struct TextInput {
|
||||
|
@ -44,8 +43,7 @@ pub struct TextInput {
|
|||
selection_begin: Option<TextPoint>,
|
||||
/// Is this a multiline input?
|
||||
multiline: bool,
|
||||
/// Means of accessing the clipboard
|
||||
clipboard_ctx: ClipboardContext,
|
||||
constellation_channel: ConstellationChan
|
||||
}
|
||||
|
||||
/// Resulting action to be taken by the owner of a text input that is handling an event.
|
||||
|
@ -93,13 +91,13 @@ fn is_control_key(event: JSRef<KeyboardEvent>) -> bool {
|
|||
|
||||
impl TextInput {
|
||||
/// Instantiate a new text input control
|
||||
pub fn new(lines: Lines, initial: DOMString) -> 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,
|
||||
clipboard_ctx: ClipboardContext::new().unwrap(),
|
||||
constellation_channel: cc,
|
||||
};
|
||||
i.set_content(initial);
|
||||
i
|
||||
|
@ -299,7 +297,9 @@ impl TextInput {
|
|||
KeyReaction::Nothing
|
||||
},
|
||||
"v" if is_control_key(event) => {
|
||||
let contents = self.clipboard_ctx.get_contents().unwrap();
|
||||
let (tx, rx) = channel();
|
||||
self.constellation_channel.0.send(ConstellationMsg::GetClipboardContents(tx)).unwrap();
|
||||
let contents = rx.recv().unwrap();
|
||||
self.insert_string(contents.as_slice());
|
||||
KeyReaction::DispatchInput
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue