ScrollingCoordinatorCoordinatedGraphics.cpp [plain text]
#include "config.h"
#if USE(COORDINATED_GRAPHICS)
#include "ScrollingCoordinatorCoordinatedGraphics.h"
#include "CoordinatedGraphicsLayer.h"
#include "FrameView.h"
#include "HostWindow.h"
#include "Page.h"
#include "RenderLayer.h"
#include "RenderLayerBacking.h"
#include "ScrollingConstraints.h"
#include "ScrollingStateFixedNode.h"
#include "ScrollingStateScrollingNode.h"
#include "ScrollingStateStickyNode.h"
#include "ScrollingStateTree.h"
namespace WebCore {
ScrollingCoordinatorCoordinatedGraphics::ScrollingCoordinatorCoordinatedGraphics(Page* page)
: ScrollingCoordinator(page)
, m_scrollingStateTree(std::make_unique<ScrollingStateTree>())
{
}
ScrollingCoordinatorCoordinatedGraphics::~ScrollingCoordinatorCoordinatedGraphics()
{
}
ScrollingNodeID ScrollingCoordinatorCoordinatedGraphics::attachToStateTree(ScrollingNodeType nodeType, ScrollingNodeID newNodeID, ScrollingNodeID parentID)
{
return m_scrollingStateTree->attachNode(nodeType, newNodeID, parentID);
}
void ScrollingCoordinatorCoordinatedGraphics::detachFromStateTree(ScrollingNodeID nodeID)
{
ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID);
if (node && node->nodeType() == FixedNode)
downcast<CoordinatedGraphicsLayer>(*static_cast<GraphicsLayer*>(node->layer())).setFixedToViewport(false);
m_scrollingStateTree->detachNode(nodeID);
}
void ScrollingCoordinatorCoordinatedGraphics::clearStateTree()
{
m_scrollingStateTree->clear();
}
void ScrollingCoordinatorCoordinatedGraphics::updateNodeLayer(ScrollingNodeID nodeID, GraphicsLayer* graphicsLayer)
{
ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID);
if (!node)
return;
node->setLayer(graphicsLayer);
}
void AsyncScrollingCoordinator::updateNodeViewportConstraints(ScrollingNodeID nodeID, const ViewportConstraints& constraints)
{
ScrollingStateNode* node = m_scrollingStateTree->stateNodeForID(nodeID);
if (!node)
return;
switch (constraints.constraintType()) {
case ViewportConstraints::FixedPositionConstraint: {
downcast<CoordinatedGraphicsLayer>(*graphicsLayer).setFixedToViewport(true);
break;
}
case ViewportConstraints::StickyPositionConstraint:
break; default:
ASSERT_NOT_REACHED();
}
}
void ScrollingCoordinatorCoordinatedGraphics::scrollableAreaScrollLayerDidChange(ScrollableArea& scrollableArea)
{
CoordinatedGraphicsLayer* layer = downcast<CoordinatedGraphicsLayer>(scrollLayerForScrollableArea(scrollableArea));
if (!layer)
return;
layer->setScrollableArea(&scrollableArea);
}
void ScrollingCoordinatorCoordinatedGraphics::willDestroyScrollableArea(ScrollableArea& scrollableArea)
{
CoordinatedGraphicsLayer* layer = downcast<CoordinatedGraphicsLayer>(scrollLayerForScrollableArea(scrollableArea));
if (!layer)
return;
layer->setScrollableArea(nullptr);
}
bool ScrollingCoordinatorCoordinatedGraphics::requestScrollPositionUpdate(FrameView& frameView, const IntPoint& scrollPosition)
{
if (!frameView.delegatesScrolling())
return false;
frameView.hostWindow()->delegatedScrollRequested(scrollPosition);
return true;
}
}
#endif // USE(COORDINATED_GRAPHICS)