diff --git a/desktop/src/cef/consts.rs b/desktop/src/cef/consts.rs index e89862ef..fd61a58d 100644 --- a/desktop/src/cef/consts.rs +++ b/desktop/src/cef/consts.rs @@ -8,5 +8,7 @@ pub(crate) const SCROLL_LINE_WIDTH: usize = 40; pub(crate) const SCROLL_SPEED_X: f32 = 3.0; pub(crate) const SCROLL_SPEED_Y: f32 = 3.0; +pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.0; + pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500); pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4; diff --git a/desktop/src/cef/input.rs b/desktop/src/cef/input.rs index fc8449d8..feb9eff5 100644 --- a/desktop/src/cef/input.rs +++ b/desktop/src/cef/input.rs @@ -7,7 +7,7 @@ use winit::event::{ButtonSource, ElementState, MouseButton, MouseScrollDelta, Wi mod keymap; use keymap::{ToNativeKeycode, ToVKBits}; -use super::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y}; +use super::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y}; pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputState, event: &WindowEvent) { match event { @@ -129,6 +129,20 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat } } } + WindowEvent::PinchGesture { delta, .. } => { + if !delta.is_normal() { + return; + } + let Some(host) = browser.host() else { return }; + + let mut mouse_event: MouseEvent = input_state.into(); + mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN as u32; + mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_PRECISION_SCROLLING_DELTA as u32; + + let delta = (delta * PINCH_ZOOM_SPEED).round() as i32; + + host.send_mouse_wheel_event(Some(&mouse_event), 0, delta); + } _ => {} } }