ScrollingCoordinator.h [plain text]
#pragma once
#include "EventTrackingRegions.h"
#include "LayoutRect.h"
#include "PlatformWheelEvent.h"
#include "ScrollSnapOffsetsInfo.h"
#include "ScrollTypes.h"
#include "ScrollingCoordinatorTypes.h"
#include <wtf/Forward.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/TypeCasts.h>
#include <wtf/Variant.h>
#if ENABLE(ASYNC_SCROLLING)
#include <wtf/HashMap.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Threading.h>
#endif
#if ENABLE(CSS_SCROLL_SNAP)
#include "AxisScrollSnapOffsets.h"
#endif
namespace WTF {
class TextStream;
}
namespace WebCore {
class AbsolutePositionConstraints;
class Document;
class Frame;
class FrameView;
class GraphicsLayer;
class Page;
class Region;
class RenderObject;
class RenderLayer;
class ScrollableArea;
class ViewportConstraints;
#if ENABLE(ASYNC_SCROLLING)
class ScrollingTree;
#endif
class ScrollingCoordinator : public ThreadSafeRefCounted<ScrollingCoordinator> {
public:
static Ref<ScrollingCoordinator> create(Page*);
virtual ~ScrollingCoordinator();
WEBCORE_EXPORT virtual void pageDestroyed();
virtual bool isAsyncScrollingCoordinator() const { return false; }
virtual bool isRemoteScrollingCoordinator() const { return false; }
WEBCORE_EXPORT virtual bool coordinatesScrollingForFrameView(const FrameView&) const;
WEBCORE_EXPORT virtual bool coordinatesScrollingForOverflowLayer(const RenderLayer&) const;
WEBCORE_EXPORT virtual ScrollingNodeID scrollableContainerNodeID(const RenderObject&) const;
virtual void frameViewLayoutUpdated(FrameView&) { }
using LayoutViewportOriginOrOverrideRect = WTF::Variant<Optional<FloatPoint>, Optional<FloatRect>>;
virtual void reconcileScrollingState(FrameView&, const FloatPoint&, const LayoutViewportOriginOrOverrideRect&, ScrollType, ViewportRectStability, ScrollingLayerPositionAction) { }
void frameViewHasSlowRepaintObjectsDidChange(FrameView&);
void frameViewFixedObjectsDidChange(FrameView&);
virtual void frameViewVisualViewportChanged(FrameView&) { }
virtual void frameViewEventTrackingRegionsChanged(FrameView&) { }
virtual void frameViewRootLayerDidChange(FrameView&);
virtual void applyScrollingTreeLayerPositions() { }
#if PLATFORM(COCOA)
void handleWheelEventPhase(PlatformWheelEventPhase);
#endif
WEBCORE_EXPORT void setForceSynchronousScrollLayerPositionUpdates(bool);
virtual void commitTreeStateIfNeeded() { }
virtual bool requestScrollPositionUpdate(ScrollableArea&, const IntPoint&, ScrollType = ScrollType::Programmatic, ScrollClamping = ScrollClamping::Clamped) { return false; }
virtual ScrollingEventResult handleWheelEvent(FrameView&, const PlatformWheelEvent&) { return ScrollingEventResult::DidNotHandleEvent; }
virtual ScrollingNodeID createNode(ScrollingNodeType, ScrollingNodeID newNodeID) { return newNodeID; }
virtual ScrollingNodeID insertNode(ScrollingNodeType, ScrollingNodeID newNodeID, ScrollingNodeID , size_t = notFound) { return newNodeID; }
virtual void unparentNode(ScrollingNodeID) { }
virtual void unparentChildrenAndDestroyNode(ScrollingNodeID) { }
virtual void detachAndDestroySubtree(ScrollingNodeID) { }
virtual void clearAllNodes() { }
virtual ScrollingNodeID parentOfNode(ScrollingNodeID) const { return 0; }
virtual Vector<ScrollingNodeID> childrenOfNode(ScrollingNodeID) const { return { }; }
struct NodeLayers {
GraphicsLayer* layer { nullptr };
GraphicsLayer* scrollContainerLayer { nullptr };
GraphicsLayer* scrolledContentsLayer { nullptr };
GraphicsLayer* counterScrollingLayer { nullptr };
GraphicsLayer* insetClipLayer { nullptr };
GraphicsLayer* rootContentsLayer { nullptr };
GraphicsLayer* horizontalScrollbarLayer { nullptr };
GraphicsLayer* verticalScrollbarLayer { nullptr };
};
virtual void setNodeLayers(ScrollingNodeID, const NodeLayers&) { }
virtual void setRectRelativeToParentNode(ScrollingNodeID, const LayoutRect&) { }
virtual void setScrollingNodeScrollableAreaGeometry(ScrollingNodeID, ScrollableArea&) { }
virtual void setFrameScrollingNodeState(ScrollingNodeID, const FrameView&) { }
virtual void setViewportConstraintedNodeConstraints(ScrollingNodeID, const ViewportConstraints&) { }
virtual void setPositionedNodeConstraints(ScrollingNodeID, const AbsolutePositionConstraints&) { }
virtual void setRelatedOverflowScrollingNodes(ScrollingNodeID, Vector<ScrollingNodeID>&&) { }
virtual void reconcileViewportConstrainedLayerPositions(ScrollingNodeID, const LayoutRect&, ScrollingLayerPositionAction) { }
virtual String scrollingStateTreeAsText(ScrollingStateTreeAsTextBehavior = ScrollingStateTreeAsTextBehaviorNormal) const;
virtual bool isRubberBandInProgress() const { return false; }
virtual bool isScrollSnapInProgress() const { return false; }
virtual void updateScrollSnapPropertiesWithFrameView(const FrameView&) { }
virtual void setScrollPinningBehavior(ScrollPinningBehavior) { }
ScrollingNodeID uniqueScrollingNodeID();
enum MainThreadScrollingReasonFlags {
ForcedOnMainThread = 1 << 0,
HasSlowRepaintObjects = 1 << 1,
HasViewportConstrainedObjectsWithoutSupportingFixedLayers = 1 << 2,
HasNonLayerViewportConstrainedObjects = 1 << 3,
IsImageDocument = 1 << 4
};
SynchronousScrollingReasons synchronousScrollingReasons(const FrameView&) const;
bool shouldUpdateScrollLayerPositionSynchronously(const FrameView&) const;
virtual void willDestroyScrollableArea(ScrollableArea&) { }
virtual void scrollableAreaScrollbarLayerDidChange(ScrollableArea&, ScrollbarOrientation) { }
static String synchronousScrollingReasonsAsText(SynchronousScrollingReasons);
String synchronousScrollingReasonsAsText() const;
EventTrackingRegions absoluteEventTrackingRegions() const;
virtual void updateIsMonitoringWheelEventsForFrameView(const FrameView&) { }
protected:
explicit ScrollingCoordinator(Page*);
GraphicsLayer* scrollContainerLayerForFrameView(FrameView&);
GraphicsLayer* scrolledContentsLayerForFrameView(FrameView&);
GraphicsLayer* counterScrollingLayerForFrameView(FrameView&);
GraphicsLayer* insetClipLayerForFrameView(FrameView&);
GraphicsLayer* rootContentsLayerForFrameView(FrameView&);
GraphicsLayer* contentShadowLayerForFrameView(FrameView&);
GraphicsLayer* headerLayerForFrameView(FrameView&);
GraphicsLayer* footerLayerForFrameView(FrameView&);
virtual void willCommitTree() { }
Page* m_page;
private:
virtual void setSynchronousScrollingReasons(FrameView&, SynchronousScrollingReasons) { }
virtual bool hasVisibleSlowRepaintViewportConstrainedObjects(const FrameView&) const;
void updateSynchronousScrollingReasons(FrameView&);
void updateSynchronousScrollingReasonsForAllFrames();
EventTrackingRegions absoluteEventTrackingRegionsForFrame(const Frame&) const;
bool m_forceSynchronousScrollLayerPositionUpdates { false };
};
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ScrollableAreaParameters);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ScrollingNodeType);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ScrollingLayerPositionAction);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ViewportRectStability);
}
#define SPECIALIZE_TYPE_TRAITS_SCROLLING_COORDINATOR(ToValueTypeName, predicate) \
SPECIALIZE_TYPE_TRAITS_BEGIN(ToValueTypeName) \
static bool isType(const WebCore::ScrollingCoordinator& value) { return value.predicate; } \
SPECIALIZE_TYPE_TRAITS_END()