From 6fe967c4b0abaffccb4301f7167b08916da4d80f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 11 Apr 2017 18:42:16 +0200 Subject: 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 Reviewed-by: Joerg Bornemann --- src/core/web_event_factory.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/core/web_event_factory.cpp') 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(ev->localPos().x() / dpiScale); + webKitEvent.y = static_cast(ev->localPos().y() / dpiScale); + + webKitEvent.globalX = static_cast(ev->screenPos().x() / dpiScale); + webKitEvent.globalY = static_cast(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(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; -- cgit v1.2.3