QtPanGestureRecognizer.cpp [plain text]
#include "config.h"
#include "QtPanGestureRecognizer.h"
#include "QtViewportInteractionEngine.h"
#include "QtWebPageEventHandler.h"
namespace WebKit {
QtPanGestureRecognizer::QtPanGestureRecognizer(QtWebPageEventHandler* eventHandler)
: QtGestureRecognizer(eventHandler)
{
reset();
}
bool QtPanGestureRecognizer::update(const QTouchEvent::TouchPoint& touchPoint, qint64 eventTimestampMillis)
{
if (!interactionEngine())
return false;
m_lastPosition = touchPoint.pos();
m_lastEventTimestampMillis = eventTimestampMillis;
switch (m_state) {
case NoGesture:
m_state = GestureRecognitionStarted;
m_firstScreenPosition = touchPoint.scenePos();
interactionEngine()->cancelScrollAnimation();
return false;
case GestureRecognitionStarted: {
QPointF totalOffsetFromStart(touchPoint.scenePos() - m_firstScreenPosition);
if (qAbs(totalOffsetFromStart.x()) < panningInitialTriggerDistanceThreshold && qAbs(totalOffsetFromStart.y()) < panningInitialTriggerDistanceThreshold)
return false;
m_state = GestureRecognized;
interactionEngine()->panGestureStarted(touchPoint.pos(), eventTimestampMillis);
return true;
}
case GestureRecognized:
interactionEngine()->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;
ASSERT(interactionEngine());
interactionEngine()->panGestureEnded(touchPoint.pos(), eventTimestampMillis);
reset();
}
void QtPanGestureRecognizer::cancel()
{
if (m_state == NoGesture)
return;
interactionEngine()->panGestureEnded(m_lastPosition, m_lastEventTimestampMillis);
interactionEngine()->panGestureCancelled();
reset();
}
}