mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
Auto merge of #22871 - jdm:simpleml, r=ajeffrey,paul
Use simpleservo embedding API for Magic Leap This removes the duplication between the two ports and makes it easier to improve all of our embeddings simultaneously. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #22065 - [x] These changes do not require tests because no automated tests for embedded devices. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22871) <!-- Reviewable:end -->
This commit is contained in:
commit
cfb401eea9
11 changed files with 266 additions and 386 deletions
|
@ -39,3 +39,4 @@ oculusvr = ["libservo/oculusvr"]
|
|||
native-bluetooth = ["libservo/native-bluetooth"]
|
||||
webgl_backtrace = ["libservo/webgl_backtrace"]
|
||||
js_backtrace = ["libservo/js_backtrace"]
|
||||
no_static_freetype = ["libservo/no_static_freetype"]
|
||||
|
|
|
@ -7,14 +7,17 @@ extern crate log;
|
|||
|
||||
pub mod gl_glue;
|
||||
|
||||
pub use servo::script_traits::MouseButton;
|
||||
|
||||
use servo::compositing::windowing::{
|
||||
AnimationState, EmbedderCoordinates, MouseWindowEvent, WindowEvent, WindowMethods,
|
||||
};
|
||||
use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods};
|
||||
use servo::embedder_traits::EmbedderMsg;
|
||||
use servo::euclid::{TypedPoint2D, TypedScale, TypedSize2D, TypedVector2D};
|
||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
use servo::msg::constellation_msg::TraversalDirection;
|
||||
use servo::script_traits::{MouseButton, TouchEventType, TouchId};
|
||||
use servo::script_traits::{TouchEventType, TouchId};
|
||||
use servo::servo_config::opts;
|
||||
use servo::servo_config::prefs::{PrefValue, PREFS};
|
||||
use servo::servo_url::ServoUrl;
|
||||
|
@ -82,6 +85,8 @@ pub trait HostTrait {
|
|||
fn on_animating_changed(&self, animating: bool);
|
||||
/// Servo finished shutting down.
|
||||
fn on_shutdown_complete(&self);
|
||||
/// A text input is focused.
|
||||
fn on_ime_state_changed(&self, show: bool);
|
||||
}
|
||||
|
||||
pub struct ServoGlue {
|
||||
|
@ -276,12 +281,12 @@ impl ServoGlue {
|
|||
/// Start scrolling.
|
||||
/// x/y are scroll coordinates.
|
||||
/// dx/dy are scroll deltas.
|
||||
pub fn scroll_start(&mut self, dx: i32, dy: i32, x: u32, y: u32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx as f32, dy as f32);
|
||||
pub fn scroll_start(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx, dy);
|
||||
let scroll_location = webrender_api::ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(
|
||||
scroll_location,
|
||||
TypedPoint2D::new(x as i32, y as i32),
|
||||
TypedPoint2D::new(x, y),
|
||||
TouchEventType::Down,
|
||||
);
|
||||
self.process_event(event)
|
||||
|
@ -290,12 +295,12 @@ impl ServoGlue {
|
|||
/// Scroll.
|
||||
/// x/y are scroll coordinates.
|
||||
/// dx/dy are scroll deltas.
|
||||
pub fn scroll(&mut self, dx: i32, dy: i32, x: u32, y: u32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx as f32, dy as f32);
|
||||
pub fn scroll(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx, dy);
|
||||
let scroll_location = webrender_api::ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(
|
||||
scroll_location,
|
||||
TypedPoint2D::new(x as i32, y as i32),
|
||||
TypedPoint2D::new(x, y),
|
||||
TouchEventType::Move,
|
||||
);
|
||||
self.process_event(event)
|
||||
|
@ -304,14 +309,11 @@ impl ServoGlue {
|
|||
/// End scrolling.
|
||||
/// x/y are scroll coordinates.
|
||||
/// dx/dy are scroll deltas.
|
||||
pub fn scroll_end(&mut self, dx: i32, dy: i32, x: u32, y: u32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx as f32, dy as f32);
|
||||
pub fn scroll_end(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = TypedVector2D::new(dx, dy);
|
||||
let scroll_location = webrender_api::ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(
|
||||
scroll_location,
|
||||
TypedPoint2D::new(x as i32, y as i32),
|
||||
TouchEventType::Up,
|
||||
);
|
||||
let event =
|
||||
WindowEvent::Scroll(scroll_location, TypedPoint2D::new(x, y), TouchEventType::Up);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -355,6 +357,27 @@ impl ServoGlue {
|
|||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Register a mouse movement.
|
||||
pub fn move_mouse(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
|
||||
let point = TypedPoint2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowMoveEventClass(point);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Register a mouse button press.
|
||||
pub fn mouse_down(&mut self, x: f32, y: f32, button: MouseButton) -> Result<(), &'static str> {
|
||||
let point = TypedPoint2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseDown(button, point));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Register a mouse button release.
|
||||
pub fn mouse_up(&mut self, x: f32, y: f32, button: MouseButton) -> Result<(), &'static str> {
|
||||
let point = TypedPoint2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseUp(button, point));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Start pinchzoom.
|
||||
/// x/y are pinch origin coordinates.
|
||||
pub fn pinchzoom_start(&mut self, factor: f32, _x: u32, _y: u32) -> Result<(), &'static str> {
|
||||
|
@ -374,13 +397,30 @@ impl ServoGlue {
|
|||
}
|
||||
|
||||
/// Perform a click.
|
||||
pub fn click(&mut self, x: u32, y: u32) -> Result<(), &'static str> {
|
||||
let mouse_event =
|
||||
MouseWindowEvent::Click(MouseButton::Left, TypedPoint2D::new(x as f32, y as f32));
|
||||
pub fn click(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
|
||||
let mouse_event = MouseWindowEvent::Click(MouseButton::Left, TypedPoint2D::new(x, y));
|
||||
let event = WindowEvent::MouseWindowEventClass(mouse_event);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
pub fn key_down(&mut self, key: Key) -> Result<(), &'static str> {
|
||||
let key_event = KeyboardEvent {
|
||||
state: KeyState::Down,
|
||||
key,
|
||||
..KeyboardEvent::default()
|
||||
};
|
||||
self.process_event(WindowEvent::Keyboard(key_event))
|
||||
}
|
||||
|
||||
pub fn key_up(&mut self, key: Key) -> Result<(), &'static str> {
|
||||
let key_event = KeyboardEvent {
|
||||
state: KeyState::Up,
|
||||
key,
|
||||
..KeyboardEvent::default()
|
||||
};
|
||||
self.process_event(WindowEvent::Keyboard(key_event))
|
||||
}
|
||||
|
||||
fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
|
||||
self.events.push(event);
|
||||
if !self.batch_mode {
|
||||
|
|
|
@ -40,6 +40,7 @@ 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),
|
||||
}
|
||||
|
||||
/// Servo options
|
||||
|
@ -191,19 +192,19 @@ pub extern "C" fn go_forward() {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn scroll_start(dx: i32, dy: i32, x: i32, y: i32) {
|
||||
debug!("scroll_start");
|
||||
call(|s| s.scroll_start(dx as i32, dy as i32, x as u32, y as u32));
|
||||
call(|s| s.scroll_start(dx as f32, dy as f32, x, y));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn scroll_end(dx: i32, dy: i32, x: i32, y: i32) {
|
||||
debug!("scroll_end");
|
||||
call(|s| s.scroll_end(dx as i32, dy as i32, x as u32, y as u32));
|
||||
call(|s| s.scroll_end(dx as f32, dy as f32, x, y));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn scroll(dx: i32, dy: i32, x: i32, y: i32) {
|
||||
debug!("scroll");
|
||||
call(|s| s.scroll(dx as i32, dy as i32, x as u32, y as u32));
|
||||
call(|s| s.scroll(dx as f32, dy as f32, x, y));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -251,7 +252,7 @@ pub extern "C" fn pinchzoom_end(factor: f32, x: i32, y: i32) {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn click(x: i32, y: i32) {
|
||||
debug!("click");
|
||||
call(|s| s.click(x as u32, y as u32));
|
||||
call(|s| s.click(x as f32, y as f32));
|
||||
}
|
||||
|
||||
pub struct WakeupCallback(extern "C" fn());
|
||||
|
@ -330,4 +331,9 @@ impl HostTrait for HostCallbacks {
|
|||
debug!("on_shutdown_complete");
|
||||
(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_scrollStart(
|
|||
) {
|
||||
debug!("scrollStart");
|
||||
call(&env, |s| {
|
||||
s.scroll_start(dx as i32, dy as i32, x as u32, y as u32)
|
||||
s.scroll_start(dx as f32, dy as f32, x as i32, y as i32)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_scrollEnd(
|
|||
) {
|
||||
debug!("scrollEnd");
|
||||
call(&env, |s| {
|
||||
s.scroll_end(dx as i32, dy as i32, x as u32, y as u32)
|
||||
s.scroll_end(dx as f32, dy as f32, x as i32, y as i32)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_scroll(
|
|||
y: jint,
|
||||
) {
|
||||
debug!("scroll");
|
||||
call(&env, |s| s.scroll(dx as i32, dy as i32, x as u32, y as u32));
|
||||
call(&env, |s| s.scroll(dx as f32, dy as f32, x as i32, y as i32));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -321,7 +321,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_pinchZoomEnd(
|
|||
#[no_mangle]
|
||||
pub fn Java_org_mozilla_servoview_JNIServo_click(env: JNIEnv, _: JClass, x: jint, y: jint) {
|
||||
debug!("click");
|
||||
call(&env, |s| s.click(x as u32, y as u32));
|
||||
call(&env, |s| s.click(x as f32, y as f32));
|
||||
}
|
||||
|
||||
pub struct WakeupCallback {
|
||||
|
@ -454,6 +454,8 @@ impl HostTrait for HostCallbacks {
|
|||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn on_ime_state_changed(&self, _show: bool) {}
|
||||
}
|
||||
|
||||
fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue