QtPanGestureRecognizer.cpp [plain text]
#include "config.h"
#include "QtPanGestureRecognizer.h"
#include "PageViewportControllerClientQt.h"
#include "QtWebPageEventHandler.h"
namespace WebKit {
QtPanGestureRecognizer::QtPanGestureRecognizer(QtWebPageEventHandler* eventHandler)
: QtGestureRecognizer(eventHandler)
{
reset();
}
bool QtPanGestureRecognizer::update(const QTouchEvent::TouchPoint& touchPoint, qint64 eventTimestampMillis)
{
m_lastPosition = touchPoint.pos();
m_lastEventTimestampMillis = eventTimestampMillis;
switch (m_state) {
case NoGesture:
m_state = GestureRecognitionStarted;
m_firstScreenPosition = touchPoint.screenPos();
if (viewportController())
viewportController()->cancelScrollAnimation();
return false;
case GestureRecognitionStarted: {
QPointF totalOffsetFromStart(touchPoint.screenPos() - m_firstScreenPosition);
if (qAbs(totalOffsetFromStart.x()) < panningInitialTriggerDistanceThreshold && qAbs(totalOffsetFromStart.y()) < panningInitialTriggerDistanceThreshold)
return false;
m_state = GestureRecognized;
if (viewportController())
viewportController()->panGestureStarted(touchPoint.pos(), eventTimestampMillis);
return true;
}
case GestureRecognized:
if (viewportController())
viewportController()->panGestureRequestUpdate(touchPoint.pos(), eventTimestampMillis);
return true;
default:
ASSERT_NOT_REACHED();
}
return false;
}
void QtPanGestureRecognizer::finish(const QTouchEvent::TouchPoint& touchPoint, qint64 eventTimestampMillis)
{
if (m_state == NoGesture)
return;
if (viewportController())
viewportController()->panGestureEnded(touchPoint.pos(), eventTimestampMillis);
reset();
}
void QtPanGestureRecognizer::cancel()
{
if (m_state == NoGesture)
return;
if (viewportController()) {
viewportController()->panGestureEnded(m_lastPosition, m_lastEventTimestampMillis);
viewportController()->panGestureCancelled();
}
reset();
}
}