mirror of
https://github.com/servo/servo.git
synced 2025-10-01 00:59:15 +01:00
UWP: support virtual keyboard
This commit is contained in:
parent
19b36bd795
commit
34265c872e
11 changed files with 143 additions and 43 deletions
|
@ -14,10 +14,11 @@ use rust_webvr::api::MagicLeapVRService;
|
|||
use servo::euclid::Scale;
|
||||
use servo::keyboard_types::Key;
|
||||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_api::units::{DevicePixel, DevicePoint, LayoutPixel};
|
||||
use servo::webrender_api::units::{DeviceIntRect, DevicePixel, DevicePoint, LayoutPixel};
|
||||
use simpleservo::{self, deinit, gl_glue, MouseButton, ServoGlue, SERVO};
|
||||
use simpleservo::{
|
||||
Coordinates, EventLoopWaker, HostTrait, InitOptions, PromptResult, VRInitOptions,
|
||||
Coordinates, EventLoopWaker, HostTrait, InitOptions, InputMethodType, PromptResult,
|
||||
VRInitOptions,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
use std::cell::Cell;
|
||||
|
@ -412,9 +413,20 @@ impl HostTrait for HostCallbacks {
|
|||
self.shut_down_complete.set(true);
|
||||
}
|
||||
|
||||
fn on_ime_state_changed(&self, show: bool) {
|
||||
fn on_ime_show(
|
||||
&self,
|
||||
_input_type: InputMethodType,
|
||||
_text: Option<String>,
|
||||
_bounds: DeviceIntRect,
|
||||
) {
|
||||
if let Some(keyboard) = self.keyboard.0 {
|
||||
keyboard(self.app, show)
|
||||
keyboard(self.app, true)
|
||||
}
|
||||
}
|
||||
|
||||
fn on_ime_hide(&self) {
|
||||
if let Some(keyboard) = self.keyboard.0 {
|
||||
keyboard(self.app, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ pub use servo::config::prefs::{add_user_prefs, PrefValue};
|
|||
pub use servo::embedder_traits::{
|
||||
ContextMenuResult, MediaSessionPlaybackState, PermissionPrompt, PermissionRequest, PromptResult,
|
||||
};
|
||||
pub use servo::msg::constellation_msg::InputMethodType;
|
||||
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
||||
pub use servo::webrender_api::units::DeviceIntRect;
|
||||
|
||||
use getopts::Options;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
|
@ -133,7 +135,9 @@ pub trait HostTrait {
|
|||
/// Servo finished shutting down.
|
||||
fn on_shutdown_complete(&self);
|
||||
/// A text input is focused.
|
||||
fn on_ime_state_changed(&self, show: bool);
|
||||
fn on_ime_show(&self, input_type: InputMethodType, text: Option<String>, bounds: DeviceIntRect);
|
||||
/// Input lost focus
|
||||
fn on_ime_hide(&self);
|
||||
/// Gets sytem clipboard contents.
|
||||
fn get_clipboard_contents(&self) -> Option<String>;
|
||||
/// Sets system clipboard contents.
|
||||
|
@ -721,11 +725,13 @@ impl ServoGlue {
|
|||
|
||||
let _ = sender.send(result);
|
||||
},
|
||||
EmbedderMsg::ShowIME(..) => {
|
||||
self.callbacks.host_callbacks.on_ime_state_changed(true);
|
||||
EmbedderMsg::ShowIME(kind, text, bounds) => {
|
||||
self.callbacks
|
||||
.host_callbacks
|
||||
.on_ime_show(kind, text, bounds);
|
||||
},
|
||||
EmbedderMsg::HideIME => {
|
||||
self.callbacks.host_callbacks.on_ime_state_changed(false);
|
||||
self.callbacks.host_callbacks.on_ime_hide();
|
||||
},
|
||||
EmbedderMsg::MediaSessionEvent(event) => {
|
||||
match event {
|
||||
|
|
|
@ -20,8 +20,8 @@ use keyboard_types::Key;
|
|||
use log::LevelFilter;
|
||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||
use simpleservo::{
|
||||
ContextMenuResult, Coordinates, EventLoopWaker, HostTrait, InitOptions, MediaSessionActionType,
|
||||
MediaSessionPlaybackState, MouseButton, PromptResult,
|
||||
ContextMenuResult, Coordinates, DeviceIntRect, EventLoopWaker, HostTrait, InitOptions,
|
||||
InputMethodType, MediaSessionActionType, MediaSessionPlaybackState, MouseButton, PromptResult,
|
||||
};
|
||||
use std::ffi::{CStr, CString};
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -212,7 +212,8 @@ pub struct CHostCallbacks {
|
|||
pub on_history_changed: extern "C" fn(can_go_back: bool, can_go_forward: bool),
|
||||
pub on_animating_changed: extern "C" fn(animating: bool),
|
||||
pub on_shutdown_complete: extern "C" fn(),
|
||||
pub on_ime_state_changed: extern "C" fn(show: bool),
|
||||
pub on_ime_show: extern "C" fn(text: *const c_char, x: i32, y: i32, width: i32, height: i32),
|
||||
pub on_ime_hide: extern "C" fn(),
|
||||
pub get_clipboard_contents: extern "C" fn() -> *const c_char,
|
||||
pub set_clipboard_contents: extern "C" fn(contents: *const c_char),
|
||||
pub on_media_session_metadata:
|
||||
|
@ -834,9 +835,30 @@ impl HostTrait for HostCallbacks {
|
|||
(self.0.on_shutdown_complete)();
|
||||
}
|
||||
|
||||
fn on_ime_state_changed(&self, show: bool) {
|
||||
debug!("on_ime_state_changed");
|
||||
(self.0.on_ime_state_changed)(show);
|
||||
fn on_ime_show(
|
||||
&self,
|
||||
_input_type: InputMethodType,
|
||||
text: Option<String>,
|
||||
bounds: DeviceIntRect,
|
||||
) {
|
||||
debug!("on_ime_show");
|
||||
let text = text.and_then(|s| CString::new(s).ok());
|
||||
let text_ptr = text
|
||||
.as_ref()
|
||||
.map(|cstr| cstr.as_ptr())
|
||||
.unwrap_or(std::ptr::null());
|
||||
(self.0.on_ime_show)(
|
||||
text_ptr,
|
||||
bounds.origin.x,
|
||||
bounds.origin.y,
|
||||
bounds.size.width,
|
||||
bounds.size.height,
|
||||
);
|
||||
}
|
||||
|
||||
fn on_ime_hide(&self) {
|
||||
debug!("on_ime_hide");
|
||||
(self.0.on_ime_hide)();
|
||||
}
|
||||
|
||||
fn get_clipboard_contents(&self) -> Option<String> {
|
||||
|
|
|
@ -14,10 +14,11 @@ use jni::sys::{jboolean, jfloat, jint, jstring, JNI_TRUE};
|
|||
use jni::{errors, JNIEnv, JavaVM};
|
||||
use libc::{dup2, pipe, read};
|
||||
use log::Level;
|
||||
use simpleservo::{self, deinit, gl_glue, MouseButton, ServoGlue, SERVO};
|
||||
use simpleservo::{self, gl_glue, ServoGlue, SERVO};
|
||||
use simpleservo::{
|
||||
Coordinates, EventLoopWaker, HostTrait, InitOptions, MediaSessionPlaybackState, PromptResult,
|
||||
VRInitOptions,
|
||||
Coordinates, DeviceIntRect, EventLoopWaker, HostTrait, InitOptions, InputMethodType,
|
||||
MediaSessionPlaybackState, PromptResult, VRInitOptions,
|
||||
};
|
||||
use std::os::raw::{c_char, c_int, c_void};
|
||||
use std::ptr::{null, null_mut};
|
||||
|
@ -529,7 +530,8 @@ impl HostTrait for HostCallbacks {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_ime_state_changed(&self, _show: bool) {}
|
||||
fn on_ime_show(&self, _type: InputEncoding, _text: Option<String>, _rect: DeviceIntRect) {}
|
||||
fn on_ime_hide(&self) {}
|
||||
|
||||
fn get_clipboard_contents(&self) -> Option<String> {
|
||||
None
|
||||
|
|
|
@ -498,7 +498,7 @@ where
|
|||
let permission_state = prompt_user(prompt);
|
||||
let _ = sender.send(permission_state);
|
||||
}
|
||||
EmbedderMsg::ShowIME(_kind) => {
|
||||
EmbedderMsg::ShowIME(_kind, _text, _rect) => {
|
||||
debug!("ShowIME received");
|
||||
},
|
||||
EmbedderMsg::HideIME => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue