diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a0dbabf..250ef38a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Unreleased +- On Web, prevent the webpage from scrolling when the user is focused on a winit canvas # 0.22.2 (2020-05-16) diff --git a/src/platform_impl/web/stdweb/canvas.rs b/src/platform_impl/web/stdweb/canvas.rs index f6ed4866..64f6a18f 100644 --- a/src/platform_impl/web/stdweb/canvas.rs +++ b/src/platform_impl/web/stdweb/canvas.rs @@ -10,9 +10,9 @@ use stdweb::js; use stdweb::traits::IPointerEvent; use stdweb::unstable::TryInto; use stdweb::web::event::{ - BlurEvent, ConcreteEvent, FocusEvent, FullscreenChangeEvent, KeyDownEvent, KeyPressEvent, - KeyUpEvent, MouseWheelEvent, PointerDownEvent, PointerMoveEvent, PointerOutEvent, - PointerOverEvent, PointerUpEvent, + BlurEvent, ConcreteEvent, FocusEvent, FullscreenChangeEvent, IEvent, KeyDownEvent, + KeyPressEvent, KeyUpEvent, MouseWheelEvent, PointerDownEvent, PointerMoveEvent, + PointerOutEvent, PointerOverEvent, PointerUpEvent, }; use stdweb::web::html_element::CanvasElement; use stdweb::web::{ @@ -130,6 +130,7 @@ impl Canvas { F: 'static + FnMut(ScanCode, Option, ModifiersState), { self.on_keyboard_release = Some(self.add_user_event(move |event: KeyUpEvent| { + event.prevent_default(); handler( event::scan_code(&event), event::virtual_key_code(&event), @@ -143,6 +144,7 @@ impl Canvas { F: 'static + FnMut(ScanCode, Option, ModifiersState), { self.on_keyboard_press = Some(self.add_user_event(move |event: KeyDownEvent| { + event.prevent_default(); handler( event::scan_code(&event), event::virtual_key_code(&event), @@ -228,6 +230,7 @@ impl Canvas { F: 'static + FnMut(i32, MouseScrollDelta, ModifiersState), { self.on_mouse_wheel = Some(self.add_event(move |event: MouseWheelEvent| { + event.prevent_default(); if let Some(delta) = event::mouse_scroll_delta(&event) { handler(0, delta, 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 a2755b95..e8fd3a2b 100644 --- a/src/platform_impl/web/web_sys/canvas.rs +++ b/src/platform_impl/web/web_sys/canvas.rs @@ -135,6 +135,7 @@ impl Canvas { { self.on_keyboard_release = Some(self.add_user_event("keyup", move |event: KeyboardEvent| { + event.prevent_default(); handler( event::scan_code(&event), event::virtual_key_code(&event), @@ -149,6 +150,7 @@ impl Canvas { { self.on_keyboard_press = Some(self.add_user_event("keydown", move |event: KeyboardEvent| { + event.prevent_default(); handler( event::scan_code(&event), event::virtual_key_code(&event), @@ -242,6 +244,7 @@ impl Canvas { F: 'static + FnMut(i32, MouseScrollDelta, ModifiersState), { self.on_mouse_wheel = Some(self.add_event("wheel", move |event: WheelEvent| { + event.prevent_default(); if let Some(delta) = event::mouse_scroll_delta(&event) { handler(0, delta, event::mouse_modifiers(&event)); }