Desktop: Trackpad pinch to zoom (#3271)
* prototype pinch gesture * pinch to zoom * fix
This commit is contained in:
parent
34d0b76333
commit
717defb2bb
|
|
@ -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_X: f32 = 3.0;
|
||||||
pub(crate) const SCROLL_SPEED_Y: 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_TIMEOUT: Duration = Duration::from_millis(500);
|
||||||
pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4;
|
pub(crate) const MULTICLICK_ALLOWED_TRAVEL: usize = 4;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use winit::event::{ButtonSource, ElementState, MouseButton, MouseScrollDelta, Wi
|
||||||
mod keymap;
|
mod keymap;
|
||||||
use keymap::{ToNativeKeycode, ToVKBits};
|
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) {
|
pub(crate) fn handle_window_event(browser: &Browser, input_state: &mut InputState, event: &WindowEvent) {
|
||||||
match event {
|
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);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue