void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled) { if (wasEventHandled || event.type() == WebEvent::TouchCancel) { m_panGestureRecognizer.cancel(); m_pinchGestureRecognizer.cancel(); if (event.type() != WebEvent::TouchMove) m_tapGestureRecognizer.cancel(); return; } const QTouchEvent* ev = event.nativeEvent(); handleInputEvent(ev); }
void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled) { if (!m_interactionEngine) return; if (wasEventHandled || event.type() == WebEvent::TouchCancel) { resetGestureRecognizers(); return; } const QTouchEvent* ev = event.nativeEvent(); switch (ev->type()) { case QEvent::TouchBegin: ASSERT(!m_interactionEngine->panGestureActive()); ASSERT(!m_interactionEngine->pinchGestureActive()); // The interaction engine might still be animating kinetic scrolling or a scale animation // such as double-tap to zoom or the bounce back effect. A touch stops the kinetic scrolling // where as it does not stop the scale animation. if (m_interactionEngine->scrollAnimationActive()) m_interactionEngine->interruptScrollAnimation(); break; case QEvent::TouchUpdate: // The scale animation can only be interrupted by a pinch gesture, which will then take over. if (m_interactionEngine->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized()) m_interactionEngine->interruptScaleAnimation(); break; default: break; } // If the scale animation is active we don't pass the event to the recognizers. In the future // we would want to queue the event here and repost then when the animation ends. if (m_interactionEngine->scaleAnimationActive()) return; // Convert the event timestamp from second to millisecond. qint64 eventTimestampMillis = static_cast<qint64>(event.timestamp() * 1000); m_panGestureRecognizer.recognize(ev, eventTimestampMillis); m_pinchGestureRecognizer.recognize(ev); if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized()) m_tapGestureRecognizer.reset(); else { const QTouchEvent* ev = event.nativeEvent(); m_tapGestureRecognizer.recognize(ev, eventTimestampMillis); } }
void QtWebPageEventHandler::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled) { if (!m_interactionEngine) return; if (wasEventHandled || event.type() == WebEvent::TouchCancel) { resetGestureRecognizers(); return; } const QTouchEvent* ev = event.nativeEvent(); switch (ev->type()) { case QEvent::TouchBegin: ASSERT(!m_interactionEngine->panGestureActive()); ASSERT(!m_interactionEngine->pinchGestureActive()); m_interactionEngine->touchBegin(); // The interaction engine might still be animating kinetic scrolling or a scale animation // such as double-tap to zoom or the bounce back effect. A touch stops the kinetic scrolling // where as it does not stop the scale animation. // The gesture recognizer stops the kinetic scrolling animation if needed. break; case QEvent::TouchUpdate: // The scale animation can only be interrupted by a pinch gesture, which will then take over. if (m_interactionEngine->scaleAnimationActive() && m_pinchGestureRecognizer.isRecognized()) m_interactionEngine->interruptScaleAnimation(); break; case QEvent::TouchEnd: m_interactionEngine->touchEnd(); break; default: break; } // If the scale animation is active we don't pass the event to the recognizers. In the future // we would want to queue the event here and repost then when the animation ends. if (m_interactionEngine->scaleAnimationActive()) return; const QList<QTouchEvent::TouchPoint>& touchPoints = ev->touchPoints(); const int touchPointCount = touchPoints.size(); qint64 eventTimestampMillis = ev->timestamp(); QList<QTouchEvent::TouchPoint> activeTouchPoints; activeTouchPoints.reserve(touchPointCount); for (int i = 0; i < touchPointCount; ++i) { if (touchPoints[i].state() != Qt::TouchPointReleased) activeTouchPoints << touchPoints[i]; } const int activeTouchPointCount = activeTouchPoints.size(); if (!activeTouchPointCount) { if (touchPointCount == 1) { // No active touch points, one finger released. if (!m_panGestureRecognizer.isRecognized()) m_tapGestureRecognizer.update(ev->type(), touchPoints.first()); m_panGestureRecognizer.finish(touchPoints.first(), eventTimestampMillis); } else m_pinchGestureRecognizer.finish(); // Early return since this was a touch-end event. return; } else if (activeTouchPointCount == 1) { // If the pinch gesture recognizer was previously in active state the content might // be out of valid zoom boundaries, thus we need to finish the pinch gesture here. // This will resume the content to valid zoom levels before the pan gesture is started. m_pinchGestureRecognizer.finish(); m_panGestureRecognizer.update(activeTouchPoints.first(), eventTimestampMillis); } else if (activeTouchPointCount == 2) { m_panGestureRecognizer.cancel(); m_pinchGestureRecognizer.update(activeTouchPoints.first(), activeTouchPoints.last()); } if (m_panGestureRecognizer.isRecognized() || m_pinchGestureRecognizer.isRecognized() || m_webView->isMoving()) m_tapGestureRecognizer.cancel(); else if (touchPointCount == 1) m_tapGestureRecognizer.update(ev->type(), touchPoints.first()); }