ScrollLatchingController.h [plain text]
#pragma once
#include "FloatSize.h"
#include "ScrollTypes.h"
#include "Timer.h"
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
#if ENABLE(WHEEL_EVENT_LATCHING)
namespace WTF {
class TextStream;
}
namespace WebCore {
class Element;
class Frame;
class PlatformWheelEvent;
class ScrollableArea;
class ScrollLatchingController {
WTF_MAKE_FAST_ALLOCATED;
public:
ScrollLatchingController();
~ScrollLatchingController();
void clear();
void receivedWheelEvent(const PlatformWheelEvent&);
FloatSize cumulativeEventDelta() const { return m_cumulativeEventDelta; }
Frame* latchedFrame() const;
bool latchingAllowsScrollingInFrame(const Frame&, WeakPtr<ScrollableArea>& latchedScroller) const;
void updateAndFetchLatchingStateForFrame(Frame&, const PlatformWheelEvent&, RefPtr<Element>& latchedElement, WeakPtr<ScrollableArea>&, bool& isOverWidget);
void removeLatchingStateForTarget(const Element&);
void removeLatchingStateForFrame(const Frame&);
void dump(WTF::TextStream&) const;
private:
struct FrameState {
WeakPtr<Element> wheelEventElement;
WeakPtr<ScrollableArea> scrollableArea;
Frame* frame { nullptr };
bool isOverWidget { false };
};
void clearOrScheduleClearIfNeeded(const PlatformWheelEvent&);
void clearTimerFired();
bool hasStateForFrame(const Frame&) const;
FrameState* stateForFrame(const Frame&);
const FrameState* stateForFrame(const Frame&) const;
bool shouldLatchToScrollableArea(const Frame&, ScrollableArea*, FloatSize) const;
FloatSize m_cumulativeEventDelta;
Vector<FrameState> m_frameStateStack;
Timer m_clearLatchingStateTimer;
};
WTF::TextStream& operator<<(WTF::TextStream&, const ScrollLatchingController&);
}
#endif // ENABLE(WHEEL_EVENT_LATCHING)