UI/Qt: Handle pinch zoom gestures
Translate Qt native zoom gestures into Web::PinchEvent for the web content view. This gives the Qt UI the same pinch-to-zoom input path as the AppKit UI while leaving ordinary wheel scrolling unchanged. Map the Qt native gesture screen position back into WebContentView before creating the event, since macOS delivers the gesture through the top-level widget window after forwarding. Keeping the pinch focal point in content coordinates lets visual viewport zoom preserve the user's focus point.
This commit is contained in:
parent
7cc81327a1
commit
bc22063e30
1 changed files with 13 additions and 0 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include <QKeySequence>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QNativeGestureEvent>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include <QPalette>
|
||||
|
|
@ -946,6 +947,18 @@ bool WebContentView::event(QEvent* event)
|
|||
keyReleaseEvent(static_cast<QKeyEvent*>(event));
|
||||
return true;
|
||||
}
|
||||
if (event->type() == QEvent::NativeGesture) {
|
||||
auto const& native_gesture_event = *static_cast<QNativeGestureEvent const*>(event);
|
||||
if (native_gesture_event.gestureType() == Qt::ZoomNativeGesture) {
|
||||
Web::PinchEvent pinch_event;
|
||||
auto const local_position = mapFromGlobal(native_gesture_event.globalPosition());
|
||||
pinch_event.position = { local_position.x() * m_device_pixel_ratio, local_position.y() * m_device_pixel_ratio };
|
||||
pinch_event.modifiers = get_modifiers_from_qt_keyboard_modifiers(native_gesture_event.modifiers());
|
||||
pinch_event.scale_delta = native_gesture_event.value();
|
||||
enqueue_input_event(AK::move(pinch_event));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::PaletteChange || event->type() == QEvent::ApplicationPaletteChange || event->type() == QEvent::ThemeChange) {
|
||||
QTimer::singleShot(0, this, [this] {
|
||||
|
|
|
|||
Loading…
Reference in a new issue