Skip to content

Commit 717defb

Browse files
Desktop: Trackpad pinch to zoom (#3271)
* prototype pinch gesture * pinch to zoom * fix
1 parent 34d0b76 commit 717defb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

desktop/src/cef/consts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ pub(crate) const SCROLL_LINE_WIDTH: usize = 40;
88
pub(crate) const SCROLL_SPEED_X: f32 = 3.0;
99
pub(crate) const SCROLL_SPEED_Y: f32 = 3.0;
1010

11+
pub(crate) const PINCH_ZOOM_SPEED: f64 = 300.0;
12+
1113
pub(crate) const MULTICLICK_TIMEOUT: Duration = Duration::from_millis(500);
1214
pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4;

desktop/src/cef/input.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use winit::event::{ButtonSource, ElementState, MouseButton, MouseScrollDelta, Wi
77
mod keymap;
88
use keymap::{ToNativeKeycode, ToVKBits};
99

10-
use super::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y};
10+
use super::consts::{MULTICLICK_ALLOWED_TRAVEL, MULTICLICK_TIMEOUT, PINCH_ZOOM_SPEED, SCROLL_LINE_HEIGHT, SCROLL_LINE_WIDTH, SCROLL_SPEED_X, SCROLL_SPEED_Y};
1111

1212
pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputState, event: &WindowEvent) {
1313
match event {
@@ -129,6 +129,20 @@ pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputStat
129129
}
130130
}
131131
}
132+
WindowEvent::PinchGesture { delta, .. } => {
133+
if !delta.is_normal() {
134+
return;
135+
}
136+
let Some(host) = browser.host() else { return };
137+
138+
let mut mouse_event: MouseEvent = input_state.into();
139+
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_CONTROL_DOWN as u32;
140+
mouse_event.modifiers |= cef_event_flags_t::EVENTFLAG_PRECISION_SCROLLING_DELTA as u32;
141+
142+
let delta = (delta * PINCH_ZOOM_SPEED).round() as i32;
143+
144+
host.send_mouse_wheel_event(Some(&mouse_event), 0, delta);
145+
}
132146
_ => {}
133147
}
134148
}

0 commit comments

Comments
 (0)