summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2017-04-11 18:42:16 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2017-04-21 11:10:02 +0000
commit6fe967c4b0abaffccb4301f7167b08916da4d80f (patch)
tree4c1bbc02956b6977cb111ea2014174a83a73743f
parent0c9e2eae483dc777b9f53819d23805abc80e51d8 (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>
-rw-r--r--src/core/render_widget_host_view_qt.cpp19
-rw-r--r--src/core/render_widget_host_view_qt.h1
-rw-r--r--src/core/web_event_factory.cpp37
-rw-r--r--src/core/web_event_factory.h3
-rw-r--r--src/webengine/render_widget_host_view_qt_delegate_quick.cpp3
5 files changed, 63 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
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 304fa0e1a..09e027497 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -189,6 +189,7 @@ public:
void handleKeyEvent(QKeyEvent*);
void handleWheelEvent(QWheelEvent*);
void handleTouchEvent(QTouchEvent*);
+ void handleGestureEvent(QNativeGestureEvent *);
void handleHoverEvent(QHoverEvent*);
void handleFocusEvent(QFocusEvent*);
void handleInputMethodEvent(QInputMethodEvent*);
diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp
index 2cd15aa58..a7df934e4 100644
--- a/src/core/web_event_factory.cpp
+++ b/src/core/web_event_factory.cpp
@@ -1212,6 +1212,43 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale)
return webKitEvent;
}
+WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev, double dpiScale)
+{
+ WebGestureEvent webKitEvent;
+ webKitEvent.timeStampSeconds = currentTimeForEvent(ev);
+ webKitEvent.modifiers = modifiersForEvent(ev);
+
+ webKitEvent.x = static_cast<int>(ev->localPos().x() / dpiScale);
+ webKitEvent.y = static_cast<int>(ev->localPos().y() / dpiScale);
+
+ webKitEvent.globalX = static_cast<int>(ev->screenPos().x() / dpiScale);
+ webKitEvent.globalY = static_cast<int>(ev->screenPos().y() / dpiScale);
+
+ webKitEvent.sourceDevice = blink::WebGestureDeviceTouchpad;
+
+ Qt::NativeGestureType gestureType = ev->gestureType();
+ switch (gestureType) {
+ case Qt::ZoomNativeGesture:
+ webKitEvent.type = WebInputEvent::GesturePinchUpdate;
+ webKitEvent.data.pinchUpdate.scale = static_cast<float>(ev->value() + 1.0);
+ break;
+ case Qt::SmartZoomNativeGesture:
+ webKitEvent.type = WebInputEvent::GestureDoubleTap;
+ webKitEvent.data.tap.tapCount = 1;
+ break;
+ case Qt::BeginNativeGesture:
+ case Qt::EndNativeGesture:
+ case Qt::RotateNativeGesture:
+ case Qt::PanNativeGesture:
+ case Qt::SwipeNativeGesture:
+ // Not implemented by Chromium for now.
+ webKitEvent.type = blink::WebInputEvent::Undefined;
+ break;
+ }
+
+ return webKitEvent;
+}
+
blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, double dpiScale)
{
WebMouseWheelEvent webEvent;
diff --git a/src/core/web_event_factory.h b/src/core/web_event_factory.h
index c9871a4b9..d82113db3 100644
--- a/src/core/web_event_factory.h
+++ b/src/core/web_event_factory.h
@@ -42,6 +42,7 @@
#include "content/public/browser/native_web_keyboard_event.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h"
+#include "third_party/WebKit/public/platform/WebGestureEvent.h"
#include <QtGlobal>
@@ -50,6 +51,7 @@ class QHoverEvent;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
+class QNativeGestureEvent;
QT_END_NAMESPACE
class WebEventFactory {
@@ -57,6 +59,7 @@ class WebEventFactory {
public:
static blink::WebMouseEvent toWebMouseEvent(QMouseEvent*, double dpiScale);
static blink::WebMouseEvent toWebMouseEvent(QHoverEvent*, double dpiScale);
+ static blink::WebGestureEvent toWebGestureEvent(QNativeGestureEvent *, double dpiScale);
static blink::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*, double dpiScale);
static content::NativeWebKeyboardEvent toWebKeyboardEvent(QKeyEvent*);
};
diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
index 4e4fc406f..b3348b43e 100644
--- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
+++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp
@@ -247,6 +247,9 @@ bool RenderWidgetHostViewQtDelegateQuick::event(QEvent *event)
}
}
+ if (event->type() == QEvent::NativeGesture)
+ return m_client->forwardEvent(event);
+
return QQuickItem::event(event);
}