mirror of
https://github.com/servo/servo.git
synced 2025-06-13 10:54:29 +00: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
|
@ -58,6 +58,9 @@ git = "https://github.com/servo/rust-core-text"
|
||||||
[dependencies.gleam]
|
[dependencies.gleam]
|
||||||
git = "https://github.com/servo/gleam"
|
git = "https://github.com/servo/gleam"
|
||||||
|
|
||||||
|
[dependencies.clipboard]
|
||||||
|
git = "https://github.com/aweinstock314/rust-x11-clipboard"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
url = "0.2.16"
|
url = "0.2.16"
|
||||||
time = "0.1.17"
|
time = "0.1.17"
|
||||||
|
|
|
@ -38,6 +38,7 @@ use util::cursor::Cursor;
|
||||||
use util::geometry::PagePx;
|
use util::geometry::PagePx;
|
||||||
use util::opts;
|
use util::opts;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
use clipboard::ClipboardContext;
|
||||||
|
|
||||||
/// Maintains the pipelines and navigation context and grants permission to composite.
|
/// Maintains the pipelines and navigation context and grants permission to composite.
|
||||||
pub struct Constellation<LTF, STF> {
|
pub struct Constellation<LTF, STF> {
|
||||||
|
@ -102,6 +103,9 @@ pub struct Constellation<LTF, STF> {
|
||||||
phantom: PhantomData<(LTF, STF)>,
|
phantom: PhantomData<(LTF, STF)>,
|
||||||
|
|
||||||
pub window_size: WindowSizeData,
|
pub window_size: WindowSizeData,
|
||||||
|
|
||||||
|
/// Means of accessing the clipboard
|
||||||
|
clipboard_ctx: ClipboardContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stores the navigation context for a single frame in the frame tree.
|
/// Stores the navigation context for a single frame in the frame tree.
|
||||||
|
@ -212,6 +216,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
||||||
device_pixel_ratio: ScaleFactor::new(1.0),
|
device_pixel_ratio: ScaleFactor::new(1.0),
|
||||||
},
|
},
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
|
clipboard_ctx: ClipboardContext::new().unwrap(),
|
||||||
};
|
};
|
||||||
constellation.run();
|
constellation.run();
|
||||||
});
|
});
|
||||||
|
@ -395,6 +400,16 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
|
||||||
debug!("constellation got focus message");
|
debug!("constellation got focus message");
|
||||||
self.handle_focus_msg(pipeline_id);
|
self.handle_focus_msg(pipeline_id);
|
||||||
}
|
}
|
||||||
|
ConstellationMsg::GetClipboardContents(sender) => {
|
||||||
|
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
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern crate net_traits;
|
||||||
extern crate util;
|
extern crate util;
|
||||||
extern crate gleam;
|
extern crate gleam;
|
||||||
extern crate webdriver_server;
|
extern crate webdriver_server;
|
||||||
|
extern crate clipboard;
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
|
@ -229,6 +229,8 @@ pub enum Msg {
|
||||||
GetRootPipeline(Sender<Option<PipelineId>>),
|
GetRootPipeline(Sender<Option<PipelineId>>),
|
||||||
/// Notifies the constellation that this frame has received focus.
|
/// Notifies the constellation that this frame has received focus.
|
||||||
FocusMsg(PipelineId),
|
FocusMsg(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
|
// https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API#Events
|
||||||
|
|
|
@ -69,12 +69,6 @@ git = "https://github.com/servo/string-cache"
|
||||||
[dependencies.string_cache_plugin]
|
[dependencies.string_cache_plugin]
|
||||||
git = "https://github.com/servo/string-cache"
|
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]
|
[dependencies]
|
||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
url = "0.2.16"
|
url = "0.2.16"
|
||||||
|
|
|
@ -29,6 +29,7 @@ use dom::htmlformelement::{SubmittedFrom, ResetFrom};
|
||||||
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId};
|
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId};
|
||||||
use dom::node::{document_from_node, window_from_node};
|
use dom::node::{document_from_node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
use dom::window::WindowHelpers;
|
||||||
use textinput::TextInput;
|
use textinput::TextInput;
|
||||||
use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing};
|
use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing};
|
||||||
use textinput::Lines::Single;
|
use textinput::Lines::Single;
|
||||||
|
@ -109,6 +110,7 @@ static DEFAULT_INPUT_SIZE: u32 = 20;
|
||||||
|
|
||||||
impl HTMLInputElement {
|
impl HTMLInputElement {
|
||||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLInputElement {
|
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLInputElement {
|
||||||
|
let chan = document.window().root().r().constellation_chan();
|
||||||
HTMLInputElement {
|
HTMLInputElement {
|
||||||
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLInputElement, localName, prefix, document),
|
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLInputElement, localName, prefix, document),
|
||||||
input_type: Cell::new(InputType::InputText),
|
input_type: Cell::new(InputType::InputText),
|
||||||
|
@ -118,7 +120,7 @@ impl HTMLInputElement {
|
||||||
checked_changed: Cell::new(false),
|
checked_changed: Cell::new(false),
|
||||||
value_changed: Cell::new(false),
|
value_changed: Cell::new(false),
|
||||||
size: Cell::new(DEFAULT_INPUT_SIZE),
|
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())
|
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 dom::node::{document_from_node, window_from_node};
|
||||||
use textinput::{TextInput, Lines, KeyReaction};
|
use textinput::{TextInput, Lines, KeyReaction};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
use dom::window::WindowHelpers;
|
||||||
use script_task::{ScriptMsg, Runnable};
|
use script_task::{ScriptMsg, Runnable};
|
||||||
|
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
@ -90,9 +91,10 @@ static DEFAULT_ROWS: u32 = 2;
|
||||||
|
|
||||||
impl HTMLTextAreaElement {
|
impl HTMLTextAreaElement {
|
||||||
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLTextAreaElement {
|
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLTextAreaElement {
|
||||||
|
let chan = document.window().root().r().constellation_chan();
|
||||||
HTMLTextAreaElement {
|
HTMLTextAreaElement {
|
||||||
htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLTextAreaElement, localName, prefix, document),
|
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),
|
cols: Cell::new(DEFAULT_COLS),
|
||||||
rows: Cell::new(DEFAULT_ROWS),
|
rows: Cell::new(DEFAULT_ROWS),
|
||||||
value_changed: Cell::new(false),
|
value_changed: Cell::new(false),
|
||||||
|
|
|
@ -52,7 +52,6 @@ extern crate style;
|
||||||
extern crate url;
|
extern crate url;
|
||||||
extern crate uuid;
|
extern crate uuid;
|
||||||
extern crate string_cache;
|
extern crate string_cache;
|
||||||
extern crate clipboard;
|
|
||||||
|
|
||||||
pub mod cors;
|
pub mod cors;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
||||||
use dom::bindings::js::JSRef;
|
use dom::bindings::js::JSRef;
|
||||||
|
use msg::constellation_msg::ConstellationChan;
|
||||||
|
use msg::constellation_msg::Msg as ConstellationMsg;
|
||||||
use dom::keyboardevent::KeyboardEvent;
|
use dom::keyboardevent::KeyboardEvent;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
@ -13,8 +15,7 @@ use std::borrow::ToOwned;
|
||||||
use std::cmp::{min, max};
|
use std::cmp::{min, max};
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::num::SignedInt;
|
use std::num::SignedInt;
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
use clipboard::ClipboardContext;
|
|
||||||
|
|
||||||
#[derive(Copy, PartialEq)]
|
#[derive(Copy, PartialEq)]
|
||||||
pub enum Selection {
|
pub enum Selection {
|
||||||
|
@ -31,8 +32,6 @@ pub struct TextPoint {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
no_jsmanaged_fields!(ClipboardContext);
|
|
||||||
|
|
||||||
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
|
/// Encapsulated state for handling keyboard input in a single or multiline text input control.
|
||||||
#[jstraceable]
|
#[jstraceable]
|
||||||
pub struct TextInput {
|
pub struct TextInput {
|
||||||
|
@ -44,8 +43,7 @@ pub struct TextInput {
|
||||||
selection_begin: Option<TextPoint>,
|
selection_begin: Option<TextPoint>,
|
||||||
/// Is this a multiline input?
|
/// Is this a multiline input?
|
||||||
multiline: bool,
|
multiline: bool,
|
||||||
/// Means of accessing the clipboard
|
constellation_channel: ConstellationChan
|
||||||
clipboard_ctx: ClipboardContext,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resulting action to be taken by the owner of a text input that is handling an event.
|
/// 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 {
|
impl TextInput {
|
||||||
/// Instantiate a new text input control
|
/// 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 {
|
let mut i = TextInput {
|
||||||
lines: vec!(),
|
lines: vec!(),
|
||||||
edit_point: Default::default(),
|
edit_point: Default::default(),
|
||||||
selection_begin: None,
|
selection_begin: None,
|
||||||
multiline: lines == Lines::Multiple,
|
multiline: lines == Lines::Multiple,
|
||||||
clipboard_ctx: ClipboardContext::new().unwrap(),
|
constellation_channel: cc,
|
||||||
};
|
};
|
||||||
i.set_content(initial);
|
i.set_content(initial);
|
||||||
i
|
i
|
||||||
|
@ -299,7 +297,9 @@ impl TextInput {
|
||||||
KeyReaction::Nothing
|
KeyReaction::Nothing
|
||||||
},
|
},
|
||||||
"v" if is_control_key(event) => {
|
"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());
|
self.insert_string(contents.as_slice());
|
||||||
KeyReaction::DispatchInput
|
KeyReaction::DispatchInput
|
||||||
},
|
},
|
||||||
|
|
11
components/servo/Cargo.lock
generated
11
components/servo/Cargo.lock
generated
|
@ -75,6 +75,15 @@ dependencies = [
|
||||||
"gleam 0.0.1 (git+https://github.com/servo/gleam)",
|
"gleam 0.0.1 (git+https://github.com/servo/gleam)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clipboard"
|
||||||
|
version = "0.0.1"
|
||||||
|
source = "git+https://github.com/aweinstock314/rust-x11-clipboard#eae9596e7e407c8b6037b934c1a8e42a309423fd"
|
||||||
|
dependencies = [
|
||||||
|
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clock_ticks"
|
name = "clock_ticks"
|
||||||
version = "0.0.4"
|
version = "0.0.4"
|
||||||
|
@ -94,6 +103,7 @@ name = "compositing"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
|
||||||
|
"clipboard 0.0.1 (git+https://github.com/aweinstock314/rust-x11-clipboard)",
|
||||||
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
"core_graphics 0.1.0 (git+https://github.com/servo/rust-core-graphics)",
|
||||||
"core_text 0.1.0 (git+https://github.com/servo/rust-core-text)",
|
"core_text 0.1.0 (git+https://github.com/servo/rust-core-text)",
|
||||||
"devtools_traits 0.0.1",
|
"devtools_traits 0.0.1",
|
||||||
|
@ -822,7 +832,6 @@ dependencies = [
|
||||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
"uuid 0.1.11 (git+https://github.com/rust-lang/uuid)",
|
"uuid 0.1.11 (git+https://github.com/rust-lang/uuid)",
|
||||||
"xlib 0.1.0 (git+https://github.com/servo/rust-xlib)",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue