From d18891b0c5267b1db8f19fcef64c9a4f8f03f76f Mon Sep 17 00:00:00 2001 From: Ted de Munnik Date: Fri, 8 May 2020 18:36:01 +0200 Subject: [PATCH] Wasm druid-shell backend fills out MouseEvent for wheel --- druid-shell/src/platform/web/window.rs | 30 +++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/druid-shell/src/platform/web/window.rs b/druid-shell/src/platform/web/window.rs index 282bd07ec0..5d63739b1f 100644 --- a/druid-shell/src/platform/web/window.rs +++ b/druid-shell/src/platform/web/window.rs @@ -199,20 +199,26 @@ fn setup_scroll_callback(ws: &Rc) { let height = state.canvas.height() as f64; let width = state.canvas.width() as f64; - let modifiers = get_modifiers!(event); - let mut handler = state.handler.borrow_mut(); - // The value 35.0 was manually picked to produce similar behavior to mac/linux. - match delta_mode { - web_sys::WheelEvent::DOM_DELTA_PIXEL => handler.wheel(Vec2::from((dx, dy)), modifiers), - web_sys::WheelEvent::DOM_DELTA_LINE => { - handler.wheel(Vec2::from((35.0 * dx, 35.0 * dy)), modifiers) - } - web_sys::WheelEvent::DOM_DELTA_PAGE => { - handler.wheel(Vec2::from((width * dx, height * dy)), modifiers) + let wheel_delta = match delta_mode { + web_sys::WheelEvent::DOM_DELTA_PIXEL => Vec2::new(dx, dy) + web_sys::WheelEvent::DOM_DELTA_LINE => Vec2::new(35.0 * dx, 35.0 * dy), + web_sys::WheelEvent::DOM_DELTA_PAGE => Vec2::new(width * dx, height * dy), + _ => { + log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode); + return; } - _ => log::warn!("Invalid deltaMode in WheelEvent: {}", delta_mode), - } + }; + + let event = MouseEvent { + pos: Point::new(event.offset_x() as f64, event.offset_y() as f64), + buttons: mouse_buttons(event.buttons()), + mods: get_modifiers!(event), + count: 0, + button: MouseButton::None, + wheel_delta: wheel_delta + }; + state.handler.borrow_mut().wheel(&event); }); }