ScrollingTreeOverflowScrollingNodeNicosia.cpp [plain text]
#include "config.h"
#include "ScrollingTreeOverflowScrollingNodeNicosia.h"
#if ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)
#include "NicosiaPlatformLayer.h"
#if ENABLE(KINETIC_SCROLLING)
#include "ScrollAnimationKinetic.h"
#endif
#include "ScrollingStateOverflowScrollingNode.h"
#include "ScrollingTree.h"
namespace WebCore {
Ref<ScrollingTreeOverflowScrollingNode> ScrollingTreeOverflowScrollingNodeNicosia::create(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
{
return adoptRef(*new ScrollingTreeOverflowScrollingNodeNicosia(scrollingTree, nodeID));
}
ScrollingTreeOverflowScrollingNodeNicosia::ScrollingTreeOverflowScrollingNodeNicosia(ScrollingTree& scrollingTree, ScrollingNodeID nodeID)
: ScrollingTreeOverflowScrollingNode(scrollingTree, nodeID)
{
#if ENABLE(KINETIC_SCROLLING)
m_kineticAnimation = makeUnique<ScrollAnimationKinetic>(
[this]() -> ScrollAnimationKinetic::ScrollExtents {
return { IntPoint(minimumScrollPosition()), IntPoint(maximumScrollPosition()) };
},
[this](FloatPoint&& position) {
auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
ASSERT(scrollLayer);
auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
auto updateScope = compositionLayer.createUpdateScope();
scrollTo(position);
});
#endif
}
ScrollingTreeOverflowScrollingNodeNicosia::~ScrollingTreeOverflowScrollingNodeNicosia() = default;
void ScrollingTreeOverflowScrollingNodeNicosia::commitStateAfterChildren(const ScrollingStateNode& stateNode)
{
ScrollingTreeOverflowScrollingNode::commitStateAfterChildren(stateNode);
const auto& overflowStateNode = downcast<ScrollingStateOverflowScrollingNode>(stateNode);
if (overflowStateNode.hasChangedProperty(ScrollingStateScrollingNode::RequestedScrollPosition)) {
const auto& requestedScrollData = overflowStateNode.requestedScrollData();
scrollTo(requestedScrollData.scrollPosition, requestedScrollData.scrollType, requestedScrollData.clamping);
}
}
FloatPoint ScrollingTreeOverflowScrollingNodeNicosia::adjustedScrollPosition(const FloatPoint& position, ScrollClamping clamping) const
{
FloatPoint scrollPosition(roundf(position.x()), roundf(position.y()));
return ScrollingTreeOverflowScrollingNode::adjustedScrollPosition(scrollPosition, clamping);
}
void ScrollingTreeOverflowScrollingNodeNicosia::repositionScrollingLayers()
{
auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrolledContentsLayer());
ASSERT(scrollLayer);
auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
auto scrollOffset = currentScrollOffset();
compositionLayer.updateState(
[&scrollOffset](Nicosia::CompositionLayer::LayerState& state)
{
state.boundsOrigin = scrollOffset;
state.delta.boundsOriginChanged = true;
});
}
WheelEventHandlingResult ScrollingTreeOverflowScrollingNodeNicosia::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
{
if (!canHandleWheelEvent(wheelEvent))
return WheelEventHandlingResult::unhandled();
if (wheelEvent.deltaX() || wheelEvent.deltaY()) {
auto* scrollLayer = static_cast<Nicosia::PlatformLayer*>(scrollContainerLayer());
ASSERT(scrollLayer);
auto& compositionLayer = downcast<Nicosia::CompositionLayer>(*scrollLayer);
auto updateScope = compositionLayer.createUpdateScope();
scrollBy({ -wheelEvent.deltaX(), -wheelEvent.deltaY() });
}
#if ENABLE(KINETIC_SCROLLING)
m_kineticAnimation->appendToScrollHistory(wheelEvent);
#endif
#if ENABLE(KINETIC_SCROLLING)
m_kineticAnimation->stop();
if (wheelEvent.isEndOfNonMomentumScroll()) {
m_kineticAnimation->start(currentScrollPosition(), m_kineticAnimation->computeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
m_kineticAnimation->clearScrollHistory();
}
if (wheelEvent.isTransitioningToMomentumScroll()) {
m_kineticAnimation->start(currentScrollPosition(), wheelEvent.swipeVelocity(), canHaveHorizontalScrollbar(), canHaveVerticalScrollbar());
m_kineticAnimation->clearScrollHistory();
}
#endif
return WheelEventHandlingResult::handled();
}
void ScrollingTreeOverflowScrollingNodeNicosia::stopScrollAnimations()
{
#if ENABLE(KINETIC_SCROLLING)
m_kineticAnimation->stop();
m_kineticAnimation->clearScrollHistory();
#endif
}
}
#endif // ENABLE(ASYNC_SCROLLING) && USE(NICOSIA)