Changeset 156190 in webkit


Ignore:
Timestamp:
Sep 20, 2013, 12:56:33 PM (12 years ago)
Author:
Antti Koivisto
Message:

Move layer hierarchy functions from RenderObject to RenderElement
https://bugs.webkit.org/show_bug.cgi?id=121692

Reviewed by Andreas Kling.

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::addLayers):
(WebCore::RenderElement::removeLayers):
(WebCore::RenderElement::moveLayers):
(WebCore::RenderElement::findNextLayer):
(WebCore::RenderElement::layerCreationAllowedForSubtree):

Move these from RenderObject.

(WebCore::RenderElement::insertedIntoTree):
(WebCore::RenderElement::willBeRemovedFromTree):

Factor the layer related portion of these virtuals here.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r156189 r156190  
     12013-09-20  Antti Koivisto  <antti@apple.com>
     2
     3        Move layer hierarchy functions from RenderObject to RenderElement
     4        https://bugs.webkit.org/show_bug.cgi?id=121692
     5
     6        Reviewed by Andreas Kling.
     7
     8        * rendering/RenderElement.cpp:
     9        (WebCore::RenderElement::addLayers):
     10        (WebCore::RenderElement::removeLayers):
     11        (WebCore::RenderElement::moveLayers):
     12        (WebCore::RenderElement::findNextLayer):
     13        (WebCore::RenderElement::layerCreationAllowedForSubtree):
     14       
     15            Move these from RenderObject.
     16
     17        (WebCore::RenderElement::insertedIntoTree):
     18        (WebCore::RenderElement::willBeRemovedFromTree):
     19       
     20            Factor the layer related portion of these virtuals here.
     21
    1222013-09-20  Benjamin Poulain  <benjamin@webkit.org>
    223
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r156151 r156190  
    193193}
    194194
    195 
    196 }
     195static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderElement*& newObject, RenderLayer*& beforeChild)
     196{
     197    if (obj->hasLayer()) {
     198        if (!beforeChild && newObject) {
     199            // We need to figure out the layer that follows newObject. We only do
     200            // this the first time we find a child layer, and then we update the
     201            // pointer values for newObject and beforeChild used by everyone else.
     202            beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
     203            newObject = nullptr;
     204        }
     205        parentLayer->addChild(toRenderLayerModelObject(obj)->layer(), beforeChild);
     206        return;
     207    }
     208
     209    for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
     210        addLayers(curr, parentLayer, newObject, beforeChild);
     211}
     212
     213void RenderElement::addLayers(RenderLayer* parentLayer)
     214{
     215    if (!parentLayer)
     216        return;
     217
     218    RenderElement* renderer = this;
     219    RenderLayer* beforeChild = nullptr;
     220    WebCore::addLayers(this, parentLayer, renderer, beforeChild);
     221}
     222
     223void RenderElement::removeLayers(RenderLayer* parentLayer)
     224{
     225    if (!parentLayer)
     226        return;
     227
     228    if (hasLayer()) {
     229        parentLayer->removeChild(toRenderLayerModelObject(this)->layer());
     230        return;
     231    }
     232
     233    for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
     234        if (child->isRenderElement())
     235            toRenderElement(child)->removeLayers(parentLayer);
     236    }
     237}
     238
     239void RenderElement::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
     240{
     241    if (!newParent)
     242        return;
     243
     244    if (hasLayer()) {
     245        RenderLayer* layer = toRenderLayerModelObject(this)->layer();
     246        ASSERT(oldParent == layer->parent());
     247        if (oldParent)
     248            oldParent->removeChild(layer);
     249        newParent->addChild(layer);
     250        return;
     251    }
     252
     253    for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
     254        if (child->isRenderElement())
     255            toRenderElement(child)->moveLayers(oldParent, newParent);
     256    }
     257}
     258
     259RenderLayer* RenderElement::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent)
     260{
     261    // Error check the parent layer passed in. If it's null, we can't find anything.
     262    if (!parentLayer)
     263        return 0;
     264
     265    // Step 1: If our layer is a child of the desired parent, then return our layer.
     266    RenderLayer* ourLayer = hasLayer() ? toRenderLayerModelObject(this)->layer() : nullptr;
     267    if (ourLayer && ourLayer->parent() == parentLayer)
     268        return ourLayer;
     269
     270    // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
     271    // into our siblings trying to find the next layer whose parent is the desired parent.
     272    if (!ourLayer || ourLayer == parentLayer) {
     273        for (RenderObject* child = startPoint ? startPoint->nextSibling() : firstChild(); child; child = child->nextSibling()) {
     274            if (!child->isRenderElement())
     275                continue;
     276            RenderLayer* nextLayer = toRenderElement(child)->findNextLayer(parentLayer, nullptr, false);
     277            if (nextLayer)
     278                return nextLayer;
     279        }
     280    }
     281
     282    // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
     283    // find anything.
     284    if (parentLayer == ourLayer)
     285        return nullptr;
     286
     287    // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
     288    // follow us to see if we can locate a layer.
     289    if (checkParent && parent())
     290        return parent()->findNextLayer(parentLayer, this, true);
     291
     292    return nullptr;
     293}
     294
     295bool RenderElement::layerCreationAllowedForSubtree() const
     296{
     297#if ENABLE(SVG)
     298    RenderElement* parentRenderer = parent();
     299    while (parentRenderer) {
     300        if (parentRenderer->isSVGHiddenContainer())
     301            return false;
     302        parentRenderer = parentRenderer->parent();
     303    }
     304#endif
     305   
     306    return true;
     307}
     308
     309void RenderElement::insertedIntoTree()
     310{
     311    RenderObject::insertedIntoTree();
     312
     313    // Keep our layer hierarchy updated. Optimize for the common case where we don't have any children
     314    // and don't have a layer attached to ourselves.
     315    RenderLayer* layer = nullptr;
     316    if (firstChild() || hasLayer()) {
     317        layer = parent()->enclosingLayer();
     318        addLayers(layer);
     319    }
     320
     321    // If |this| is visible but this object was not, tell the layer it has some visible content
     322    // that needs to be drawn and layer visibility optimization can't be used
     323    if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
     324        if (!layer)
     325            layer = parent()->enclosingLayer();
     326        if (layer)
     327            layer->setHasVisibleContent();
     328    }
     329}
     330
     331void RenderElement::willBeRemovedFromTree()
     332{
     333    // If we remove a visible child from an invisible parent, we don't know the layer visibility any more.
     334    RenderLayer* layer = nullptr;
     335    if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
     336        if ((layer = parent()->enclosingLayer()))
     337            layer->dirtyVisibleContentStatus();
     338    }
     339    // Keep our layer hierarchy updated.
     340    if (firstChild() || hasLayer()) {
     341        if (!layer)
     342            layer = parent()->enclosingLayer();
     343        removeLayers(layer);
     344    }
     345
     346    RenderObject::willBeRemovedFromTree();
     347}
     348
     349
     350}
  • trunk/Source/WebCore/rendering/RenderElement.h

    r156166 r156190  
    4444    virtual void removeChild(RenderObject*);
    4545
     46    // The following functions are used when the render tree hierarchy changes to make sure layers get
     47    // properly added and removed. Since containership can be implemented by any subclass, and since a hierarchy
     48    // can contain a mixture of boxes and other object types, these functions need to be in the base class.
     49    void addLayers(RenderLayer* parentLayer);
     50    void removeLayers(RenderLayer* parentLayer);
     51    void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
     52    RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
     53
    4654protected:
    4755    explicit RenderElement(Element*);
    4856
    49     LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages = false) const
    50     {
    51         return WebCore::valueForLength(length, maximumValue, &view(), roundPercentages);
    52     }
     57    bool layerCreationAllowedForSubtree() const;
    5358
    54     LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages = false) const
    55     {
    56         return WebCore::minimumValueForLength(length, maximumValue, &view(), roundPercentages);
    57     }
     59    LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue, bool roundPercentages = false) const;
     60    LayoutUnit minimumValueForLength(const Length&, LayoutUnit maximumValue, bool roundPercentages = false) const;
     61
     62    virtual void insertedIntoTree() OVERRIDE;
     63    virtual void willBeRemovedFromTree() OVERRIDE;
    5864
    5965private:
     
    6369    void isText() const WTF_DELETED_FUNCTION;
    6470};
     71
     72inline LayoutUnit RenderElement::valueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) const
     73{
     74    return WebCore::valueForLength(length, maximumValue, &view(), roundPercentages);
     75}
     76
     77inline LayoutUnit RenderElement::minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) const
     78{
     79    return WebCore::minimumValueForLength(length, maximumValue, &view(), roundPercentages);
     80}
    6581
    6682inline RenderElement& toRenderElement(RenderObject& object)
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r156146 r156190  
    18991899
    19001900    // Remove all descendant layers from the hierarchy and add them to the new position.
    1901     for (RenderObject* curr = renderer().firstChild(); curr; curr = curr->nextSibling())
    1902         curr->moveLayers(m_parent, this);
     1901    for (RenderObject* curr = renderer().firstChild(); curr; curr = curr->nextSibling()) {
     1902        if (curr->isRenderElement())
     1903            toRenderElement(curr)->moveLayers(m_parent, this);
     1904    }
    19031905
    19041906    // Clear out all the clip rects.
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r156166 r156190  
    527527#endif // ENABLE(IOS_TEXT_AUTOSIZING)
    528528
    529 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
    530                       RenderLayer*& beforeChild)
    531 {
    532     if (obj->hasLayer()) {
    533         if (!beforeChild && newObject) {
    534             // We need to figure out the layer that follows newObject. We only do
    535             // this the first time we find a child layer, and then we update the
    536             // pointer values for newObject and beforeChild used by everyone else.
    537             beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
    538             newObject = 0;
    539         }
    540         parentLayer->addChild(toRenderLayerModelObject(obj)->layer(), beforeChild);
    541         return;
    542     }
    543 
    544     for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
    545         addLayers(curr, parentLayer, newObject, beforeChild);
    546 }
    547 
    548 void RenderObject::addLayers(RenderLayer* parentLayer)
    549 {
    550     if (!parentLayer)
    551         return;
    552 
    553     RenderObject* object = this;
    554     RenderLayer* beforeChild = 0;
    555     WebCore::addLayers(this, parentLayer, object, beforeChild);
    556 }
    557 
    558 void RenderObject::removeLayers(RenderLayer* parentLayer)
    559 {
    560     if (!parentLayer)
    561         return;
    562 
    563     if (hasLayer()) {
    564         parentLayer->removeChild(toRenderLayerModelObject(this)->layer());
    565         return;
    566     }
    567 
    568     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
    569         curr->removeLayers(parentLayer);
    570 }
    571 
    572 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
    573 {
    574     if (!newParent)
    575         return;
    576 
    577     if (hasLayer()) {
    578         RenderLayer* layer = toRenderLayerModelObject(this)->layer();
    579         ASSERT(oldParent == layer->parent());
    580         if (oldParent)
    581             oldParent->removeChild(layer);
    582         newParent->addChild(layer);
    583         return;
    584     }
    585 
    586     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
    587         curr->moveLayers(oldParent, newParent);
    588 }
    589 
    590 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
    591                                          bool checkParent)
    592 {
    593     // Error check the parent layer passed in. If it's null, we can't find anything.
    594     if (!parentLayer)
    595         return 0;
    596 
    597     // Step 1: If our layer is a child of the desired parent, then return our layer.
    598     RenderLayer* ourLayer = hasLayer() ? toRenderLayerModelObject(this)->layer() : 0;
    599     if (ourLayer && ourLayer->parent() == parentLayer)
    600         return ourLayer;
    601 
    602     // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
    603     // into our siblings trying to find the next layer whose parent is the desired parent.
    604     if (!ourLayer || ourLayer == parentLayer) {
    605         for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
    606              curr; curr = curr->nextSibling()) {
    607             RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
    608             if (nextLayer)
    609                 return nextLayer;
    610         }
    611     }
    612 
    613     // Step 3: If our layer is the desired parent layer, then we're finished. We didn't
    614     // find anything.
    615     if (parentLayer == ourLayer)
    616         return 0;
    617 
    618     // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
    619     // follow us to see if we can locate a layer.
    620     if (checkParent && parent())
    621         return parent()->findNextLayer(parentLayer, this, true);
    622 
    623     return 0;
    624 }
    625 
    626529RenderLayer* RenderObject::enclosingLayer() const
    627530{
     
    634537    }
    635538    return 0;
    636 }
    637 
    638 bool RenderObject::layerCreationAllowedForSubtree() const
    639 {
    640 #if ENABLE(SVG)
    641     RenderElement* parentRenderer = parent();
    642     while (parentRenderer) {
    643         if (parentRenderer->isSVGHiddenContainer())
    644             return false;
    645         parentRenderer = parentRenderer->parent();
    646     }
    647 #endif
    648    
    649     return true;
    650539}
    651540
     
    25872476    // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion.
    25882477
    2589     // Keep our layer hierarchy updated. Optimize for the common case where we don't have any children
    2590     // and don't have a layer attached to ourselves.
    2591     RenderLayer* layer = 0;
    2592     if (firstChild() || hasLayer()) {
    2593         layer = parent()->enclosingLayer();
    2594         addLayers(layer);
    2595     }
    2596 
    2597     // If |this| is visible but this object was not, tell the layer it has some visible content
    2598     // that needs to be drawn and layer visibility optimization can't be used
    2599     if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
    2600         if (!layer)
    2601             layer = parent()->enclosingLayer();
    2602         if (layer)
    2603             layer->setHasVisibleContent();
    2604     }
    2605 
    26062478    if (!isFloating() && parent()->childrenInline())
    26072479        parent()->dirtyLinesFromChangedChild(this);
     
    26192491        if (repaintFixedBackgroundsOnScroll && m_style && m_style->hasFixedBackgroundImage())
    26202492            view().frameView().removeSlowRepaintObject(this);
    2621     }
    2622 
    2623     // If we remove a visible child from an invisible parent, we don't know the layer visibility any more.
    2624     RenderLayer* layer = 0;
    2625     if (parent()->style()->visibility() != VISIBLE && style()->visibility() == VISIBLE && !hasLayer()) {
    2626         if ((layer = parent()->enclosingLayer()))
    2627             layer->dirtyVisibleContentStatus();
    2628     }
    2629 
    2630     // Keep our layer hierarchy updated.
    2631     if (firstChild() || hasLayer()) {
    2632         if (!layer)
    2633             layer = parent()->enclosingLayer();
    2634         removeLayers(layer);
    26352493    }
    26362494
  • trunk/Source/WebCore/rendering/RenderObject.h

    r156155 r156190  
    221221#endif
    222222
    223     // The following six functions are used when the render tree hierarchy changes to make sure layers get
    224     // properly added and removed.  Since containership can be implemented by any subclass, and since a hierarchy
    225     // can contain a mixture of boxes and other object types, these functions need to be in the base class.
    226223    RenderLayer* enclosingLayer() const;
    227     void addLayers(RenderLayer* parentLayer);
    228     void removeLayers(RenderLayer* parentLayer);
    229     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
    230     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
    231224
    232225    // Scrolling is a RenderBox concept, however some code just cares about recursively scrolling our enclosing ScrollableArea(s).
     
    993986
    994987protected:
    995     bool layerCreationAllowedForSubtree() const;
    996 
    997988    // Overrides should call the superclass at the end
    998989    virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle);
Note: See TracChangeset for help on using the changeset viewer.