Changeset 164759 in webkit


Ignore:
Timestamp:
Feb 26, 2014, 5:04:23 PM (11 years ago)
Author:
Simon Fraser
Message:

Prepare for overflow scrolling nodes in the scrolling tree
https://bugs.webkit.org/show_bug.cgi?id=129398

Reviewed by Tim Horton.

Lay some groundwork for overflow:scrolling nodes in the scrolling tree.
Change terminology to refer to "scroll-coordinatored" layers now, not just viewport-constrained
layers.

A given layer can be both viewport-constrained and overflow-scrolling (e.g. position:fixed,
overflow:scroll), so handle that in RenderLayerBacking, and use some "reason" flags
in RenderLayerCompositor.

  • page/FrameView.cpp:

(WebCore::FrameView::scrollLayerID): Rename

  • page/scrolling/ScrollingStateTree.cpp:

(WebCore::ScrollingStateTree::attachNode): Remove invalid assertion.

  • rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::RenderLayerBacking):
(WebCore::RenderLayerBacking::updateGraphicsLayerGeometry):
(WebCore::RenderLayerBacking::updateScrollingLayers): Simplify the logic with
an early return.
(WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
Allow a layer to play both viewport-constrained and scrolling roles
in the scrolling tree.

  • rendering/RenderLayerBacking.h:

(WebCore::RenderLayerBacking::viewportConstrainedNodeID):
(WebCore::RenderLayerBacking::setViewportConstrainedNodeID):
(WebCore::RenderLayerBacking::scrollingNodeID):
(WebCore::RenderLayerBacking::setScrollingNodeID):
(WebCore::RenderLayerBacking::scrollingNodeIDForChildren):

  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::flushPendingLayerChanges):
(WebCore::RenderLayerCompositor::didFlushChangesForLayer):
(WebCore::RenderLayerCompositor::updateBacking):
(WebCore::RenderLayerCompositor::layerWillBeRemoved):
(WebCore::RenderLayerCompositor::fixedRootBackgroundLayerChanged):
(WebCore::RenderLayerCompositor::clearBackingForLayerIncludingDescendants):
(WebCore::RenderLayerCompositor::requiresCompositingLayer):
(WebCore::RenderLayerCompositor::requiresOwnBackingStore):
(WebCore::RenderLayerCompositor::reasonsForCompositing):
(WebCore::RenderLayerCompositor::requiresCompositingForScrolling):
(WebCore::isViewportConstrainedFixedOrStickyLayer):
(WebCore::isMainFrameScrollingOrOverflowScrolling):
(WebCore::RenderLayerCompositor::rootLayerAttachmentChanged):
(WebCore::RenderLayerCompositor::updateScrollCoordinatedStatus):
(WebCore::RenderLayerCompositor::removeFromScrollCoordinatedLayers):
(WebCore::nearestScrollCoordinatedAncestor):
(WebCore::RenderLayerCompositor::updateScrollCoordinatedLayer):
(WebCore::RenderLayerCompositor::detachScrollCoordinatedLayer):
(WebCore::RenderLayerCompositor::registerAllViewportConstrainedLayers):
(WebCore::RenderLayerCompositor::willRemoveScrollingLayer):
(WebCore::RenderLayerCompositor::didAddScrollingLayer):

  • rendering/RenderLayerCompositor.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r164757 r164759  
     12014-02-26  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Prepare for overflow scrolling nodes in the scrolling tree
     4        https://bugs.webkit.org/show_bug.cgi?id=129398
     5
     6        Reviewed by Tim Horton.
     7
     8        Lay some groundwork for overflow:scrolling nodes in the scrolling tree.
     9        Change terminology to refer to "scroll-coordinatored" layers now, not just viewport-constrained
     10        layers.
     11       
     12        A given layer can be both viewport-constrained and overflow-scrolling (e.g. position:fixed,
     13        overflow:scroll), so handle that in RenderLayerBacking, and use some "reason" flags
     14        in RenderLayerCompositor.
     15
     16        * page/FrameView.cpp:
     17        (WebCore::FrameView::scrollLayerID): Rename
     18        * page/scrolling/ScrollingStateTree.cpp:
     19        (WebCore::ScrollingStateTree::attachNode): Remove invalid assertion.
     20        * rendering/RenderLayerBacking.cpp:
     21        (WebCore::RenderLayerBacking::RenderLayerBacking):
     22        (WebCore::RenderLayerBacking::updateGraphicsLayerGeometry):
     23        (WebCore::RenderLayerBacking::updateScrollingLayers): Simplify the logic with
     24        an early return.
     25        (WebCore::RenderLayerBacking::detachFromScrollingCoordinator):
     26        Allow a layer to play both viewport-constrained and scrolling roles
     27        in the scrolling tree.
     28        * rendering/RenderLayerBacking.h:
     29        (WebCore::RenderLayerBacking::viewportConstrainedNodeID):
     30        (WebCore::RenderLayerBacking::setViewportConstrainedNodeID):
     31        (WebCore::RenderLayerBacking::scrollingNodeID):
     32        (WebCore::RenderLayerBacking::setScrollingNodeID):
     33        (WebCore::RenderLayerBacking::scrollingNodeIDForChildren):
     34        * rendering/RenderLayerCompositor.cpp:
     35        (WebCore::RenderLayerCompositor::flushPendingLayerChanges):
     36        (WebCore::RenderLayerCompositor::didFlushChangesForLayer):
     37        (WebCore::RenderLayerCompositor::updateBacking):
     38        (WebCore::RenderLayerCompositor::layerWillBeRemoved):
     39        (WebCore::RenderLayerCompositor::fixedRootBackgroundLayerChanged):
     40        (WebCore::RenderLayerCompositor::clearBackingForLayerIncludingDescendants):
     41        (WebCore::RenderLayerCompositor::requiresCompositingLayer):
     42        (WebCore::RenderLayerCompositor::requiresOwnBackingStore):
     43        (WebCore::RenderLayerCompositor::reasonsForCompositing):
     44        (WebCore::RenderLayerCompositor::requiresCompositingForScrolling):
     45        (WebCore::isViewportConstrainedFixedOrStickyLayer):
     46        (WebCore::isMainFrameScrollingOrOverflowScrolling):
     47        (WebCore::RenderLayerCompositor::rootLayerAttachmentChanged):
     48        (WebCore::RenderLayerCompositor::updateScrollCoordinatedStatus):
     49        (WebCore::RenderLayerCompositor::removeFromScrollCoordinatedLayers):
     50        (WebCore::nearestScrollCoordinatedAncestor):
     51        (WebCore::RenderLayerCompositor::updateScrollCoordinatedLayer):
     52        (WebCore::RenderLayerCompositor::detachScrollCoordinatedLayer):
     53        (WebCore::RenderLayerCompositor::registerAllViewportConstrainedLayers):
     54        (WebCore::RenderLayerCompositor::willRemoveScrollingLayer):
     55        (WebCore::RenderLayerCompositor::didAddScrollingLayer):
     56        * rendering/RenderLayerCompositor.h:
     57
    1582014-02-26  Andy Estes  <aestes@apple.com>
    259
  • trunk/Source/WebCore/page/FrameView.cpp

    r164697 r164759  
    815815        return 0;
    816816
    817     return backing->scrollLayerID();
     817    return backing->scrollingNodeID();
    818818}
    819819
  • trunk/Source/WebCore/page/scrolling/ScrollingStateTree.cpp

    r161315 r164759  
    109109        }
    110110        case ScrollingNode: {
    111             // FIXME: We currently only support child nodes that are fixed.
    112             ASSERT_NOT_REACHED();
    113111            OwnPtr<ScrollingStateScrollingNode> scrollingNode = ScrollingStateScrollingNode::create(*this, newNodeID);
    114112            newNode = scrollingNode.get();
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r164532 r164759  
    110110RenderLayerBacking::RenderLayerBacking(RenderLayer& layer)
    111111    : m_owningLayer(layer)
    112     , m_scrollLayerID(0)
     112    , m_viewportConstrainedNodeID(0)
     113    , m_scrollingNodeID(0)
    113114    , m_artificiallyInflatedBounds(false)
    114115    , m_isMainFrameRenderViewLayer(false)
     
    952953        // Scrolling the content layer does not need to trigger a repaint. The offset will be compensated away during painting.
    953954        // FIXME: The paint offset and the scroll offset should really be separate concepts.
    954         m_scrollingContentsLayer->setOffsetFromRenderer(paddingBox.location() - FloatPoint() - scrollOffset, GraphicsLayer::DontSetNeedsDisplay);
    955        
    956         compositor().scrollingLayerAddedOrUpdated(&m_owningLayer);
     955        m_scrollingContentsLayer->setOffsetFromRenderer(paddingBox.location() - IntPoint() - scrollOffset, GraphicsLayer::DontSetNeedsDisplay);
    957956#else
    958957        m_scrollingContentsLayer->setPosition(FloatPoint(-scrollOffset.width(), -scrollOffset.height()));
     
    993992    updateAfterWidgetResize();
    994993
    995     compositor().updateViewportConstraintStatus(m_owningLayer);
     994    compositor().updateScrollCoordinatedStatus(m_owningLayer);
    996995}
    997996
     
    14241423bool RenderLayerBacking::updateScrollingLayers(bool needsScrollingLayers)
    14251424{
    1426     ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer);
    1427 
    1428     bool layerChanged = false;
    1429     if (needsScrollingLayers) {
    1430         if (!m_scrollingLayer) {
    1431             // Outer layer which corresponds with the scroll view.
    1432             m_scrollingLayer = createGraphicsLayer("Scrolling container");
    1433             m_scrollingLayer->setDrawsContent(false);
    1434             m_scrollingLayer->setMasksToBounds(true);
    1435 
    1436             // Inner layer which renders the content that scrolls.
    1437             m_scrollingContentsLayer = createGraphicsLayer("Scrolled Contents");
    1438             m_scrollingContentsLayer->setDrawsContent(true);
    1439             GraphicsLayerPaintingPhase paintPhase = GraphicsLayerPaintOverflowContents | GraphicsLayerPaintCompositedScroll;
    1440             if (!m_foregroundLayer)
    1441                 paintPhase |= GraphicsLayerPaintForeground;
    1442             m_scrollingContentsLayer->setPaintingPhase(paintPhase);
    1443             m_scrollingLayer->addChild(m_scrollingContentsLayer.get());
    1444 
    1445             layerChanged = true;
    1446             if (scrollingCoordinator)
    1447                 scrollingCoordinator->scrollableAreaScrollLayerDidChange(&m_owningLayer);
    1448 #if PLATFORM(IOS)
    1449             if (m_owningLayer.parent())
    1450                 compositor().scrollingLayerAddedOrUpdated(&m_owningLayer);
    1451 #endif
    1452         }
    1453     } else if (m_scrollingLayer) {
    1454 #if PLATFORM(IOS)
    1455         if (!renderer().documentBeingDestroyed())
    1456             compositor().scrollingLayerRemoved(&m_owningLayer, m_scrollingLayer->platformLayer(), m_scrollingContentsLayer->platformLayer());
    1457 #endif
     1425    if (needsScrollingLayers == !!m_scrollingLayer)
     1426        return false;
     1427
     1428    if (!m_scrollingLayer) {
     1429        // Outer layer which corresponds with the scroll view.
     1430        m_scrollingLayer = createGraphicsLayer("Scrolling container");
     1431        m_scrollingLayer->setDrawsContent(false);
     1432        m_scrollingLayer->setMasksToBounds(true);
     1433
     1434        // Inner layer which renders the content that scrolls.
     1435        m_scrollingContentsLayer = createGraphicsLayer("Scrolled Contents");
     1436        m_scrollingContentsLayer->setDrawsContent(true);
     1437        GraphicsLayerPaintingPhase paintPhase = GraphicsLayerPaintOverflowContents | GraphicsLayerPaintCompositedScroll;
     1438        if (!m_foregroundLayer)
     1439            paintPhase |= GraphicsLayerPaintForeground;
     1440        m_scrollingContentsLayer->setPaintingPhase(paintPhase);
     1441        m_scrollingLayer->addChild(m_scrollingContentsLayer.get());
     1442    } else {
     1443        compositor().willRemoveScrollingLayer(m_owningLayer);
     1444
    14581445        willDestroyLayer(m_scrollingLayer.get());
    14591446        willDestroyLayer(m_scrollingContentsLayer.get());
    14601447        m_scrollingLayer = nullptr;
    14611448        m_scrollingContentsLayer = nullptr;
    1462         layerChanged = true;
    1463         if (scrollingCoordinator)
    1464             scrollingCoordinator->scrollableAreaScrollLayerDidChange(&m_owningLayer);
    1465     }
    1466 
    1467     if (layerChanged) {
    1468         updateInternalHierarchy();
    1469         m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
    1470 #if !PLATFORM(IOS)
    1471         m_graphicsLayer->setNeedsDisplay();
    1472         compositor().scrollingLayerDidChange(m_owningLayer);
    1473 #endif
    1474     }
    1475 
    1476     return layerChanged;
    1477 }
    1478 
    1479 void RenderLayerBacking::attachToScrollingCoordinatorWithParent(RenderLayerBacking* parent)
    1480 {
     1449    }
     1450
     1451    updateInternalHierarchy();
     1452    m_graphicsLayer->setPaintingPhase(paintingPhaseForPrimaryLayer());
     1453    m_graphicsLayer->setNeedsDisplay(); // Because painting phases changed.
     1454
     1455    if (m_scrollingLayer)
     1456        compositor().didAddScrollingLayer(m_owningLayer);
     1457   
     1458    return true;
     1459}
     1460
     1461void RenderLayerBacking::detachFromScrollingCoordinator()
     1462{
     1463    if (!m_scrollingNodeID && !m_viewportConstrainedNodeID)
     1464        return;
     1465
    14811466    ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer);
    14821467    if (!scrollingCoordinator)
    14831468        return;
    14841469
    1485     // FIXME: When we support overflow areas, we will have to refine this for overflow areas that are also
    1486     // positon:fixed.
    1487     ScrollingNodeType nodeType;
    1488     if (renderer().style().position() == FixedPosition)
    1489         nodeType = FixedNode;
    1490     else if (renderer().style().position() == StickyPosition)
    1491         nodeType = StickyNode;
    1492     else
    1493         nodeType = ScrollingNode;
    1494 
    1495     ScrollingNodeID parentID = parent ? parent->scrollLayerID() : 0;
    1496     m_scrollLayerID = scrollingCoordinator->attachToStateTree(nodeType, m_scrollLayerID ? m_scrollLayerID : scrollingCoordinator->uniqueScrollLayerID(), parentID);
    1497 }
    1498 
    1499 void RenderLayerBacking::detachFromScrollingCoordinator()
    1500 {
    1501     // If m_scrollLayerID is 0, then this backing is not attached to the ScrollingCoordinator.
    1502     if (!m_scrollLayerID)
    1503         return;
    1504 
    1505     ScrollingCoordinator* scrollingCoordinator = scrollingCoordinatorFromLayer(m_owningLayer);
    1506     if (!scrollingCoordinator)
    1507         return;
    1508 
    1509     scrollingCoordinator->detachFromStateTree(m_scrollLayerID);
    1510     m_scrollLayerID = 0;
     1470    if (m_scrollingNodeID)
     1471        scrollingCoordinator->detachFromStateTree(m_scrollingNodeID);
     1472
     1473    if (m_viewportConstrainedNodeID)
     1474        scrollingCoordinator->detachFromStateTree(m_viewportConstrainedNodeID);
     1475
     1476    m_scrollingNodeID = 0;
     1477    m_viewportConstrainedNodeID = 0;
    15111478}
    15121479
  • trunk/Source/WebCore/rendering/RenderLayerBacking.h

    r164532 r164759  
    3232#include "GraphicsLayerClient.h"
    3333#include "RenderLayer.h"
     34#include "ScrollingCoordinator.h"
    3435
    3536namespace WebCore {
     
    102103    GraphicsLayer* scrollingContentsLayer() const { return m_scrollingContentsLayer.get(); }
    103104
    104     void attachToScrollingCoordinatorWithParent(RenderLayerBacking* parent);
    105105    void detachFromScrollingCoordinator();
    106     uint64_t scrollLayerID() const { return m_scrollLayerID; }
    107    
     106
     107    ScrollingNodeID viewportConstrainedNodeID() const { return m_viewportConstrainedNodeID; }
     108    void setViewportConstrainedNodeID(ScrollingNodeID nodeID) { m_viewportConstrainedNodeID = nodeID; }
     109
     110    ScrollingNodeID scrollingNodeID() const { return m_scrollingNodeID; }
     111    void setScrollingNodeID(ScrollingNodeID nodeID) { m_scrollingNodeID = nodeID; }
     112   
     113    ScrollingNodeID scrollingNodeIDForChildren() const { return m_scrollingNodeID ? m_scrollingNodeID : m_viewportConstrainedNodeID; }
     114
    108115    bool hasMaskLayer() const { return m_maskLayer != 0; }
    109116
     
    309316    std::unique_ptr<GraphicsLayer> m_scrollingContentsLayer; // Only used if the layer is using composited scrolling.
    310317
    311     uint64_t m_scrollLayerID;
     318    ScrollingNodeID m_viewportConstrainedNodeID;
     319    ScrollingNodeID m_scrollingNodeID;
    312320
    313321    LayoutRect m_compositedBounds;
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r164699 r164759  
    440440#endif
    441441
    442     for (auto it = m_viewportConstrainedLayersNeedingUpdate.begin(), end = m_viewportConstrainedLayersNeedingUpdate.end(); it != end; ++it)
    443         registerOrUpdateViewportConstrainedLayer(**it);
    444 
    445     m_viewportConstrainedLayersNeedingUpdate.clear();
     442    for (auto it = m_scrollCoordinatedLayersNeedingUpdate.begin(), end = m_scrollCoordinatedLayersNeedingUpdate.end(); it != end; ++it)
     443        updateScrollCoordinatedStatus(**it);
     444
     445    m_scrollCoordinatedLayersNeedingUpdate.clear();
    446446    startLayerFlushTimerIfNeeded();
    447447}
     
    489489void RenderLayerCompositor::didFlushChangesForLayer(RenderLayer& layer, const GraphicsLayer* graphicsLayer)
    490490{
    491     if (m_viewportConstrainedLayers.contains(&layer))
    492         m_viewportConstrainedLayersNeedingUpdate.add(&layer);
     491    if (m_scrollCoordinatedLayers.contains(&layer))
     492        m_scrollCoordinatedLayersNeedingUpdate.add(&layer);
    493493
    494494#if PLATFORM(IOS)
     
    775775            // At this time, the ScrollingCoordinator only supports the top-level frame.
    776776            if (layer.isRootLayer() && !m_renderView.document().ownerElement()) {
    777                 layer.backing()->attachToScrollingCoordinatorWithParent(0);
     777                updateScrollCoordinatedStatus(layer);
    778778                if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
    779779                    scrollingCoordinator->frameViewRootLayerDidChange(&m_renderView.frameView());
     
    808808            }
    809809
    810             removeViewportConstrainedLayer(layer);
     810            detachScrollCoordinatedLayer(layer);
    811811           
    812812            layer.clearBacking();
     
    931931        return;
    932932
    933     removeViewportConstrainedLayer(child);
     933    removeFromScrollCoordinatedLayers(child);
    934934    repaintInCompositedAncestor(child, child.backing()->compositedBounds());
    935935
     
    15601560        return;
    15611561
    1562     if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
    1563         RenderLayerBacking* renderViewBacking = m_renderView.layer()->backing();
    1564         if (!renderViewBacking)
    1565             return;
    1566 
    1567         scrollingCoordinator->updateScrollingNode(renderViewBacking->scrollLayerID(), scrollLayer(), nullptr, fixedRootBackgroundLayer());
    1568     }
     1562    if (m_renderView.layer()->isComposited())
     1563        updateScrollCoordinatedStatus(*m_renderView.layer());
    15691564}
    15701565
     
    18681863{
    18691864    if (layer.isComposited()) {
    1870         removeViewportConstrainedLayer(layer);
     1865        removeFromScrollCoordinatedLayers(layer);
    18711866        layer.clearBacking();
    18721867    }
     
    19861981        || requiresCompositingForPosition(*renderer, *renderer->layer(), viewportConstrainedNotCompositedReason)
    19871982#if PLATFORM(IOS)
    1988         || requiresCompositingForScrolling(*renderer)
     1983        || requiresCompositingForScrolling(*renderer->layer())
    19891984#endif
    19901985        || requiresCompositingForOverflowScrolling(*renderer->layer());
     
    20342029        || renderer.hasFilter()
    20352030#if PLATFORM(IOS)
    2036         || requiresCompositingForScrolling(renderer)
     2031        || requiresCompositingForScrolling(layer)
    20372032#endif
    20382033        )
     
    20942089
    20952090#if PLATFORM(IOS)
    2096     if (requiresCompositingForScrolling(*renderer))
     2091    if (requiresCompositingForScrolling(*renderer->layer()))
    20972092        reasons |= CompositingReasonOverflowScrollingTouch;
    20982093#endif
     
    24172412
    24182413#if PLATFORM(IOS)
    2419 bool RenderLayerCompositor::requiresCompositingForScrolling(RenderLayerModelObject& renderer) const
    2420 {
    2421     return renderer.hasLayer() && toRenderBoxModelObject(renderer).layer()->hasAcceleratedTouchScrolling();
     2414bool RenderLayerCompositor::requiresCompositingForScrolling(const RenderLayer& layer) const
     2415{
     2416    return layer.hasAcceleratedTouchScrolling();
    24222417}
    24232418#endif
     
    24652460        return false;
    24662461
     2462    // FIXME: Handle fixed inside of a transform, which should not behave as fixed.
    24672463    for (RenderLayer* stackingContainer = layer.stackingContainer(); stackingContainer; stackingContainer = stackingContainer->stackingContainer()) {
    24682464        if (stackingContainer->isComposited() && stackingContainer->renderer().style().position() == FixedPosition)
     
    24712467
    24722468    return true;
     2469}
     2470
     2471static bool isMainFrameScrollingOrOverflowScrolling(RenderView& view, const RenderLayer& layer)
     2472{
     2473    if (layer.isRootLayer() && !view.document().ownerElement())
     2474        return true;
     2475
     2476#if PLATFORM(IOS)
     2477    return layer.hasAcceleratedTouchScrolling();
     2478#else
     2479    return layer.needsCompositedScrolling();
     2480#endif
    24732481}
    24742482
     
    32693277{
    32703278    // The attachment can affect whether the RenderView layer's paintsIntoWindow() behavior,
    3271     // so call updateGraphicsLayerGeometry() to udpate that.
     3279    // so call updateDrawsContent() to update that.
    32723280    RenderLayer* layer = m_renderView.layer();
    32733281    if (RenderLayerBacking* backing = layer ? layer->backing() : 0)
     
    33433351}
    33443352
    3345 void RenderLayerCompositor::updateViewportConstraintStatus(RenderLayer& layer)
    3346 {
     3353void RenderLayerCompositor::updateScrollCoordinatedStatus(RenderLayer& layer)
     3354{
     3355    ScrollCoordinationReasons coordinationReasons = 0;
    33473356    if (isViewportConstrainedFixedOrStickyLayer(layer))
    3348         addViewportConstrainedLayer(layer);
    3349     else
    3350         removeViewportConstrainedLayer(layer);
    3351 }
    3352 
    3353 void RenderLayerCompositor::addViewportConstrainedLayer(RenderLayer& layer)
    3354 {
    3355     m_viewportConstrainedLayers.add(&layer);
    3356     registerOrUpdateViewportConstrainedLayer(layer);
    3357 }
    3358 
    3359 void RenderLayerCompositor::removeViewportConstrainedLayer(RenderLayer& layer)
    3360 {
    3361     if (!m_viewportConstrainedLayers.contains(&layer))
    3362         return;
    3363 
    3364     unregisterViewportConstrainedLayer(layer);
    3365     m_viewportConstrainedLayers.remove(&layer);
    3366     m_viewportConstrainedLayersNeedingUpdate.remove(&layer);
     3357        coordinationReasons |= FixedOrSticky;
     3358
     3359    if (isMainFrameScrollingOrOverflowScrolling(m_renderView, layer))
     3360        coordinationReasons |= Scrolling;
     3361       
     3362    if (coordinationReasons) {
     3363        m_scrollCoordinatedLayers.add(&layer);
     3364        updateScrollCoordinatedLayer(layer, coordinationReasons);
     3365    } else
     3366        removeFromScrollCoordinatedLayers(layer);
     3367}
     3368
     3369void RenderLayerCompositor::removeFromScrollCoordinatedLayers(RenderLayer& layer)
     3370{
     3371    if (!m_scrollCoordinatedLayers.contains(&layer))
     3372        return;
     3373
     3374    removeFromScrollCoordinatedLayers(layer);
     3375    m_scrollCoordinatedLayers.remove(&layer);
     3376    m_scrollCoordinatedLayersNeedingUpdate.remove(&layer);
    33673377}
    33683378
     
    34253435}
    34263436
    3427 static RenderLayerBacking* nearestScrollingCoordinatorAncestor(RenderLayer& layer)
     3437static RenderLayerBacking* nearestScrollCoordinatedAncestor(RenderLayer& layer)
    34283438{
    34293439    RenderLayer* ancestor = layer.parent();
    34303440    while (ancestor) {
    34313441        if (RenderLayerBacking* backing = ancestor->backing()) {
    3432             if (backing->scrollLayerID() && !ancestor->scrollsOverflow())
     3442            if (backing->scrollingNodeIDForChildren())
    34333443                return backing;
    34343444        }
     
    34393449}
    34403450
    3441 void RenderLayerCompositor::registerOrUpdateViewportConstrainedLayer(RenderLayer& layer)
    3442 {
    3443     // FIXME: We should support sticky position here! And we should eventuall support fixed/sticky elements
    3444     // that are inside non-main frames once we get non-main frames scrolling with the ScrollingCoordinator.
     3451void RenderLayerCompositor::updateScrollCoordinatedLayer(RenderLayer& layer, ScrollCoordinationReasons reasons)
     3452{
     3453    // FIXME: support scrolling layers in iframes.
    34453454    if (m_renderView.document().ownerElement())
    34463455        return;
     
    34493458    if (!scrollingCoordinator)
    34503459        return;
    3451 
    3452     // FIXME: rename to supportsViewportConstrainedPositionLayers()?
    3453     if (!scrollingCoordinator->supportsFixedPositionLayers() || !layer.parent())
    3454         return;
    3455 
    3456     ASSERT(m_viewportConstrainedLayers.contains(&layer));
     3460   
     3461    bool isRootLayer = &layer == m_renderView.layer();
     3462
     3463    // FIXME: Remove supportsFixedPositionLayers() since all platforms support them now.
     3464    if (!scrollingCoordinator->supportsFixedPositionLayers() || (!layer.parent() && !isRootLayer))
     3465        return;
     3466
     3467    ASSERT(m_scrollCoordinatedLayers.contains(&layer));
    34573468    ASSERT(layer.isComposited());
    34583469
     
    34613472        return;
    34623473
    3463     ScrollingNodeID nodeID = backing->scrollLayerID();
    3464     RenderLayerBacking* parent = nearestScrollingCoordinatorAncestor(layer);
    3465     if (!parent)
    3466         return;
    3467 
     3474    RenderLayerBacking* parent = nearestScrollCoordinatedAncestor(layer);
     3475    if (!parent && !isRootLayer)
     3476        return;
     3477
     3478    ScrollingNodeID parentNodeID = parent ? parent->scrollingNodeIDForChildren() : 0;
     3479   
    34683480    // Always call this even if the backing is already attached because the parent may have changed.
    3469     backing->attachToScrollingCoordinatorWithParent(parent);
    3470     nodeID = backing->scrollLayerID();
    3471 
    3472     if (layer.renderer().isStickyPositioned())
    3473         scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeStickyViewportConstraints(layer), backing->graphicsLayer());
    3474     else
    3475         scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeFixedViewportConstraints(layer), backing->graphicsLayer());
    3476 }
    3477 
    3478 void RenderLayerCompositor::unregisterViewportConstrainedLayer(RenderLayer& layer)
    3479 {
    3480     ASSERT(m_viewportConstrainedLayers.contains(&layer));
     3481    // If a node plays both roles, fixed/sticky is always the ancestor node of scrolling.
     3482    if (reasons & FixedOrSticky) {
     3483        ScrollingNodeID nodeID = backing->viewportConstrainedNodeID();
     3484        if (!nodeID)
     3485            nodeID = scrollingCoordinator->uniqueScrollLayerID();
     3486
     3487        ScrollingNodeType nodeType = ScrollingNode;
     3488        if (layer.renderer().style().position() == FixedPosition)
     3489            nodeType = FixedNode;
     3490        else if (layer.renderer().style().position() == StickyPosition)
     3491            nodeType = StickyNode;
     3492        else
     3493            ASSERT_NOT_REACHED();
     3494
     3495        nodeID = scrollingCoordinator->attachToStateTree(nodeType, nodeID, parentNodeID);
     3496        backing->setViewportConstrainedNodeID(nodeID);
     3497
     3498        switch (nodeType) {
     3499        case FixedNode:
     3500            scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeFixedViewportConstraints(layer), backing->graphicsLayer());
     3501            break;
     3502        case StickyNode:
     3503            scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeStickyViewportConstraints(layer), backing->graphicsLayer());
     3504            break;
     3505        case ScrollingNode:
     3506            break;
     3507        }
     3508       
     3509        parentNodeID = nodeID;
     3510    }
     3511
     3512    if (reasons & Scrolling) {
     3513        ScrollingNodeID nodeID = backing->scrollingNodeID();
     3514        if (!nodeID)
     3515            nodeID = scrollingCoordinator->uniqueScrollLayerID();
     3516
     3517        nodeID = scrollingCoordinator->attachToStateTree(ScrollingNode, nodeID, parentNodeID);
     3518        backing->setScrollingNodeID(nodeID);
     3519
     3520        GraphicsLayer* scrollingLayer = backing->scrollingLayer();
     3521        GraphicsLayer* scrolledContentsLayer = backing->scrollingContentsLayer();
     3522        GraphicsLayer* counterScrollingLayer = nullptr;
     3523
     3524        if (&layer == m_renderView.layer()) {
     3525            scrollingLayer = m_scrollLayer.get();
     3526            scrolledContentsLayer = nullptr;
     3527            counterScrollingLayer = fixedRootBackgroundLayer();
     3528        }
     3529   
     3530        scrollingCoordinator->updateScrollingNode(nodeID, scrollingLayer, scrolledContentsLayer, counterScrollingLayer);
     3531    }
     3532}
     3533
     3534void RenderLayerCompositor::detachScrollCoordinatedLayer(RenderLayer& layer)
     3535{
     3536    ASSERT(m_scrollCoordinatedLayers.contains(&layer));
    34813537
    34823538    if (RenderLayerBacking* backing = layer.backing())
     
    35003556    StickyContainerMap stickyContainerMap;
    35013557
    3502     for (auto it = m_viewportConstrainedLayers.begin(), end = m_viewportConstrainedLayers.end(); it != end; ++it) {
     3558    for (auto it = m_scrollCoordinatedLayers.begin(), end = m_scrollCoordinatedLayers.end(); it != end; ++it) {
    35033559        RenderLayer& layer = **it;
    35043560        ASSERT(layer.isComposited());
     
    35123568                stickyContainerMap.add(layer.backing()->graphicsLayer()->platformLayer(), enclosingTouchScrollableLayer->backing()->scrollingLayer()->platformLayer());
    35133569            }
    3514         } else
     3570        } else if (layer.renderer().style().position() == FixedPosition)
    35153571            constraints = std::make_unique<FixedPositionViewportConstraints>(computeFixedViewportConstraints(layer));
     3572        else
     3573            continue;
    35163574
    35173575        layerMap.add(layer.backing()->graphicsLayer()->platformLayer(), adoptPtr(constraints.release()));
     
    35613619    }
    35623620}
    3563 
    3564 // Called when the size of the contentsLayer changes, and when the contentsLayer is replaced by another layer.
    3565 void RenderLayerCompositor::scrollingLayerAddedOrUpdated(RenderLayer* layer)
    3566 {
     3621#endif
     3622
     3623void RenderLayerCompositor::willRemoveScrollingLayer(RenderLayer& layer)
     3624{
     3625    if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
     3626        RenderLayerBacking* backing = layer.backing();
     3627   
     3628        if (backing)
     3629            scrollingCoordinator->detachFromStateTree(backing->scrollingNodeID());
     3630
     3631        // For Coordinated Graphics.
     3632        scrollingCoordinator->scrollableAreaScrollLayerDidChange(&layer);
     3633        return;
     3634    }
     3635
     3636#if PLATFORM(IOS)
     3637    m_scrollingLayersNeedingUpdate.remove(&layer);
     3638    m_scrollingLayers.remove(&layer);
     3639
     3640    if (m_renderView.document().inPageCache() || !layer.backing())
     3641        return;
     3642
     3643    if (ChromeClient* client = this->chromeClient()) {
     3644        PlatformLayer* scrollingLayer = layer.backing()->scrollingLayer()->platformLayer();
     3645        PlatformLayer* contentsLayer = layer.backing()->scrollingContentsLayer()->platformLayer();
     3646        client->removeScrollingLayer(layer.renderer().element(), scrollingLayer, contentsLayer);
     3647    }
     3648#endif
     3649}
     3650
     3651void RenderLayerCompositor::didAddScrollingLayer(RenderLayer& layer)
     3652{
     3653    updateScrollCoordinatedStatus(layer);
     3654
     3655    if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
     3656        // For Coordinated Graphics.
     3657        scrollingCoordinator->scrollableAreaScrollLayerDidChange(&layer);
     3658        return;
     3659    }
     3660
     3661#if PLATFORM(IOS)
    35673662    ASSERT(!m_renderView.document().inPageCache());
    3568     m_scrollingLayers.add(layer);
    3569 }
    3570 
    3571 void RenderLayerCompositor::scrollingLayerRemoved(RenderLayer* layer, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer)
    3572 {
    3573     m_scrollingLayersNeedingUpdate.remove(layer);
    3574     m_scrollingLayers.remove(layer);
    3575 
    3576     if (m_renderView.document().inPageCache())
    3577         return;
    3578 
    3579     if (ChromeClient* client = this->chromeClient())
    3580         client->removeScrollingLayer(layer->renderer().element(), scrollingLayer, contentsLayer);
    3581 }
    3582 #endif
     3663    m_scrollingLayers.add(&layer);
     3664#endif
     3665}
    35833666
    35843667void RenderLayerCompositor::windowScreenDidChange(PlatformDisplayID displayID)
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.h

    r164699 r164759  
    267267#endif
    268268
    269     void updateViewportConstraintStatus(RenderLayer&);
    270     void removeViewportConstrainedLayer(RenderLayer&);
     269    void updateScrollCoordinatedStatus(RenderLayer&);
     270    void removeFromScrollCoordinatedLayers(RenderLayer&);
     271
     272    void willRemoveScrollingLayer(RenderLayer&);
     273    void didAddScrollingLayer(RenderLayer&);
    271274
    272275#if PLATFORM(IOS)
     
    274277    void unregisterAllViewportConstrainedLayers();
    275278
    276     void scrollingLayerAddedOrUpdated(RenderLayer*);
    277     void scrollingLayerRemoved(RenderLayer*, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer);
    278 
    279279    void registerAllScrollingLayers();
    280280    void unregisterAllScrollingLayers();
    281281#endif
     282
    282283    void resetTrackedRepaintRects();
    283284    void setTracksRepaints(bool);
     
    396397
    397398#if PLATFORM(IOS)
    398     bool requiresCompositingForScrolling(RenderLayerModelObject&) const;
     399    bool requiresCompositingForScrolling(const RenderLayer&) const;
    399400
    400401    void updateCustomLayersAfterFlush();
     
    404405#endif
    405406
    406     void addViewportConstrainedLayer(RenderLayer&);
    407     void registerOrUpdateViewportConstrainedLayer(RenderLayer&);
    408     void unregisterViewportConstrainedLayer(RenderLayer&);
     407    enum ScrollCoordinationReason {
     408        FixedOrSticky = 1 << 0,
     409        Scrolling = 1 << 1
     410    };
     411    typedef unsigned ScrollCoordinationReasons;
     412
     413    void updateScrollCoordinatedLayer(RenderLayer&, ScrollCoordinationReasons);
     414    void detachScrollCoordinatedLayer(RenderLayer&);
    409415
    410416    FixedPositionViewportConstraints computeFixedViewportConstraints(RenderLayer&) const;
     
    476482    HashSet<RenderLayer*> m_scrollingLayersNeedingUpdate;
    477483#endif
    478     HashSet<RenderLayer*> m_viewportConstrainedLayers;
    479     HashSet<RenderLayer*> m_viewportConstrainedLayersNeedingUpdate;
     484    HashSet<RenderLayer*> m_scrollCoordinatedLayers;
     485    HashSet<RenderLayer*> m_scrollCoordinatedLayersNeedingUpdate;
    480486
    481487    // Enclosing layer for overflow controls and the clipping layer
Note: See TracChangeset for help on using the changeset viewer.