ScrollSnapAnimatorState.h [plain text]
#ifndef ScrollSnapAnimatorState_h
#define ScrollSnapAnimatorState_h
#if ENABLE(CSS_SCROLL_SNAP)
#include "AxisScrollSnapOffsets.h"
#include "FloatPoint.h"
#include "FloatSize.h"
#include "LayoutUnit.h"
#include "PlatformWheelEvent.h"
#include "ScrollTypes.h"
namespace WebCore {
enum class ScrollSnapState {
Snapping,
Gliding,
DestinationReached,
UserInteraction
};
struct ScrollSnapAnimatorState {
ScrollSnapAnimatorState(ScrollEventAxis, const Vector<LayoutUnit>&);
void pushInitialWheelDelta(float);
float averageInitialWheelDelta() const;
void clearInitialWheelDeltaWindow();
bool isSnapping() const;
bool canReachTargetWithCurrentInitialScrollDelta() const;
bool wheelDeltaTrackingIsInProgress() const;
bool hasFinishedTrackingWheelDeltas() const;
float interpolatedOffsetAtProgress(float) const;
static const int wheelDeltaWindowSize = 3;
Vector<LayoutUnit> m_snapOffsets;
ScrollEventAxis m_axis;
ScrollSnapState m_currentState;
LayoutUnit m_initialOffset;
LayoutUnit m_targetOffset;
LayoutUnit m_beginTrackingWheelDeltaOffset;
int m_numWheelDeltasTracked { 0 };
unsigned m_activeSnapIndex { 0 };
float m_wheelDeltaWindow[wheelDeltaWindowSize];
float m_initialScrollDelta { 0 };
bool m_shouldOverrideWheelEvent { false };
};
struct ScrollSnapAnimationCurveState {
void initializeSnapProgressCurve(const FloatSize&, const FloatSize&, const FloatSize&);
void initializeInterpolationCoefficientsIfNecessary(const FloatSize&, const FloatSize&, const FloatSize&);
FloatPoint interpolatedPositionAtProgress(float) const;
bool shouldCompleteSnapAnimationImmediatelyAtTime(double) const;
float animationProgressAtTime(double) const;
bool shouldAnimateDirectlyToSnapPoint { false };
private:
double m_startTime { 0 };
float m_snapAnimationCurveMagnitude { 0 };
float m_snapAnimationDecayFactor { 0 };
FloatSize m_snapAnimationCurveCoefficients[4] { };
};
}
#endif // ENABLE(CSS_SCROLL_SNAP)
#endif // ScrollSnapAnimatorState_h