mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #28308 - philip-lamb:phil-ime-textentry, r=jdm
Improve IME messaging to embedder with insertion point index and mult… …iline flag. <!-- Please describe your changes on the following line: --> This improves handling of IME requests in the embedder by passing the location of the insertion point along with the current text, and a boolean flag 'multiline' (true for HTML textarea, false otherwise) which allows the embedder to be more clever about handling of the 'enter' or 'return' keys. Tested and working in an embedding example. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
94e337f22f
8 changed files with 58 additions and 16 deletions
|
@ -416,7 +416,8 @@ impl HostTrait for HostCallbacks {
|
|||
fn on_ime_show(
|
||||
&self,
|
||||
_input_type: InputMethodType,
|
||||
_text: Option<String>,
|
||||
_text: Option<(String, i32)>,
|
||||
_multiline: bool,
|
||||
_bounds: DeviceIntRect,
|
||||
) {
|
||||
if let Some(keyboard) = self.keyboard.0 {
|
||||
|
|
|
@ -141,7 +141,13 @@ pub trait HostTrait {
|
|||
/// Servo finished shutting down.
|
||||
fn on_shutdown_complete(&self);
|
||||
/// A text input is focused.
|
||||
fn on_ime_show(&self, input_type: InputMethodType, text: Option<String>, bounds: DeviceIntRect);
|
||||
fn on_ime_show(
|
||||
&self,
|
||||
input_type: InputMethodType,
|
||||
text: Option<(String, i32)>,
|
||||
multiline: bool,
|
||||
bounds: DeviceIntRect,
|
||||
);
|
||||
/// Input lost focus
|
||||
fn on_ime_hide(&self);
|
||||
/// Gets sytem clipboard contents.
|
||||
|
@ -742,10 +748,10 @@ impl ServoGlue {
|
|||
|
||||
let _ = sender.send(result);
|
||||
},
|
||||
EmbedderMsg::ShowIME(kind, text, bounds) => {
|
||||
EmbedderMsg::ShowIME(kind, text, multiline, bounds) => {
|
||||
self.callbacks
|
||||
.host_callbacks
|
||||
.on_ime_show(kind, text, bounds);
|
||||
.on_ime_show(kind, text, multiline, bounds);
|
||||
},
|
||||
EmbedderMsg::HideIME => {
|
||||
self.callbacks.host_callbacks.on_ime_hide();
|
||||
|
|
|
@ -205,7 +205,15 @@ 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_show: extern "C" fn(text: *const c_char, x: i32, y: i32, width: i32, height: i32),
|
||||
pub on_ime_show: extern "C" fn(
|
||||
text: *const c_char,
|
||||
text_index: i32,
|
||||
multiline: bool,
|
||||
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),
|
||||
|
@ -808,17 +816,21 @@ impl HostTrait for HostCallbacks {
|
|||
fn on_ime_show(
|
||||
&self,
|
||||
_input_type: InputMethodType,
|
||||
text: Option<String>,
|
||||
text: Option<(String, i32)>,
|
||||
multiline: bool,
|
||||
bounds: DeviceIntRect,
|
||||
) {
|
||||
debug!("on_ime_show");
|
||||
let text = text.and_then(|s| CString::new(s).ok());
|
||||
let text_index = text.as_ref().map_or(0, |(_, i)| *i);
|
||||
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,
|
||||
text_index,
|
||||
multiline,
|
||||
bounds.origin.x,
|
||||
bounds.origin.y,
|
||||
bounds.size.width,
|
||||
|
|
|
@ -530,7 +530,14 @@ impl HostTrait for HostCallbacks {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_ime_show(&self, _type: InputEncoding, _text: Option<String>, _rect: DeviceIntRect) {}
|
||||
fn on_ime_show(
|
||||
&self,
|
||||
_type: InputEncoding,
|
||||
_text: Option<(String, i32)>,
|
||||
_multiline: bool,
|
||||
_rect: DeviceIntRect,
|
||||
) {
|
||||
}
|
||||
fn on_ime_hide(&self) {}
|
||||
|
||||
fn get_clipboard_contents(&self) -> Option<String> {
|
||||
|
|
|
@ -487,7 +487,7 @@ where
|
|||
let permission_state = prompt_user(prompt);
|
||||
let _ = sender.send(permission_state);
|
||||
},
|
||||
EmbedderMsg::ShowIME(_kind, _text, _rect) => {
|
||||
EmbedderMsg::ShowIME(_kind, _text, _multiline, _rect) => {
|
||||
debug!("ShowIME received");
|
||||
},
|
||||
EmbedderMsg::HideIME => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue