ScrollingTreeFixedNode.cpp [plain text]
#include "config.h"
#include "ScrollingTreeFixedNode.h"
#if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
#include "Logging.h"
#include "NicosiaPlatformLayer.h"
#include "ScrollingStateFixedNode.h"
#include "ScrollingTree.h"
#include "ScrollingTreeFrameScrollingNode.h"
#include "ScrollingTreeOverflowScrollingNode.h"
#include <wtf/text/TextStream.h>
namespace WebCore {
Ref<ScrollingTreeFixedNode> ScrollingTreeFixedNode::create(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
{
return adoptRef(*new ScrollingTreeFixedNode(scrollingTree, nodeID));
}
ScrollingTreeFixedNode::ScrollingTreeFixedNode(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
: ScrollingTreeNode(scrollingTree, ScrollingNodeType::Fixed, nodeID)
{
scrollingTree.fixedOrStickyNodeAdded();
}
ScrollingTreeFixedNode::~ScrollingTreeFixedNode()
{
scrollingTree().fixedOrStickyNodeRemoved();
}
void ScrollingTreeFixedNode::commitStateBeforeChildren(const ScrollingStateNode& stateNode)
{
auto& fixedStateNode = downcast<ScrollingStateFixedNode>(stateNode);
if (fixedStateNode.hasChangedProperty(ScrollingStateNode::Layer)) {
auto* layer = static_cast<Nicosia::PlatformLayer*>(fixedStateNode.layer());
m_layer = downcast<Nicosia::CompositionLayer>(layer);
}
if (fixedStateNode.hasChangedProperty(ScrollingStateFixedNode::ViewportConstraints))
m_constraints = fixedStateNode.viewportConstraints();
}
void ScrollingTreeFixedNode::applyLayerPositions()
{
auto computeLayerPosition = [&] {
FloatSize overflowScrollDelta;
for (auto* node = parent(); node; node = node->parent()) {
if (is<ScrollingTreeFrameScrollingNode>(*node)) {
auto layoutViewport = downcast<ScrollingTreeFrameScrollingNode>(*node).layoutViewport();
return m_constraints.layerPositionForViewportRect(layoutViewport) - overflowScrollDelta;
}
if (is<ScrollingTreeOverflowScrollingNode>(*node)) {
auto& overflowNode = downcast<ScrollingTreeOverflowScrollingNode>(*node);
auto localDelta = overflowNode.lastCommittedScrollPosition() - overflowNode.currentScrollPosition();
overflowScrollDelta += localDelta;
}
}
ASSERT_NOT_REACHED();
return FloatPoint();
};
auto layerPosition = computeLayerPosition();
LOG_WITH_STREAM(Scrolling, stream << "ScrollingTreeFixedNode " << scrollingNodeID() << " relatedNodeScrollPositionDidChange: viewportRectAtLastLayout " << m_constraints.viewportRectAtLastLayout() << " last layer pos " << m_constraints.layerPositionAtLastLayout() << " layerPosition " << layerPosition);
ASSERT(m_layer);
m_layer->updateState(
[&layerPosition](Nicosia::CompositionLayer::LayerState& state)
{
state.position = layerPosition;
state.delta.positionChanged = true;
});
}
void ScrollingTreeFixedNode::dumpProperties(TextStream& ts, ScrollingStateTreeAsTextBehavior behavior) const
{
ts << "fixed node";
ScrollingTreeNode::dumpProperties(ts, behavior);
ts.dumpProperty("fixed constraints", m_constraints);
if (behavior & ScrollingStateTreeAsTextBehaviorIncludeLayerPositions) {
FloatPoint layerTopLeft;
ASSERT(m_layer);
m_layer->accessCommitted(
[this, &layerTopLeft](Nicosia::CompositionLayer::LayerState& state)
{
layerTopLeft = state.position - toFloatSize(state.anchorPoint.xy()) * state.size + m_constraints.alignmentOffset();
});
ts.dumpProperty("layer top left", layerTopLeft);
}
}
}
#endif // ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)