mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add HostTrait methods get_clipboard_contents set_clipboard_contents, and call them instead of directly handlind clipboard
This commit is contained in:
parent
588cec0422
commit
caaa2a425c
4 changed files with 17 additions and 29 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4311,7 +4311,6 @@ source = "git+https://github.com/pcwalton/signpost.git#7ed712507f343c38646b9d1fe
|
||||||
name = "simpleservo"
|
name = "simpleservo"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clipboard 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"core-foundation 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gl_generator 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.53 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -7,7 +7,6 @@ edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clipboard = "0.5"
|
|
||||||
libservo = { path = "../../../components/servo" }
|
libservo = { path = "../../../components/servo" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ pub mod gl_glue;
|
||||||
|
|
||||||
pub use servo::script_traits::MouseButton;
|
pub use servo::script_traits::MouseButton;
|
||||||
|
|
||||||
use clipboard::{ClipboardContext, ClipboardProvider};
|
|
||||||
use servo::compositing::windowing::{
|
use servo::compositing::windowing::{
|
||||||
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
||||||
WindowMethods,
|
WindowMethods,
|
||||||
|
@ -112,6 +111,10 @@ pub trait HostTrait {
|
||||||
fn on_shutdown_complete(&self);
|
fn on_shutdown_complete(&self);
|
||||||
/// A text input is focused.
|
/// A text input is focused.
|
||||||
fn on_ime_state_changed(&self, show: bool);
|
fn on_ime_state_changed(&self, show: bool);
|
||||||
|
/// Gets sytem clipboard contents
|
||||||
|
fn get_clipboard_contents(&self) -> Option<String>;
|
||||||
|
/// Sets system clipboard contents
|
||||||
|
fn set_clipboard_contents(&self, contents: String);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ServoGlue {
|
pub struct ServoGlue {
|
||||||
|
@ -128,7 +131,6 @@ pub struct ServoGlue {
|
||||||
browsers: Vec<BrowserId>,
|
browsers: Vec<BrowserId>,
|
||||||
events: Vec<WindowEvent>,
|
events: Vec<WindowEvent>,
|
||||||
current_url: Option<ServoUrl>,
|
current_url: Option<ServoUrl>,
|
||||||
clipboard_ctx: Option<ClipboardContext>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn servo_version() -> String {
|
pub fn servo_version() -> String {
|
||||||
|
@ -195,13 +197,6 @@ pub fn init(
|
||||||
browsers: vec![],
|
browsers: vec![],
|
||||||
events: vec![],
|
events: vec![],
|
||||||
current_url: Some(url.clone()),
|
current_url: Some(url.clone()),
|
||||||
clipboard_ctx: match ClipboardContext::new() {
|
|
||||||
Ok(c) => Some(c),
|
|
||||||
Err(e) => {
|
|
||||||
warn!("Error creating clipboard context ({})", e);
|
|
||||||
None
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
let browser_id = BrowserId::new();
|
let browser_id = BrowserId::new();
|
||||||
let _ = servo_glue.process_event(WindowEvent::NewBrowser(url, browser_id));
|
let _ = servo_glue.process_event(WindowEvent::NewBrowser(url, browser_id));
|
||||||
|
@ -527,26 +522,11 @@ impl ServoGlue {
|
||||||
self.events.push(WindowEvent::SelectBrowser(new_browser_id));
|
self.events.push(WindowEvent::SelectBrowser(new_browser_id));
|
||||||
},
|
},
|
||||||
EmbedderMsg::GetClipboardContents(sender) => {
|
EmbedderMsg::GetClipboardContents(sender) => {
|
||||||
let contents = match self.clipboard_ctx {
|
let contents = self.callbacks.host_callbacks.get_clipboard_contents();
|
||||||
Some(ref mut ctx) => match ctx.get_contents() {
|
sender.send(contents.unwrap_or("".to_owned()));
|
||||||
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) {
|
|
||||||
warn!("Failed to send clipboard ({})", e);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
EmbedderMsg::SetClipboardContents(text) => {
|
EmbedderMsg::SetClipboardContents(text) => {
|
||||||
if let Some(ref mut ctx) = self.clipboard_ctx {
|
self.callbacks.host_callbacks.set_clipboard_contents(text);
|
||||||
if let Err(e) = ctx.set_contents(text) {
|
|
||||||
warn!("Error setting clipboard contents ({})", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
EmbedderMsg::CloseBrowser => {
|
EmbedderMsg::CloseBrowser => {
|
||||||
// TODO: close the appropriate "tab".
|
// TODO: close the appropriate "tab".
|
||||||
|
|
|
@ -43,6 +43,8 @@ pub struct CHostCallbacks {
|
||||||
pub on_animating_changed: extern "C" fn(animating: bool),
|
pub on_animating_changed: extern "C" fn(animating: bool),
|
||||||
pub on_shutdown_complete: extern "C" fn(),
|
pub on_shutdown_complete: extern "C" fn(),
|
||||||
pub on_ime_state_changed: extern "C" fn(show: bool),
|
pub on_ime_state_changed: extern "C" fn(show: bool),
|
||||||
|
pub get_clipboard_contents: extern "C" fn() -> *const c_char,
|
||||||
|
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Servo options
|
/// Servo options
|
||||||
|
@ -347,4 +349,12 @@ impl HostTrait for HostCallbacks {
|
||||||
debug!("on_ime_state_changed");
|
debug!("on_ime_state_changed");
|
||||||
(self.0.on_ime_state_changed)(show);
|
(self.0.on_ime_state_changed)(show);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_clipboard_contents(&self) -> Option<String> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_clipboard_contents(&self, contents: String) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue