WheelEventDeltaTracker.cpp [plain text]
#include "config.h"
#include "WheelEventDeltaTracker.h"
#include "PlatformWheelEvent.h"
namespace WebCore {
WheelEventDeltaTracker::WheelEventDeltaTracker()
: m_isTrackingDeltas(false)
{
}
WheelEventDeltaTracker::~WheelEventDeltaTracker()
{
}
void WheelEventDeltaTracker::beginTrackingDeltas()
{
m_recentWheelEventDeltas.clear();
m_isTrackingDeltas = true;
}
void WheelEventDeltaTracker::endTrackingDeltas()
{
m_isTrackingDeltas = false;
}
void WheelEventDeltaTracker::recordWheelEventDelta(const PlatformWheelEvent& event)
{
m_recentWheelEventDeltas.append(FloatSize(event.deltaX(), event.deltaY()));
if (m_recentWheelEventDeltas.size() > recentEventCount)
m_recentWheelEventDeltas.removeFirst();
}
static bool deltaIsPredominantlyVertical(const FloatSize& delta)
{
return fabs(delta.height()) > fabs(delta.width());
}
DominantScrollGestureDirection WheelEventDeltaTracker::dominantScrollGestureDirection() const
{
bool allVertical = m_recentWheelEventDeltas.size();
bool allHorizontal = m_recentWheelEventDeltas.size();
for (const auto& delta : m_recentWheelEventDeltas) {
bool isVertical = deltaIsPredominantlyVertical(delta);
allVertical &= isVertical;
allHorizontal &= !isVertical;
}
if (allVertical)
return DominantScrollGestureDirection::Vertical;
if (allHorizontal)
return DominantScrollGestureDirection::Horizontal;
return DominantScrollGestureDirection::None;
}
}