ScrollingTreeNode.cpp [plain text]
#include "config.h"
#include "ScrollingTreeNode.h"
#if ENABLE(ASYNC_SCROLLING)
#include "ScrollingStateTree.h"
#include "ScrollingTreeFrameScrollingNode.h"
#include <wtf/text/TextStream.h>
namespace WebCore {
ScrollingTreeNode::ScrollingTreeNode(ScrollingTree& scrollingTree, ScrollingNodeType nodeType, ScrollingNodeID nodeID)
: m_scrollingTree(scrollingTree)
, m_nodeType(nodeType)
, m_nodeID(nodeID)
, m_parent(nullptr)
{
}
ScrollingTreeNode::~ScrollingTreeNode() = default;
void ScrollingTreeNode::appendChild(Ref<ScrollingTreeNode>&& childNode)
{
childNode->setParent(this);
if (!m_children)
m_children = std::make_unique<Vector<RefPtr<ScrollingTreeNode>>>();
m_children->append(WTFMove(childNode));
}
void ScrollingTreeNode::removeChild(ScrollingTreeNode& node)
{
if (!m_children)
return;
size_t index = m_children->find(&node);
if (index != notFound) {
m_children->remove(index);
return;
}
for (auto& child : *m_children)
child->removeChild(node);
}
void ScrollingTreeNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
{
if (behavior & ScrollingStateTreeAsTextBehaviorIncludeNodeIDs)
ts.dumpProperty("nodeID", scrollingNodeID());
}
ScrollingTreeFrameScrollingNode* ScrollingTreeNode::enclosingFrameNodeIncludingSelf()
{
auto* node = this;
while (node && !node->isFrameScrollingNode())
node = node->parent();
return downcast<ScrollingTreeFrameScrollingNode>(node);
}
void ScrollingTreeNode::dump(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
{
dumpProperties(ts, behavior);
if (m_children) {
for (auto& child : *m_children) {
TextStream::GroupScope scope(ts);
child->dump(ts, behavior);
}
}
}
}
#endif // ENABLE(ASYNC_SCROLLING)