Changeset 148759 in webkit


Ignore:
Timestamp:
Apr 19, 2013 12:58:08 PM (11 years ago)
Author:
rniwa@webkit.org
Message:

Make loops in RenderObject::containingBlock homogeneous in their forms to simplify
https://bugs.webkit.org/show_bug.cgi?id=114853

Reviewed by David Hyatt.

This patch prepares us to avoid computing containing blocks during a depth-first traversal of the render tree.

Extracted inline functions out of RenderBlock::containingBlock to make the code simpler. Also moved the code
to obtain the nearest containing block out of the loop for a relatively positioned inline.

  • rendering/RenderObject.cpp:

(WebCore::isNonReplacedInlineInFlowPosition): Extracted.
(WebCore::isContainingBlockCandidateForAbsolutelyPositionedObject): Extracted.
(WebCore::isNonRenderBlockInline): Extracted.
(WebCore::RenderObject::containingBlock): Refactored as stated above.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148758 r148759  
     12013-04-18  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Make loops in RenderObject::containingBlock homogeneous in their forms to simplify
     4        https://bugs.webkit.org/show_bug.cgi?id=114853
     5
     6        Reviewed by David Hyatt.
     7
     8        This patch prepares us to avoid computing containing blocks during a depth-first traversal of the render tree.
     9
     10        Extracted inline functions out of RenderBlock::containingBlock to make the code simpler. Also moved the code
     11        to obtain the nearest containing block out of the loop for a relatively positioned inline.
     12
     13        * rendering/RenderObject.cpp:
     14        (WebCore::isNonReplacedInlineInFlowPosition): Extracted.
     15        (WebCore::isContainingBlockCandidateForAbsolutelyPositionedObject): Extracted.
     16        (WebCore::isNonRenderBlockInline): Extracted.
     17        (WebCore::RenderObject::containingBlock): Refactored as stated above.
     18
    1192013-04-19  Tim Horton  <timothy_horton@apple.com>
    220
  • trunk/Source/WebCore/rendering/RenderObject.cpp

    r148545 r148759  
    769769}
    770770
     771static inline bool isContainingBlockCandidateForAbsolutelyPositionedObject(RenderObject* object)
     772{
     773    return object->style()->position() != StaticPosition
     774        || (object->hasTransform() && object->isRenderBlock())
     775#if ENABLE(SVG)
     776        || object->isSVGForeignObject()
     777#endif
     778        || object->isRenderView();
     779}
     780
     781static inline bool isNonRenderBlockInline(RenderObject* object)
     782{
     783    return (object->isInline() && !object->isReplaced()) || !object->isRenderBlock();
     784}
     785
    771786RenderBlock* RenderObject::containingBlock() const
    772787{
     
    774789    if (!o && isRenderScrollbarPart())
    775790        o = toRenderScrollbarPart(this)->rendererOwningScrollbar();
     791
    776792    if (!isText() && m_style->position() == FixedPosition) {
    777         while (o) {
    778             if (o->canContainFixedPositionObjects())
    779                 break;
     793        while (o && !o->canContainFixedPositionObjects())
    780794            o = o->parent();
    781         }
    782795        ASSERT(!o || !o->isAnonymousBlock());
    783796    } else if (!isText() && m_style->position() == AbsolutePosition) {
    784         while (o) {
    785             // For relpositioned inlines, we return the nearest non-anonymous enclosing block. We don't try
    786             // to return the inline itself.  This allows us to avoid having a positioned objects
    787             // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
    788             // from this method.  The container() method can actually be used to obtain the
    789             // inline directly.
    790             if (o->style()->position() != StaticPosition && (!o->isInline() || o->isReplaced()))
    791                 break;
    792             if (o->isRenderView())
    793                 break;
    794             if (o->hasTransform() && o->isRenderBlock())
    795                 break;
    796 
    797             if (o->style()->hasInFlowPosition() && o->isInline() && !o->isReplaced()) {
    798                 o = o->containingBlock();
    799                 break;
    800             }
    801 #if ENABLE(SVG)
    802             if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it
    803                 break;
    804 #endif
    805 
     797        while (o && !isContainingBlockCandidateForAbsolutelyPositionedObject(o))
    806798            o = o->parent();
    807         }
     799
     800        // For a relatively positioned inline, return its nearest non-anonymous containing block,
     801        // not the inline itself, to avoid having a positioned objects list in all RenderInlines
     802        // and use RenderBlock* as this function's return type.
     803        // Use RenderBlock::container() to obtain the inline.
     804        if (o->isRenderInline())
     805            o = o->containingBlock();
    808806
    809807        while (o && o->isAnonymousBlock())
    810808            o = o->containingBlock();
    811809    } else {
    812         while (o && ((o->isInline() && !o->isReplaced()) || !o->isRenderBlock()))
     810        while (o && isNonRenderBlockInline(o))
    813811            o = o->parent();
    814812    }
Note: See TracChangeset for help on using the changeset viewer.