ScrollingStateTree.h [plain text]
#pragma once
#if ENABLE(ASYNC_SCROLLING)
#include "ScrollingCoordinator.h"
#include "ScrollingStateNode.h"
#include <wtf/RefPtr.h>
namespace WebCore {
class AsyncScrollingCoordinator;
class ScrollingStateFrameScrollingNode;
class ScrollingStateTree {
WTF_MAKE_FAST_ALLOCATED;
friend class ScrollingStateNode;
public:
WEBCORE_EXPORT ScrollingStateTree(AsyncScrollingCoordinator* = nullptr);
WEBCORE_EXPORT ~ScrollingStateTree();
ScrollingStateFrameScrollingNode* rootStateNode() const { return m_rootStateNode.get(); }
WEBCORE_EXPORT ScrollingStateNode* stateNodeForID(ScrollingNodeID) const;
ScrollingNodeID createUnparentedNode(ScrollingNodeType, ScrollingNodeID);
WEBCORE_EXPORT ScrollingNodeID insertNode(ScrollingNodeType, ScrollingNodeID, ScrollingNodeID parentID, size_t childIndex);
void unparentNode(ScrollingNodeID);
void unparentChildrenAndDestroyNode(ScrollingNodeID);
void detachAndDestroySubtree(ScrollingNodeID);
void clear();
WEBCORE_EXPORT std::unique_ptr<ScrollingStateTree> commit(LayerRepresentation::Type preferredLayerRepresentation);
WEBCORE_EXPORT void setHasChangedProperties(bool = true);
bool hasChangedProperties() const { return m_hasChangedProperties; }
bool hasNewRootStateNode() const { return m_hasNewRootStateNode; }
void setHasNewRootStateNode(bool hasNewRoot) { m_hasNewRootStateNode = hasNewRoot; }
unsigned nodeCount() const { return m_stateNodeMap.size(); }
typedef HashMap<ScrollingNodeID, RefPtr<ScrollingStateNode>> StateNodeMap;
const StateNodeMap& nodeMap() const { return m_stateNodeMap; }
LayerRepresentation::Type preferredLayerRepresentation() const { return m_preferredLayerRepresentation; }
void setPreferredLayerRepresentation(LayerRepresentation::Type representation) { m_preferredLayerRepresentation = representation; }
void reconcileViewportConstrainedLayerPositions(ScrollingNodeID, const LayoutRect& viewportRect, ScrollingLayerPositionAction);
private:
void setRootStateNode(Ref<ScrollingStateFrameScrollingNode>&&);
void addNode(ScrollingStateNode&);
void nodeWasReattachedRecursive(ScrollingStateNode&);
Ref<ScrollingStateNode> createNode(ScrollingNodeType, ScrollingNodeID);
bool nodeTypeAndParentMatch(ScrollingStateNode&, ScrollingNodeType, ScrollingStateNode* parentNode) const;
void removeNodeAndAllDescendants(ScrollingStateNode*);
void recursiveNodeWillBeRemoved(ScrollingStateNode*);
void willRemoveNode(ScrollingStateNode*);
void reconcileLayerPositionsRecursive(ScrollingStateNode&, const LayoutRect& viewportRect, ScrollingLayerPositionAction);
AsyncScrollingCoordinator* m_scrollingCoordinator;
StateNodeMap m_stateNodeMap;
HashMap<ScrollingNodeID, RefPtr<ScrollingStateNode>> m_unparentedNodes;
RefPtr<ScrollingStateFrameScrollingNode> m_rootStateNode;
bool m_hasChangedProperties { false };
bool m_hasNewRootStateNode { false };
LayerRepresentation::Type m_preferredLayerRepresentation { LayerRepresentation::GraphicsLayerRepresentation };
};
}
#ifndef NDEBUG
void showScrollingStateTree(const WebCore::ScrollingStateTree*);
void showScrollingStateTree(const WebCore::ScrollingStateNode*);
#endif
#endif // ENABLE(ASYNC_SCROLLING)