ohos: Add basic IME and keyboard support (#34188)

* ohos: Add basic IME and keyboard support

- Add extremely basic support for keyboard events
- Add basic IME support
   - Showing and hiding the IME
   - inserting text
   - deleting characters
   - very basic configuration of the IME

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Apply suggestions from code review

Improve the log message

Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>

* Update ports/servoshell/egl/ohos.rs

Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com>
Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>

* ohos: Bump the minimum required SDK version to 5.0

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: Remove pub from callbacks

The callbacks don't need to be public, as we will be registering them.

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Rename composition event

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: clippy in log

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: address some clippy warnings

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* ohos: Raise Error in mach if unsupported SDK version is used.

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

* Add keyboard-types dependency for android

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>

---------

Signed-off-by: Jonathan Schwender <jonathan.schwender@huawei.com>
Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Mukilan Thiyagarajan <mukilanthiagarajan@gmail.com>
This commit is contained in:
Jonathan Schwender 2024-11-15 16:04:48 +01:00 committed by GitHub
parent c64d5e9d30
commit 538ac61a82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 320 additions and 63 deletions

View file

@ -8,7 +8,8 @@ use std::os::raw::c_void;
use std::rc::Rc;
use ipc_channel::ipc::IpcSender;
use log::{debug, info, warn};
use keyboard_types::{CompositionEvent, CompositionState};
use log::{debug, error, info, warn};
use servo::base::id::WebViewId;
use servo::compositing::windowing::{
AnimationState, EmbedderCoordinates, EmbedderEvent, EmbedderMethods, MouseWindowEvent,
@ -155,7 +156,7 @@ impl ServoGlue {
/// to act on its pending events.
pub fn perform_updates(&mut self) -> Result<(), &'static str> {
debug!("perform_updates");
let events = mem::replace(&mut self.events, Vec::new());
let events = mem::take(&mut self.events);
self.servo.handle_events(events);
let r = self.handle_servo_events();
debug!("done perform_updates");
@ -274,7 +275,7 @@ impl ServoGlue {
let event = EmbedderEvent::Touch(
TouchEventType::Down,
TouchId(pointer_id),
Point2D::new(x as f32, y as f32),
Point2D::new(x, y),
);
self.process_event(event)
}
@ -284,18 +285,15 @@ impl ServoGlue {
let event = EmbedderEvent::Touch(
TouchEventType::Move,
TouchId(pointer_id),
Point2D::new(x as f32, y as f32),
Point2D::new(x, y),
);
self.process_event(event)
}
/// Touch event: Lift touching finger
pub fn touch_up(&mut self, x: f32, y: f32, pointer_id: i32) -> Result<(), &'static str> {
let event = EmbedderEvent::Touch(
TouchEventType::Up,
TouchId(pointer_id),
Point2D::new(x as f32, y as f32),
);
let event =
EmbedderEvent::Touch(TouchEventType::Up, TouchId(pointer_id), Point2D::new(x, y));
self.process_event(event)
}
@ -304,7 +302,7 @@ impl ServoGlue {
let event = EmbedderEvent::Touch(
TouchEventType::Cancel,
TouchId(pointer_id),
Point2D::new(x as f32, y as f32),
Point2D::new(x, y),
);
self.process_event(event)
}
@ -374,6 +372,13 @@ impl ServoGlue {
self.process_event(EmbedderEvent::Keyboard(key_event))
}
pub fn ime_insert_text(&mut self, text: String) -> Result<(), &'static str> {
self.process_event(EmbedderEvent::IMEComposition(CompositionEvent {
state: CompositionState::End,
data: text,
}))
}
pub fn pause_compositor(&mut self) -> Result<(), &'static str> {
self.process_event(EmbedderEvent::InvalidateNativeSurface)
}
@ -619,11 +624,13 @@ impl ServoGlue {
EmbedderMsg::ReadyToPresent(_webview_ids) => {
self.need_present = true;
},
EmbedderMsg::Keyboard(..) => {
error!("Received unexpected keyboard event");
},
EmbedderMsg::Status(..) |
EmbedderMsg::SelectFiles(..) |
EmbedderMsg::MoveTo(..) |
EmbedderMsg::ResizeTo(..) |
EmbedderMsg::Keyboard(..) |
EmbedderMsg::SetCursor(..) |
EmbedderMsg::NewFavicon(..) |
EmbedderMsg::HeadParsed |