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
This commit is contained in:
alvinhochun 2020-08-22 08:23:08 +08:00 committed by GitHub
parent 6ba583d198
commit 0f7c82d38f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View file

@ -198,9 +198,9 @@ Legend:
|Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|**N/A**| |Mouse set location |✔️ |✔️ |✔️ |❓ |**N/A**|**N/A**|**N/A**|
|Cursor grab |✔️ |▢[#165] |▢[#242] |✔️ |**N/A**|**N/A**|❓ | |Cursor grab |✔️ |▢[#165] |▢[#242] |✔️ |**N/A**|**N/A**|❓ |
|Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ | |Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ |
|Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ |✔️ | |Touch events |✔️ |❌ |✔️ |✔️ |✔️ |✔️ | |
|Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ |✔️ | |Touch pressure |✔️ |❌ |❌ |❌ |❌ |✔️ | |
|Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ |✔️ | |Multitouch |✔️ |❌ |✔️ |✔️ |❓ |✔️ | |
|Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ | |Keyboard events |✔️ |✔️ |✔️ |✔️ |❓ |❌ |✔️ |
|Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ | |Drag & Drop |▢[#720] |▢[#720] |▢[#720] |❌[#306] |**N/A**|**N/A**|❓ |
|Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ | |Raw Device Events |▢[#750] |▢[#750] |▢[#750] |❌ |❌ |❌ |❓ |

View file

@ -133,7 +133,18 @@ impl<T> WindowTarget<T> {
}); });
let runner = self.runner.clone(); 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 { runner.send_event(Event::WindowEvent {
window_id: WindowId(id), window_id: WindowId(id),
event: WindowEvent::MouseInput { event: WindowEvent::MouseInput {

View file

@ -200,11 +200,12 @@ impl Canvas {
pub fn on_mouse_press<F>(&mut self, mut handler: F) pub fn on_mouse_press<F>(&mut self, mut handler: F)
where where
F: 'static + FnMut(i32, MouseButton, ModifiersState), F: 'static + FnMut(i32, PhysicalPosition<f64>, MouseButton, ModifiersState),
{ {
self.on_mouse_press = Some(self.add_user_event(move |event: PointerDownEvent| { self.on_mouse_press = Some(self.add_user_event(move |event: PointerDownEvent| {
handler( handler(
event.pointer_id(), event.pointer_id(),
event::mouse_position(&event).to_physical(super::scale_factor()),
event::mouse_button(&event), event::mouse_button(&event),
event::mouse_modifiers(&event), event::mouse_modifiers(&event),
); );

View file

@ -248,7 +248,7 @@ impl Canvas {
pub fn on_mouse_press<F>(&mut self, mut handler: F) pub fn on_mouse_press<F>(&mut self, mut handler: F)
where where
F: 'static + FnMut(i32, MouseButton, ModifiersState), F: 'static + FnMut(i32, PhysicalPosition<f64>, MouseButton, ModifiersState),
{ {
if has_pointer_event() { if has_pointer_event() {
self.on_pointer_press = Some(self.add_user_event( self.on_pointer_press = Some(self.add_user_event(
@ -256,6 +256,7 @@ impl Canvas {
move |event: PointerEvent| { move |event: PointerEvent| {
handler( handler(
event.pointer_id(), event.pointer_id(),
event::mouse_position(&event).to_physical(super::scale_factor()),
event::mouse_button(&event), event::mouse_button(&event),
event::mouse_modifiers(&event), event::mouse_modifiers(&event),
); );
@ -266,6 +267,7 @@ impl Canvas {
Some(self.add_user_event("mousedown", move |event: MouseEvent| { Some(self.add_user_event("mousedown", move |event: MouseEvent| {
handler( handler(
0, 0,
event::mouse_position(&event).to_physical(super::scale_factor()),
event::mouse_button(&event), event::mouse_button(&event),
event::mouse_modifiers(&event), event::mouse_modifiers(&event),
); );