From 0f7c82d38fbe52831a51d5b2523e838d1da02407 Mon Sep 17 00:00:00 2001 From: alvinhochun Date: Sat, 22 Aug 2020 08:23:08 +0800 Subject: [PATCH] Send CursorMove before mouse press event and note that touch is unimplemented on web target (#1668) * Change to send CursorMove before mouse press event on web target * Fix feature matrix to indicate touch being unimplemented on web --- FEATURES.md | 6 +++--- src/platform_impl/web/event_loop/window_target.rs | 13 ++++++++++++- src/platform_impl/web/stdweb/canvas.rs | 3 ++- src/platform_impl/web/web_sys/canvas.rs | 4 +++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index cdd8cc9f..d7791f5b 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -198,9 +198,9 @@ Legend: |Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|**N/A**| |Cursor grab |✔️ |▢[#165] |▢[#242] |✔️ |**N/A**|**N/A**|❓ | |Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ | -|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |✔️ | -|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |✔️ | -|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |✔️ | +|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |❌ | +|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |❌ | +|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |❌ | |Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ | |Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ | |Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ | diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 3ba5e1d2..d1851ea0 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -133,7 +133,18 @@ impl WindowTarget { }); let runner = self.runner.clone(); - canvas.on_mouse_press(move |pointer_id, button, modifiers| { + canvas.on_mouse_press(move |pointer_id, position, button, modifiers| { + // A mouse down event may come in without any prior CursorMoved events, + // therefore we should send a CursorMoved event to make sure that the + // user code has the correct cursor position. + runner.send_event(Event::WindowEvent { + window_id: WindowId(id), + event: WindowEvent::CursorMoved { + device_id: DeviceId(device::Id(pointer_id)), + position, + modifiers, + }, + }); runner.send_event(Event::WindowEvent { window_id: WindowId(id), event: WindowEvent::MouseInput { diff --git a/src/platform_impl/web/stdweb/canvas.rs b/src/platform_impl/web/stdweb/canvas.rs index 64f6a18f..51221837 100644 --- a/src/platform_impl/web/stdweb/canvas.rs +++ b/src/platform_impl/web/stdweb/canvas.rs @@ -200,11 +200,12 @@ impl Canvas { pub fn on_mouse_press(&mut self, mut handler: F) where - F: 'static + FnMut(i32, MouseButton, ModifiersState), + F: 'static + FnMut(i32, PhysicalPosition, MouseButton, ModifiersState), { self.on_mouse_press = Some(self.add_user_event(move |event: PointerDownEvent| { handler( event.pointer_id(), + event::mouse_position(&event).to_physical(super::scale_factor()), event::mouse_button(&event), event::mouse_modifiers(&event), ); diff --git a/src/platform_impl/web/web_sys/canvas.rs b/src/platform_impl/web/web_sys/canvas.rs index 617f6ed6..ae7e8091 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -248,7 +248,7 @@ impl Canvas { pub fn on_mouse_press(&mut self, mut handler: F) where - F: 'static + FnMut(i32, MouseButton, ModifiersState), + F: 'static + FnMut(i32, PhysicalPosition, MouseButton, ModifiersState), { if has_pointer_event() { self.on_pointer_press = Some(self.add_user_event( @@ -256,6 +256,7 @@ impl Canvas { move |event: PointerEvent| { handler( event.pointer_id(), + event::mouse_position(&event).to_physical(super::scale_factor()), event::mouse_button(&event), event::mouse_modifiers(&event), ); @@ -266,6 +267,7 @@ impl Canvas { Some(self.add_user_event("mousedown", move |event: MouseEvent| { handler( 0, + event::mouse_position(&event).to_physical(super::scale_factor()), event::mouse_button(&event), event::mouse_modifiers(&event), );