From 72f83c2dd578e6ac1812e647785e8a42f0997ee3 Mon Sep 17 00:00:00 2001 From: Ilya Bogdanov Date: Wed, 26 Apr 2023 15:26:51 +0300 Subject: [PATCH] Rollback event handling changes for the mouse (#6396) Fixes #6385 Partial rollback of #6364 It turns out that preventing default for mouse events is a bad idea in general. It shouldn't affect other fixed bugs because (afaik) all of them were caused by keyboard events. We're still preventing default for keyboard events. --- lib/rust/ensogl/core/src/control/io/mouse/event.rs | 13 +++++-------- .../core/src/display/navigation/navigator/events.rs | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/rust/ensogl/core/src/control/io/mouse/event.rs b/lib/rust/ensogl/core/src/control/io/mouse/event.rs index 094f3c221e9..f6476f7b06a 100644 --- a/lib/rust/ensogl/core/src/control/io/mouse/event.rs +++ b/lib/rust/ensogl/core/src/control/io/mouse/event.rs @@ -54,7 +54,6 @@ where JsEvent: AsRef { /// Constructor. pub fn new(js_event: JsEvent, shape: Shape) -> Self { - js_event.as_ref().prevent_default(); let js_event = Some(js_event); let event_type = default(); Self { js_event, shape, event_type } @@ -175,6 +174,11 @@ where JsEvent: AsRef self.js_event.as_ref().map(|t| t.as_ref().ctrl_key()).unwrap_or_default() } + /// Prevent the default action of the event. + pub fn prevent_default(&self) { + self.js_event.as_ref().map(|t| t.as_ref().prevent_default()); + } + /// Convert the event to a different type. No checks will be performed during this action. pub fn unchecked_convert_to( self, @@ -225,13 +229,6 @@ define_events! { // - https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event // - https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseup_event // - https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event - // - // ## Preventing default - // - // To avoid triggerring any builtin bevavior of the browser, we call [`preventDefault`] on all - // mouse events. - // - // [`preventDefault`]: https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault /// The [`Down`] event is fired at an element when a button on a pointing device (such as a /// mouse or trackpad) is pressed while the pointer is inside the element. diff --git a/lib/rust/ensogl/core/src/display/navigation/navigator/events.rs b/lib/rust/ensogl/core/src/display/navigation/navigator/events.rs index 8be201e456c..7e8b6ddfa5c 100644 --- a/lib/rust/ensogl/core/src/display/navigation/navigator/events.rs +++ b/lib/rust/ensogl/core/src/display/navigation/navigator/events.rs @@ -239,6 +239,10 @@ impl NavigatorEvents { let listener = self.mouse_manager.on_wheel.add(move |event: &mouse::Wheel| { if let Some(data) = data.upgrade() { if event.ctrl_key() { + // Prevent zoom event to be handed to the browser. This avoids browser scaling + // being applied to the whole IDE, thus we need to do this always when ctrl is + // pressed. + event.prevent_default(); let position = data.mouse_position(); let zoom_speed = data.zoom_speed(); let movement = Vector2::new(event.delta_x() as f32, -event.delta_y() as f32);