diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-04-11 18:42:16 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-04-21 11:10:02 +0000 |
commit | 6fe967c4b0abaffccb4301f7167b08916da4d80f (patch) | |
tree | 4c1bbc02956b6977cb111ea2014174a83a73743f /src/core/render_widget_host_view_qt.cpp | |
parent | 0c9e2eae483dc777b9f53819d23805abc80e51d8 (diff) |
Implement proper touch handling on macOS
Use the OS provided QNativeGestureEvents for pinching and smart
zooming. This replaces the usage of the Android based gesture
recognizer on macOS.
This also implements multitouch gestures to work with the Qt Quick
implementation of QtWebEngine for macOS, because touch events
are ignored by default on macOS in QQuickItem.
Task-number: QTBUG-58779
Change-Id: I17399e4e89a57557540b2fd0940a445326b682f3
Reviewed-by: Florian Bruhin <qt-project.org@the-compiler.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index ab9fb66fb..96cddfb4b 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -905,6 +905,9 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event) case QEvent::TouchCancel: handleTouchEvent(static_cast<QTouchEvent*>(event)); break; + case QEvent::NativeGesture: + handleGestureEvent(static_cast<QNativeGestureEvent *>(event)); + break; case QEvent::HoverEnter: case QEvent::HoverLeave: case QEvent::HoverMove: @@ -1295,8 +1298,24 @@ void RenderWidgetHostViewQt::clearPreviousTouchMotionState() m_touchMotionStarted = false; } +void RenderWidgetHostViewQt::handleGestureEvent(QNativeGestureEvent *ev) +{ + const Qt::NativeGestureType type = ev->gestureType(); + // These are the only supported gestures by Chromium so far. + if (type == Qt::ZoomNativeGesture || type == Qt::SmartZoomNativeGesture) { + m_host->ForwardGestureEvent(WebEventFactory::toWebGestureEvent( + ev, + static_cast<double>(dpiScale()))); + } +} + void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) { + // On macOS instead of handling touch events, we use the OS provided QNativeGestureEvents. +#ifdef Q_OS_MACOS + return; +#endif + // Chromium expects the touch event timestamps to be comparable to base::TimeTicks::Now(). // Most importantly we also have to preserve the relative time distance between events. // Calculate a delta between event timestamps and Now() on the first received event, and |