Changeset 86098 in webkit


Ignore:
Timestamp:
May 9, 2011 3:53:20 PM (13 years ago)
Author:
tony@chromium.org
Message:

2011-05-09 Tony Chang <tony@chromium.org>

Reviewed by Eric Seidel.

Style cleanups in RenderFlexibleBox.cpp
https://bugs.webkit.org/show_bug.cgi?id=60504

No new tests, just refactoring.

  • rendering/RenderFlexibleBox.cpp: (WebCore::FlexBoxIterator::FlexBoxIterator): Use m_ for member variables, and

use class initializer list.

(WebCore::FlexBoxIterator::reset):
(WebCore::FlexBoxIterator::next):
(WebCore::RenderFlexibleBox::RenderFlexibleBox):
(WebCore::marginWidthForChild): Pull out common code used in calc*PrefWidths
(WebCore::RenderFlexibleBox::calcHorizontalPrefWidths):
(WebCore::RenderFlexibleBox::calcVerticalPrefWidths):
(WebCore::RenderFlexibleBox::computePreferredLogicalWidths):
(WebCore::RenderFlexibleBox::layoutBlock):
(WebCore::gatherFlexChildrenInfo): Rewrite uses of FlexBoxIterator into for statements

rather than while loops.

(WebCore::RenderFlexibleBox::layoutHorizontalBox): ditto
(WebCore::RenderFlexibleBox::layoutVerticalBox): ditto
(WebCore::RenderFlexibleBox::applyLineClamp):
(WebCore::RenderFlexibleBox::allowedChildFlex): Rename variables w/h to width/height.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r86093 r86098  
     12011-05-09  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Style cleanups in RenderFlexibleBox.cpp
     6        https://bugs.webkit.org/show_bug.cgi?id=60504
     7
     8        No new tests, just refactoring.
     9
     10        * rendering/RenderFlexibleBox.cpp:
     11        (WebCore::FlexBoxIterator::FlexBoxIterator): Use m_ for member variables, and
     12            use class initializer list.
     13        (WebCore::FlexBoxIterator::reset):
     14        (WebCore::FlexBoxIterator::next):
     15        (WebCore::RenderFlexibleBox::RenderFlexibleBox):
     16        (WebCore::marginWidthForChild): Pull out common code used in calc*PrefWidths
     17        (WebCore::RenderFlexibleBox::calcHorizontalPrefWidths):
     18        (WebCore::RenderFlexibleBox::calcVerticalPrefWidths):
     19        (WebCore::RenderFlexibleBox::computePreferredLogicalWidths):
     20        (WebCore::RenderFlexibleBox::layoutBlock):
     21        (WebCore::gatherFlexChildrenInfo): Rewrite uses of FlexBoxIterator into for statements
     22            rather than while loops.
     23        (WebCore::RenderFlexibleBox::layoutHorizontalBox): ditto
     24        (WebCore::RenderFlexibleBox::layoutVerticalBox): ditto
     25        (WebCore::RenderFlexibleBox::applyLineClamp):
     26        (WebCore::RenderFlexibleBox::allowedChildFlex): Rename variables w/h to width/height.
     27
    1282011-05-09  Eric Seidel  <eric@webkit.org>
    229
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r85973 r86098  
    3939public:
    4040    FlexBoxIterator(RenderFlexibleBox* parent)
     41        : m_box(parent)
     42        , m_lastOrdinal(1)
    4143    {
    42         box = parent;
    43         if (box->style()->boxOrient() == HORIZONTAL && !box->style()->isLeftToRightDirection())
    44             forward = box->style()->boxDirection() != BNORMAL;
     44        if (m_box->style()->boxOrient() == HORIZONTAL && !m_box->style()->isLeftToRightDirection())
     45            m_forward = m_box->style()->boxDirection() != BNORMAL;
    4546        else
    46             forward = box->style()->boxDirection() == BNORMAL;
    47         lastOrdinal = 1;
    48         if (!forward) {
     47            m_forward = m_box->style()->boxDirection() == BNORMAL;
     48        if (!m_forward) {
    4949            // No choice, since we're going backwards, we have to find out the highest ordinal up front.
    50             RenderBox* child = box->firstChildBox();
     50            RenderBox* child = m_box->firstChildBox();
    5151            while (child) {
    52                 if (child->style()->boxOrdinalGroup() > lastOrdinal)
    53                     lastOrdinal = child->style()->boxOrdinalGroup();
     52                if (child->style()->boxOrdinalGroup() > m_lastOrdinal)
     53                    m_lastOrdinal = child->style()->boxOrdinalGroup();
    5454                child = child->nextSiblingBox();
    5555            }
    5656        }
    57        
     57
    5858        reset();
    5959    }
     
    6161    void reset()
    6262    {
    63         current = 0;
    64         currentOrdinal = forward ? 0 : lastOrdinal+1;
     63        m_currentChild = 0;
     64        m_currentOrdinal = m_forward ? 0 : m_lastOrdinal + 1;
    6565    }
    6666
     
    7070        return next();
    7171    }
    72    
     72
    7373    RenderBox* next()
    7474    {
    75         do { 
    76             if (!current) {
    77                 if (forward) {
    78                     currentOrdinal++;
    79                     if (currentOrdinal > lastOrdinal)
     75        do {
     76            if (!m_currentChild) {
     77                if (m_forward) {
     78                    ++m_currentOrdinal;
     79                    if (m_currentOrdinal > m_lastOrdinal)
    8080                        return 0;
    81                     current = box->firstChildBox();
     81                    m_currentChild = m_box->firstChildBox();
    8282                } else {
    83                     currentOrdinal--;
    84                     if (currentOrdinal == 0)
     83                    --m_currentOrdinal;
     84                    if (!m_currentOrdinal)
    8585                        return 0;
    86                     current = box->lastChildBox();
     86                    m_currentChild = m_box->lastChildBox();
    8787                }
    8888            }
    8989            else
    90                 current = forward ? current->nextSiblingBox() : current->previousSiblingBox();
    91             if (current && current->style()->boxOrdinalGroup() > lastOrdinal)
    92                 lastOrdinal = current->style()->boxOrdinalGroup();
    93         } while (!current || current->style()->boxOrdinalGroup() != currentOrdinal ||
    94                  current->style()->visibility() == COLLAPSE);
    95         return current;
     90                m_currentChild = m_forward ? m_currentChild->nextSiblingBox() : m_currentChild->previousSiblingBox();
     91            if (m_currentChild && m_currentChild->style()->boxOrdinalGroup() > m_lastOrdinal)
     92                m_lastOrdinal = m_currentChild->style()->boxOrdinalGroup();
     93        } while (!m_currentChild || m_currentChild->style()->boxOrdinalGroup() != m_currentOrdinal
     94                 || m_currentChild->style()->visibility() == COLLAPSE);
     95        return m_currentChild;
    9696    }
    9797
    9898private:
    99     RenderFlexibleBox* box;
    100     RenderBox* current;
    101     bool forward;
    102     unsigned int currentOrdinal;
    103     unsigned int lastOrdinal;
     99    RenderFlexibleBox* m_box;
     100    RenderBox* m_currentChild;
     101    bool m_forward;
     102    unsigned int m_currentOrdinal;
     103    unsigned int m_lastOrdinal;
    104104};
    105    
     105
    106106RenderFlexibleBox::RenderFlexibleBox(Node* node)
    107 :RenderBlock(node)
     107    : RenderBlock(node)
    108108{
    109109    setChildrenInline(false); // All of our children must be block-level
     
    115115}
    116116
     117static int marginWidthForChild(RenderBox* child)
     118{
     119    // A margin basically has three types: fixed, percentage, and auto (variable).
     120    // Auto and percentage margins simply become 0 when computing min/max width.
     121    // Fixed margins can be added in as is.
     122    Length marginLeft = child->style()->marginLeft();
     123    Length marginRight = child->style()->marginRight();
     124    int margin = 0;
     125    if (marginLeft.isFixed())
     126        margin += marginLeft.value();
     127    if (marginRight.isFixed())
     128        margin += marginRight.value();
     129    return margin;
     130}
     131
    117132void RenderFlexibleBox::calcHorizontalPrefWidths()
    118133{
    119134    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
    120         // positioned children don't affect the minmaxwidth
     135        // Positioned children and collapsed children don't affect the min/max width.
    121136        if (child->isPositioned() || child->style()->visibility() == COLLAPSE)
    122137            continue;
    123138
    124         // A margin basically has three types: fixed, percentage, and auto (variable).
    125         // Auto and percentage margins simply become 0 when computing min/max width.
    126         // Fixed margins can be added in as is.
    127         Length ml = child->style()->marginLeft();
    128         Length mr = child->style()->marginRight();
    129         int margin = 0, marginLeft = 0, marginRight = 0;
    130         if (ml.isFixed())
    131             marginLeft += ml.value();
    132         if (mr.isFixed())
    133             marginRight += mr.value();
    134         margin = marginLeft + marginRight;
    135 
     139        int margin = marginWidthForChild(child);
    136140        m_minPreferredLogicalWidth += child->minPreferredLogicalWidth() + margin;
    137141        m_maxPreferredLogicalWidth += child->maxPreferredLogicalWidth() + margin;
    138     }   
     142    }
    139143}
    140144
     
    142146{
    143147    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
    144         // Positioned children and collapsed children don't affect the min/max width
     148        // Positioned children and collapsed children don't affect the min/max width.
    145149        if (child->isPositioned() || child->style()->visibility() == COLLAPSE)
    146150            continue;
    147151
    148         // A margin basically has three types: fixed, percentage, and auto (variable).
    149         // Auto/percentage margins simply become 0 when computing min/max width.
    150         // Fixed margins can be added in as is.
    151         Length ml = child->style()->marginLeft();
    152         Length mr = child->style()->marginRight();
    153         int margin = 0;
    154         if (ml.isFixed())
    155             margin += ml.value();
    156         if (mr.isFixed())
    157             margin += mr.value();
    158        
    159         int w = child->minPreferredLogicalWidth() + margin;
    160         m_minPreferredLogicalWidth = max(w, m_minPreferredLogicalWidth);
    161        
    162         w = child->maxPreferredLogicalWidth() + margin;
    163         m_maxPreferredLogicalWidth = max(w, m_maxPreferredLogicalWidth);
    164     }   
     152        int margin = marginWidthForChild(child);
     153        int width = child->minPreferredLogicalWidth() + margin;
     154        m_minPreferredLogicalWidth = max(width, m_minPreferredLogicalWidth);
     155
     156        width = child->maxPreferredLogicalWidth() + margin;
     157        m_maxPreferredLogicalWidth = max(width, m_maxPreferredLogicalWidth);
     158    }
    165159}
    166160
     
    193187        m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value()));
    194188    }
    195    
     189
    196190    if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {
    197191        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value()));
     
    218212    int previousWidth = width();
    219213    int previousHeight = height();
    220    
     214
    221215    computeLogicalWidth();
    222216    computeLogicalHeight();
    223    
     217
    224218    m_overflow.clear();
    225219
     
    273267        setMaxMarginAfterValues(0, 0);
    274268    }
    275    
     269
    276270    computeOverflow(oldClientAfterEdge);
    277271
     
    290284    // Repaint with our new bounds if they are different from our old bounds.
    291285    repainter.repaintAfterLayout();
    292    
     286
    293287    setNeedsLayout(false);
    294288}
     
    297291static void gatherFlexChildrenInfo(FlexBoxIterator& iterator, bool relayoutChildren, unsigned int& highestFlexGroup, unsigned int& lowestFlexGroup, bool& haveFlex)
    298292{
    299     RenderBox* child = iterator.first();
    300     while (child) {
     293    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    301294        // Check to see if this child flexes.
    302295        if (!child->isPositioned() && child->style()->boxFlex() > 0.0f) {
     
    315308                highestFlexGroup = flexGroup;
    316309        }
    317         child = iterator.next();
    318310    }
    319311}
     
    336328    gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex);
    337329
    338     RenderBox* child;
    339 
    340330    RenderBlock::startDelayUpdateScrollInfo();
    341331
     
    347337
    348338        xPos = borderLeft() + paddingLeft();
    349                
     339
    350340        // Our first pass is done without flexing.  We simply lay the children
    351341        // out within the box.  We have to do a layout first in order to determine
    352342        // our box's intrinsic height.
    353343        int maxAscent = 0, maxDescent = 0;
    354         child = iterator.first();
    355         while (child) {
     344        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    356345            // make sure we relayout children if we need it.
    357346            if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())))
    358347                child->setChildNeedsLayout(true, false);
    359            
    360             if (child->isPositioned()) {
    361                 child = iterator.next();
     348
     349            if (child->isPositioned())
    362350                continue;
    363             }
    364    
     351
    365352            // Compute the child's vertical margins.
    366353            child->computeBlockDirectionMargins(this);
    367    
     354
    368355            if (!child->needsLayout())
    369356                child->markForPaginationRelayoutIfNeeded();
     
    371358            // Now do the layout.
    372359            child->layoutIfNeeded();
    373    
     360
    374361            // Update our height and overflow height.
    375362            if (style()->boxAlign() == BBASELINE) {
     
    379366                ascent += child->marginTop();
    380367                int descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent;
    381                
     368
    382369                // Update our maximum ascent.
    383370                maxAscent = max(maxAscent, ascent);
    384                
     371
    385372                // Update our maximum descent.
    386373                maxDescent = max(maxDescent, descent);
    387                
     374
    388375                // Now update our height.
    389376                setHeight(max(yPos + maxAscent + maxDescent, height()));
     
    391378            else
    392379                setHeight(max(height(), yPos + child->marginTop() + child->height() + child->marginBottom()));
    393 
    394             child = iterator.next();
    395         }
    396        
     380        }
     381
    397382        if (!iterator.first() && hasLineIfEmpty())
    398383            setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
    399        
     384
    400385        setHeight(height() + toAdd);
    401        
     386
    402387        oldHeight = height();
    403388        computeLogicalHeight();
     
    406391        if (oldHeight != height())
    407392            heightSpecified = true;
    408        
     393
    409394        // Now that our height is actually known, we can place our boxes.
    410395        m_stretchingChildren = (style()->boxAlign() == BSTRETCH);
    411         child = iterator.first();
    412         while (child) {
     396        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    413397            if (child->isPositioned()) {
    414398                child->containingBlock()->insertPositionedObject(child);
     
    420404                        child->setChildNeedsLayout(true, false);
    421405                }
    422                 child = iterator.next();
    423406                continue;
    424407            }
    425    
     408
    426409            // We need to see if this child's height has changed, since we make block elements
    427410            // fill the height of a containing box by default.
     
    431414            if (oldChildHeight != child->height())
    432415                child->setChildNeedsLayout(true, false);
    433                
     416
    434417            if (!child->needsLayout())
    435418                child->markForPaginationRelayoutIfNeeded();
    436419
    437420            child->layoutIfNeeded();
    438    
     421
    439422            // We can place the child now, using our value of box-align.
    440423            xPos += child->marginLeft();
     
    442425            switch (style()->boxAlign()) {
    443426                case BCENTER:
    444                     childY += child->marginTop() + max(0, (contentHeight() - (child->height() + child->marginTop() + child->marginBottom()))/2);
     427                    childY += child->marginTop() + max(0, (contentHeight() - (child->height() + child->marginTop() + child->marginBottom())) / 2);
    445428                    break;
    446429                case BBASELINE: {
     
    461444
    462445            placeChild(child, xPos, childY);
    463            
     446
    464447            xPos += child->width() + child->marginRight();
    465    
    466             child = iterator.next();
    467448        }
    468449
    469450        remainingSpace = borderLeft() + paddingLeft() + contentWidth() - xPos;
    470        
     451
    471452        m_stretchingChildren = false;
    472453        if (m_flexingChildren)
     
    493474                    int groupRemainingSpaceAtBeginning = groupRemainingSpace;
    494475                    float totalFlex = 0.0f;
    495                     child = iterator.first();
    496                     while (child) {
     476                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    497477                        if (allowedChildFlex(child, expanding, i))
    498478                            totalFlex += child->style()->boxFlex();
    499                         child = iterator.next();
    500                     }
    501                     child = iterator.first();
     479                    }
    502480                    int spaceAvailableThisPass = groupRemainingSpace;
    503                     while (child) {
     481                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    504482                        int allowedFlex = allowedChildFlex(child, expanding, i);
    505483                        if (allowedFlex) {
     
    507485                            spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex);
    508486                        }
    509                         child = iterator.next();
    510                     }
    511 
    512                     // The flex groups may not have any flexible objects this time around.
     487                    }
     488
     489                    // The flex groups may not have any flexible objects this time around.
    513490                    if (!spaceAvailableThisPass || totalFlex == 0.0f) {
    514491                        // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group.
     
    518495
    519496                    // Now distribute the space to objects.
    520                     child = iterator.first();
    521                     while (child && spaceAvailableThisPass && totalFlex) {
     497                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
    522498                        if (allowedChildFlex(child, expanding, i)) {
    523499                            int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex));
     
    531507                            remainingSpace -= spaceAdd;
    532508                            groupRemainingSpace -= spaceAdd;
    533                            
     509
    534510                            totalFlex -= child->style()->boxFlex();
    535511                        }
    536                         child = iterator.next();
    537512                    }
    538513                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
    539                         // this is not advancing, avoid getting stuck by distributing the remaining pixels
    540                         child = iterator.first();
     514                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
    541515                        int spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
    542                         while (child && groupRemainingSpace) {
     516                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
    543517                            if (allowedChildFlex(child, expanding, i)) {
    544518                                child->setOverrideSize(child->overrideWidth() + spaceAdd);
     
    548522                                groupRemainingSpace -= spaceAdd;
    549523                            }
    550                             child = iterator.next();
    551524                        }
    552525                    }
     
    571544            // Determine the total number of children.
    572545            int totalChildren = 0;
    573             child = iterator.first();
    574             while (child) {
    575                 if (child->isPositioned()) {
    576                     child = iterator.next();
     546            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     547                if (child->isPositioned())
    577548                    continue;
    578                 }
    579                 totalChildren++;
    580                 child = iterator.next();
     549                ++totalChildren;
    581550            }
    582551
     
    584553            // justification level.
    585554            if (totalChildren > 1) {
    586                 totalChildren--;
     555                --totalChildren;
    587556                bool firstChild = true;
    588                 child = iterator.first();
    589                 while (child) {
    590                     if (child->isPositioned()) {
    591                         child = iterator.next();
     557                for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     558                    if (child->isPositioned())
    592559                        continue;
    593                     }
    594560
    595561                    if (firstChild) {
    596562                        firstChild = false;
    597                         child = iterator.next();
    598563                        continue;
    599564                    }
     
    601566                    offset += remainingSpace/totalChildren;
    602567                    remainingSpace -= (remainingSpace/totalChildren);
    603                     totalChildren--;
    604 
    605                     placeChild(child, child->x()+offset, child->y());
    606                     child = iterator.next();
     568                    --totalChildren;
     569
     570                    placeChild(child, child->x() + offset, child->y());
    607571                }
    608572            }
    609573        } else {
    610574            if (style()->boxPack() == BCENTER)
    611                 offset += remainingSpace/2;
     575                offset += remainingSpace / 2;
    612576            else // END for LTR, START for RTL
    613577                offset += remainingSpace;
    614             child = iterator.first();
    615             while (child) {
    616                 if (child->isPositioned()) {
    617                     child = iterator.next();
     578            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     579                if (child->isPositioned())
    618580                    continue;
    619                 }
    620                 placeChild(child, child->x()+offset, child->y());
    621                 child = iterator.next();
    622             }
    623         }
    624     }
    625    
     581
     582                placeChild(child, child->x() + offset, child->y());
     583            }
     584        }
     585    }
     586
    626587    // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of
    627588    // a height change, we revert our height back to the intrinsic height before returning.
     
    644605    bool haveFlex = false;
    645606    gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex);
    646 
    647     RenderBox* child;
    648607
    649608    // We confine the line clamp ugliness to vertical flexible boxes (thus keeping it out of
     
    663622        int minHeight = height() + toAdd;
    664623
    665         child = iterator.first();
    666         while (child) {
    667             // make sure we relayout children if we need it.
     624        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     625            // Make sure we relayout children if we need it.
    668626            if (!haveLineClamp && (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))))
    669627                child->setChildNeedsLayout(true, false);
    670    
     628
    671629            if (child->isPositioned()) {
    672630                child->containingBlock()->insertPositionedObject(child);
     
    678636                        child->setChildNeedsLayout(true, false);
    679637                }
    680                 child = iterator.next();
    681638                continue;
    682             } 
    683    
     639            }
     640
    684641            // Compute the child's vertical margins.
    685642            child->computeBlockDirectionMargins(this);
    686    
     643
    687644            // Add in the child's marginTop to our height.
    688645            setHeight(height() + child->marginTop());
    689    
     646
    690647            if (!child->needsLayout())
    691648                child->markForPaginationRelayoutIfNeeded();
     
    693650            // Now do a layout.
    694651            child->layoutIfNeeded();
    695    
     652
    696653            // We can place the child now, using our value of box-align.
    697654            int childX = borderLeft() + paddingLeft();
     
    699656                case BCENTER:
    700657                case BBASELINE: // Baseline just maps to center for vertical boxes
    701                     childX += child->marginLeft() + max(0, (contentWidth() - (child->width() + child->marginLeft() + child->marginRight()))/2);
     658                    childX += child->marginLeft() + max(0, (contentWidth() - (child->width() + child->marginLeft() + child->marginRight())) / 2);
    702659                    break;
    703660                case BEND:
     
    714671                    break;
    715672            }
    716    
     673
    717674            // Place the child.
    718675            placeChild(child, childX, height());
    719676            setHeight(height() + child->height() + child->marginBottom());
    720 
    721             child = iterator.next();
    722677        }
    723678
    724679        yPos = height();
    725        
     680
    726681        if (!iterator.first() && hasLineIfEmpty())
    727682            setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes));
    728    
     683
    729684        setHeight(height() + toAdd);
    730685
     
    741696
    742697        remainingSpace = borderTop() + paddingTop() + contentHeight() - yPos;
    743        
     698
    744699        if (m_flexingChildren)
    745700            haveFlex = false; // We're done.
     
    765720                    int groupRemainingSpaceAtBeginning = groupRemainingSpace;
    766721                    float totalFlex = 0.0f;
    767                     child = iterator.first();
    768                     while (child) {
     722                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    769723                        if (allowedChildFlex(child, expanding, i))
    770724                            totalFlex += child->style()->boxFlex();
    771                         child = iterator.next();
    772                     }
    773                     child = iterator.first();
     725                    }
    774726                    int spaceAvailableThisPass = groupRemainingSpace;
    775                     while (child) {
     727                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    776728                        int allowedFlex = allowedChildFlex(child, expanding, i);
    777729                        if (allowedFlex) {
     
    779731                            spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex);
    780732                        }
    781                         child = iterator.next();
    782                     }
    783 
    784                     // The flex groups may not have any flexible objects this time around.
     733                    }
     734
     735                    // The flex groups may not have any flexible objects this time around.
    785736                    if (!spaceAvailableThisPass || totalFlex == 0.0f) {
    786737                        // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group.
     
    788739                        continue;
    789740                    }
    790            
     741
    791742                    // Now distribute the space to objects.
    792                     child = iterator.first();
    793                     while (child && spaceAvailableThisPass && totalFlex) {
     743                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
    794744                        if (allowedChildFlex(child, expanding, i)) {
    795745                            int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex));
     
    803753                            remainingSpace -= spaceAdd;
    804754                            groupRemainingSpace -= spaceAdd;
    805                            
     755
    806756                            totalFlex -= child->style()->boxFlex();
    807757                        }
    808                         child = iterator.next();
    809758                    }
    810759                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
    811                         // this is not advancing, avoid getting stuck by distributing the remaining pixels
    812                         child = iterator.first();
     760                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
    813761                        int spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
    814                         while (child && groupRemainingSpace) {
     762                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
    815763                            if (allowedChildFlex(child, expanding, i)) {
    816764                                child->setOverrideSize(child->overrideHeight() + spaceAdd);
     
    820768                                groupRemainingSpace -= spaceAdd;
    821769                            }
    822                             child = iterator.next();
    823770                        }
    824771                    }
     
    829776            if (haveFlex && !m_flexingChildren)
    830777                haveFlex = false;
    831         }       
     778        }
    832779    } while (haveFlex);
    833780
     
    840787            // Determine the total number of children.
    841788            int totalChildren = 0;
    842             child = iterator.first();
    843             while (child) {
    844                 if (child->isPositioned()) {
    845                     child = iterator.next();
     789            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     790                if (child->isPositioned())
    846791                    continue;
    847                 }
    848                 totalChildren++;
    849                 child = iterator.next();
    850             }
    851            
     792
     793                ++totalChildren;
     794            }
     795
    852796            // Iterate over the children and space them out according to the
    853797            // justification level.
    854798            if (totalChildren > 1) {
    855                 totalChildren--;
     799                --totalChildren;
    856800                bool firstChild = true;
    857                 child = iterator.first();
    858                 while (child) {
    859                     if (child->isPositioned()) {
    860                         child = iterator.next();
     801                for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     802                    if (child->isPositioned())
    861803                        continue;
    862                     }
    863                    
     804
    864805                    if (firstChild) {
    865806                        firstChild = false;
    866                         child = iterator.next();
    867807                        continue;
    868808                    }
     
    870810                    offset += remainingSpace/totalChildren;
    871811                    remainingSpace -= (remainingSpace/totalChildren);
    872                     totalChildren--;
    873                     placeChild(child, child->x(), child->y()+offset);
    874                     child = iterator.next();
     812                    --totalChildren;
     813                    placeChild(child, child->x(), child->y() + offset);
    875814                }
    876815            }
    877816        } else {
    878817            if (style()->boxPack() == BCENTER)
    879                 offset += remainingSpace/2;
     818                offset += remainingSpace / 2;
    880819            else // END
    881820                offset += remainingSpace;
    882             child = iterator.first();
    883             while (child) {
    884                 if (child->isPositioned()) {
    885                     child = iterator.next();
     821            for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     822                if (child->isPositioned())
    886823                    continue;
    887                 }
    888                 placeChild(child, child->x(), child->y()+offset);
    889                 child = iterator.next();
     824                placeChild(child, child->x(), child->y() + offset);
    890825            }
    891826        }
     
    895830    // a height change, we revert our height back to the intrinsic height before returning.
    896831    if (heightSpecified)
    897         setHeight(oldHeight); 
     832        setHeight(oldHeight);
    898833}
    899834
     
    930865        if (child->isPositioned() || !child->style()->height().isAuto() || !child->isBlockFlow())
    931866            continue;
    932        
     867
    933868        RenderBlock* blockChild = toRenderBlock(child);
    934869        int lineCount = blockChild->lineCount();
    935870        if (lineCount <= numVisibleLines)
    936871            continue;
    937        
     872
    938873        int newHeight = blockChild->heightForLineCount(numVisibleLines);
    939874        if (newHeight == child->height())
    940875            continue;
    941        
     876
    942877        child->setChildNeedsLayout(true, false);
    943878        child->setOverrideSize(newHeight);
     
    952887
    953888        // Get the last line
    954         RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount-1);
     889        RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount - 1);
    955890        if (!lastLine)
    956891            continue;
    957892
    958         RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines-1);
     893        RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines - 1);
    959894        if (!lastVisibleLine)
    960895            continue;
     
    965900        const Font& font = style(numVisibleLines == 1)->font();
    966901
    967         // Get ellipsis width, and if the last child is an anchor, it will go after the ellipsis, so add in a space and the anchor width too 
     902        // Get ellipsis width, and if the last child is an anchor, it will go after the ellipsis, so add in a space and the anchor width too
    968903        int totalWidth;
    969904        InlineBox* anchorBox = lastLine->lastChild();
     
    978913        RenderBlock* destBlock = toRenderBlock(lastVisibleLine->renderer());
    979914        RenderBlock* srcBlock = toRenderBlock(lastLine->renderer());
    980        
     915
    981916        // FIXME: Directions of src/destBlock could be different from our direction and from one another.
    982917        if (!srcBlock->style()->isLeftToRightDirection())
     
    1018953    if (child->isPositioned() || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group)
    1019954        return 0;
    1020                        
     955
    1021956    if (expanding) {
    1022957        if (isHorizontal()) {
    1023958            // FIXME: For now just handle fixed values.
    1024             int maxW = INT_MAX;
    1025             int w = child->overrideWidth() - child->borderAndPaddingWidth();
    1026             if (!child->style()->maxWidth().isUndefined() &&
    1027                 child->style()->maxWidth().isFixed())
    1028                 maxW = child->style()->maxWidth().value();
     959            int maxWidth = INT_MAX;
     960            int width = child->overrideWidth() - child->borderAndPaddingWidth();
     961            if (!child->style()->maxWidth().isUndefined() && child->style()->maxWidth().isFixed())
     962                maxWidth = child->style()->maxWidth().value();
    1029963            else if (child->style()->maxWidth().type() == Intrinsic)
    1030                 maxW = child->maxPreferredLogicalWidth();
     964                maxWidth = child->maxPreferredLogicalWidth();
    1031965            else if (child->style()->maxWidth().type() == MinIntrinsic)
    1032                 maxW = child->minPreferredLogicalWidth();
    1033             if (maxW == INT_MAX)
    1034                 return maxW;
    1035             return max(0, maxW - w);
     966                maxWidth = child->minPreferredLogicalWidth();
     967            if (maxWidth == INT_MAX)
     968                return maxWidth;
     969            return max(0, maxWidth - width);
    1036970        } else {
    1037971            // FIXME: For now just handle fixed values.
    1038             int maxH = INT_MAX;
    1039             int h = child->overrideHeight() - child->borderAndPaddingHeight();
    1040             if (!child->style()->maxHeight().isUndefined() &&
    1041                 child->style()->maxHeight().isFixed())
    1042                 maxH = child->style()->maxHeight().value();
    1043             if (maxH == INT_MAX)
    1044                 return maxH;
    1045             return max(0, maxH - h);
     972            int maxHeight = INT_MAX;
     973            int height = child->overrideHeight() - child->borderAndPaddingHeight();
     974            if (!child->style()->maxHeight().isUndefined() && child->style()->maxHeight().isFixed())
     975                maxHeight = child->style()->maxHeight().value();
     976            if (maxHeight == INT_MAX)
     977                return maxHeight;
     978            return max(0, maxHeight - height);
    1046979        }
    1047980    }
     
    1049982    // FIXME: For now just handle fixed values.
    1050983    if (isHorizontal()) {
    1051         int minW = child->minPreferredLogicalWidth();
    1052         int w = child->overrideWidth() - child->borderAndPaddingWidth();
     984        int minWidth = child->minPreferredLogicalWidth();
     985        int width = child->overrideWidth() - child->borderAndPaddingWidth();
    1053986        if (child->style()->minWidth().isFixed())
    1054             minW = child->style()->minWidth().value();
     987            minWidth = child->style()->minWidth().value();
    1055988        else if (child->style()->minWidth().type() == Intrinsic)
    1056             minW = child->maxPreferredLogicalWidth();
     989            minWidth = child->maxPreferredLogicalWidth();
    1057990        else if (child->style()->minWidth().type() == MinIntrinsic)
    1058             minW = child->minPreferredLogicalWidth();
    1059            
    1060         int allowedShrinkage = min(0, minW - w);
     991            minWidth = child->minPreferredLogicalWidth();
     992
     993        int allowedShrinkage = min(0, minWidth - width);
    1061994        return allowedShrinkage;
    1062995    } else {
    1063996        if (child->style()->minHeight().isFixed()) {
    1064             int minH = child->style()->minHeight().value();
    1065             int h = child->overrideHeight() - child->borderAndPaddingHeight();
    1066             int allowedShrinkage = min(0, minH - h);
     997            int minHeight = child->style()->minHeight().value();
     998            int height = child->overrideHeight() - child->borderAndPaddingHeight();
     999            int allowedShrinkage = min(0, minHeight - height);
    10671000            return allowedShrinkage;
    10681001        }
    10691002    }
    1070    
     1003
    10711004    return 0;
    10721005}
Note: See TracChangeset for help on using the changeset viewer.