Changeset 92638 in webkit


Ignore:
Timestamp:
Aug 8, 2011 2:53:39 PM (13 years ago)
Author:
eae@chromium.org
Message:

Switch legacy flexbox to to new layout types
https://bugs.webkit.org/show_bug.cgi?id=65340

Reviewed by Eric Seidel.

No new tests, no new functionality.

  • rendering/RenderDeprecatedFlexibleBox.cpp:

(WebCore::RenderDeprecatedFlexibleBox::calcHorizontalPrefWidths):
(WebCore::RenderDeprecatedFlexibleBox::calcVerticalPrefWidths):
(WebCore::RenderDeprecatedFlexibleBox::computePreferredLogicalWidths):
(WebCore::RenderDeprecatedFlexibleBox::layoutBlock):
(WebCore::RenderDeprecatedFlexibleBox::layoutHorizontalBox):
(WebCore::RenderDeprecatedFlexibleBox::layoutVerticalBox):
(WebCore::RenderDeprecatedFlexibleBox::placeChild):
(WebCore::RenderDeprecatedFlexibleBox::allowedChildFlex):

  • rendering/RenderDeprecatedFlexibleBox.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r92631 r92638  
     12011-08-08  Emil A Eklund  <eae@chromium.org>
     2
     3        Switch legacy flexbox to to new layout types
     4        https://bugs.webkit.org/show_bug.cgi?id=65340
     5
     6        Reviewed by Eric Seidel.
     7
     8        No new tests, no new functionality.
     9
     10        * rendering/RenderDeprecatedFlexibleBox.cpp:
     11        (WebCore::RenderDeprecatedFlexibleBox::calcHorizontalPrefWidths):
     12        (WebCore::RenderDeprecatedFlexibleBox::calcVerticalPrefWidths):
     13        (WebCore::RenderDeprecatedFlexibleBox::computePreferredLogicalWidths):
     14        (WebCore::RenderDeprecatedFlexibleBox::layoutBlock):
     15        (WebCore::RenderDeprecatedFlexibleBox::layoutHorizontalBox):
     16        (WebCore::RenderDeprecatedFlexibleBox::layoutVerticalBox):
     17        (WebCore::RenderDeprecatedFlexibleBox::placeChild):
     18        (WebCore::RenderDeprecatedFlexibleBox::allowedChildFlex):
     19        * rendering/RenderDeprecatedFlexibleBox.h:
     20
    1212011-08-08  Emil A Eklund  <eae@chromium.org>
    222
  • trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp

    r92004 r92638  
    136136            continue;
    137137
    138         int margin = marginWidthForChild(child);
     138        LayoutUnit margin = marginWidthForChild(child);
    139139        m_minPreferredLogicalWidth += child->minPreferredLogicalWidth() + margin;
    140140        m_maxPreferredLogicalWidth += child->maxPreferredLogicalWidth() + margin;
     
    149149            continue;
    150150
    151         int margin = marginWidthForChild(child);
    152         int width = child->minPreferredLogicalWidth() + margin;
     151        LayoutUnit margin = marginWidthForChild(child);
     152        LayoutUnit width = child->minPreferredLogicalWidth() + margin;
    153153        m_minPreferredLogicalWidth = max(width, m_minPreferredLogicalWidth);
    154154
     
    192192    }
    193193
    194     int borderAndPadding = borderAndPaddingLogicalWidth();
     194    LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth();
    195195    m_minPreferredLogicalWidth += borderAndPadding;
    196196    m_maxPreferredLogicalWidth += borderAndPadding;
     
    209209    LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y()), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode());
    210210
    211     IntSize previousSize = size();
     211    LayoutSize previousSize = size();
    212212
    213213    computeLogicalWidth();
     
    240240        layoutVerticalBox(relayoutChildren);
    241241
    242     int oldClientAfterEdge = clientLogicalBottom();
     242    LayoutUnit oldClientAfterEdge = clientLogicalBottom();
    243243    computeLogicalHeight();
    244244
     
    315315void RenderDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren)
    316316{
    317     int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
    318     int yPos = borderTop() + paddingTop();
    319     int xPos = borderLeft() + paddingLeft();
     317    LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
     318    LayoutUnit yPos = borderTop() + paddingTop();
     319    LayoutUnit xPos = borderLeft() + paddingLeft();
    320320    bool heightSpecified = false;
    321     int oldHeight = 0;
    322 
    323     int remainingSpace = 0;
     321    LayoutUnit oldHeight = 0;
     322
     323    LayoutUnit remainingSpace = 0;
    324324
    325325
     
    343343        // out within the box.  We have to do a layout first in order to determine
    344344        // our box's intrinsic height.
    345         int maxAscent = 0, maxDescent = 0;
     345        LayoutUnit maxAscent = 0, maxDescent = 0;
    346346        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    347347            // make sure we relayout children if we need it.
     
    363363            // Update our height and overflow height.
    364364            if (style()->boxAlign() == BBASELINE) {
    365                 int ascent = child->firstLineBoxBaseline();
     365                LayoutUnit ascent = child->firstLineBoxBaseline();
    366366                if (ascent == -1)
    367367                    ascent = child->height() + child->marginBottom();
    368368                ascent += child->marginTop();
    369                 int descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent;
     369                LayoutUnit descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent;
    370370
    371371                // Update our maximum ascent.
     
    412412            // fill the height of a containing box by default.
    413413            // Now do a layout.
    414             int oldChildHeight = child->height();
     414            LayoutUnit oldChildHeight = child->height();
    415415            child->computeLogicalHeight();
    416416            if (oldChildHeight != child->height())
     
    424424            // We can place the child now, using our value of box-align.
    425425            xPos += child->marginLeft();
    426             int childY = yPos;
     426            LayoutUnit childY = yPos;
    427427            switch (style()->boxAlign()) {
    428428                case BCENTER:
    429                     childY += child->marginTop() + max(0, (contentHeight() - (child->height() + child->marginTop() + child->marginBottom())) / 2);
     429                    childY += child->marginTop() + max<LayoutUnit>(0, (contentHeight() - (child->height() + child->marginTop() + child->marginBottom())) / 2);
    430430                    break;
    431431                case BBASELINE: {
     
    468468            for (unsigned int i = start; i <= end && remainingSpace; i++) {
    469469                // Always start off by assuming the group can get all the remaining space.
    470                 int groupRemainingSpace = remainingSpace;
     470                LayoutUnit groupRemainingSpace = remainingSpace;
    471471                do {
    472472                    // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width
     
    474474                    // computing the allowed growth before an object hits its min/max width (and thus
    475475                    // forces a totalFlex recomputation).
    476                     int groupRemainingSpaceAtBeginning = groupRemainingSpace;
     476                    LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace;
    477477                    float totalFlex = 0.0f;
    478478                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     
    480480                            totalFlex += child->style()->boxFlex();
    481481                    }
    482                     int spaceAvailableThisPass = groupRemainingSpace;
     482                    LayoutUnit spaceAvailableThisPass = groupRemainingSpace;
    483483                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    484                         int allowedFlex = allowedChildFlex(child, expanding, i);
     484                        LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i);
    485485                        if (allowedFlex) {
    486                             int projectedFlex = (allowedFlex == INT_MAX) ? allowedFlex : (int)(allowedFlex * (totalFlex / child->style()->boxFlex()));
     486                            LayoutUnit projectedFlex = (allowedFlex == numeric_limits<LayoutUnit>::max()) ? allowedFlex : static_cast<LayoutUnit>(allowedFlex * (totalFlex / child->style()->boxFlex()));
    487487                            spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex);
    488488                        }
     
    499499                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
    500500                        if (allowedChildFlex(child, expanding, i)) {
    501                             int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex));
     501                            LayoutUnit spaceAdd = static_cast<LayoutUnit>(spaceAvailableThisPass * (child->style()->boxFlex() / totalFlex));
    502502                            if (spaceAdd) {
    503503                                child->setOverrideSize(LayoutSize(child->overrideWidth() + spaceAdd, 0));
     
    515515                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
    516516                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
    517                         int spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
     517                        LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
    518518                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
    519519                            if (allowedChildFlex(child, expanding, i)) {
     
    542542        || (!style()->isLeftToRightDirection() && style()->boxPack() != BEND))) {
    543543        // Children must be repositioned.
    544         int offset = 0;
     544        LayoutUnit offset = 0;
    545545        if (style()->boxPack() == BJUSTIFY) {
    546546            // Determine the total number of children.
     
    570570                    --totalChildren;
    571571
    572                     placeChild(child, child->location() + IntSize(offset, 0));
     572                    placeChild(child, child->location() + LayoutSize(offset, 0));
    573573                }
    574574            }
     
    582582                    continue;
    583583
    584                 placeChild(child, child->location() + IntSize(offset, 0));
     584                placeChild(child, child->location() + LayoutSize(offset, 0));
    585585            }
    586586        }
     
    595595void RenderDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren)
    596596{
    597     int yPos = borderTop() + paddingTop();
    598     int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
     597    LayoutUnit yPos = borderTop() + paddingTop();
     598    LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();
    599599    bool heightSpecified = false;
    600     int oldHeight = 0;
    601 
    602     int remainingSpace = 0;
     600    LayoutUnit oldHeight = 0;
     601
     602    LayoutUnit remainingSpace = 0;
    603603
    604604    FlexBoxIterator iterator(this);
     
    622622    do {
    623623        setHeight(borderTop() + paddingTop());
    624         int minHeight = height() + toAdd;
     624        LayoutUnit minHeight = height() + toAdd;
    625625
    626626        for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     
    654654
    655655            // We can place the child now, using our value of box-align.
    656             int childX = borderLeft() + paddingLeft();
     656            LayoutUnit childX = borderLeft() + paddingLeft();
    657657            switch (style()->boxAlign()) {
    658658                case BCENTER:
    659659                case BBASELINE: // Baseline just maps to center for vertical boxes
    660                     childX += child->marginLeft() + max(0, (contentWidth() - (child->width() + child->marginLeft() + child->marginRight())) / 2);
     660                    childX += child->marginLeft() + max<LayoutUnit>(0, (contentWidth() - (child->width() + child->marginLeft() + child->marginRight())) / 2);
    661661                    break;
    662662                case BEND:
     
    675675
    676676            // Place the child.
    677             placeChild(child, IntPoint(childX, height()));
     677            placeChild(child, LayoutPoint(childX, height()));
    678678            setHeight(height() + child->height() + child->marginBottom());
    679679        }
     
    714714            for (unsigned int i = start; i <= end && remainingSpace; i++) {
    715715                // Always start off by assuming the group can get all the remaining space.
    716                 int groupRemainingSpace = remainingSpace;
     716                LayoutUnit groupRemainingSpace = remainingSpace;
    717717                do {
    718718                    // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width
     
    720720                    // computing the allowed growth before an object hits its min/max width (and thus
    721721                    // forces a totalFlex recomputation).
    722                     int groupRemainingSpaceAtBeginning = groupRemainingSpace;
     722                    LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace;
    723723                    float totalFlex = 0.0f;
    724724                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
     
    726726                            totalFlex += child->style()->boxFlex();
    727727                    }
    728                     int spaceAvailableThisPass = groupRemainingSpace;
     728                    LayoutUnit spaceAvailableThisPass = groupRemainingSpace;
    729729                    for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
    730                         int allowedFlex = allowedChildFlex(child, expanding, i);
     730                        LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i);
    731731                        if (allowedFlex) {
    732                             int projectedFlex = (allowedFlex == INT_MAX) ? allowedFlex : (int)(allowedFlex * (totalFlex / child->style()->boxFlex()));
     732                            LayoutUnit projectedFlex = (allowedFlex == numeric_limits<LayoutUnit>::max()) ? allowedFlex : static_cast<LayoutUnit>(allowedFlex * (totalFlex / child->style()->boxFlex()));
    733733                            spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex);
    734734                        }
     
    745745                    for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) {
    746746                        if (allowedChildFlex(child, expanding, i)) {
    747                             int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex));
     747                            LayoutUnit spaceAdd = static_cast<LayoutUnit>(spaceAvailableThisPass * (child->style()->boxFlex() / totalFlex));
    748748                            if (spaceAdd) {
    749749                                child->setOverrideSize(LayoutSize(0, child->overrideHeight() + spaceAdd));
     
    761761                    if (groupRemainingSpace == groupRemainingSpaceAtBeginning) {
    762762                        // This is not advancing, avoid getting stuck by distributing the remaining pixels.
    763                         int spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
     763                        LayoutUnit spaceAdd = groupRemainingSpace > 0 ? 1 : -1;
    764764                        for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) {
    765765                            if (allowedChildFlex(child, expanding, i)) {
     
    785785    if (style()->boxPack() != BSTART && remainingSpace > 0) {
    786786        // Children must be repositioned.
    787         int offset = 0;
     787        LayoutUnit offset = 0;
    788788        if (style()->boxPack() == BJUSTIFY) {
    789789            // Determine the total number of children.
     
    813813                    remainingSpace -= (remainingSpace/totalChildren);
    814814                    --totalChildren;
    815                     placeChild(child, child->location() + IntSize(0, offset));
     815                    placeChild(child, child->location() + LayoutSize(0, offset));
    816816                }
    817817            }
     
    824824                if (child->isPositioned())
    825825                    continue;
    826                 placeChild(child, child->location() + IntSize(0, offset));
     826                placeChild(child, child->location() + LayoutSize(0, offset));
    827827            }
    828828        }
     
    937937}
    938938
    939 void RenderDeprecatedFlexibleBox::placeChild(RenderBox* child, const IntPoint& location)
    940 {
    941     IntRect oldRect = child->frameRect();
     939void RenderDeprecatedFlexibleBox::placeChild(RenderBox* child, const LayoutPoint& location)
     940{
     941    LayoutRect oldRect = child->frameRect();
    942942
    943943    // Place the child.
     
    951951}
    952952
    953 int RenderDeprecatedFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group)
     953LayoutUnit RenderDeprecatedFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group)
    954954{
    955955    if (child->isPositioned() || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group)
     
    959959        if (isHorizontal()) {
    960960            // FIXME: For now just handle fixed values.
    961             int maxWidth = INT_MAX;
    962             int width = child->overrideWidth() - child->borderAndPaddingWidth();
     961            LayoutUnit maxWidth = numeric_limits<LayoutUnit>::max();
     962            LayoutUnit width = child->overrideWidth() - child->borderAndPaddingWidth();
    963963            if (!child->style()->maxWidth().isUndefined() && child->style()->maxWidth().isFixed())
    964964                maxWidth = child->style()->maxWidth().value();
     
    967967            else if (child->style()->maxWidth().type() == MinIntrinsic)
    968968                maxWidth = child->minPreferredLogicalWidth();
    969             if (maxWidth == INT_MAX)
     969            if (maxWidth == numeric_limits<LayoutUnit>::max())
    970970                return maxWidth;
    971             return max(0, maxWidth - width);
     971            return max<LayoutUnit>(0, maxWidth - width);
    972972        } else {
    973973            // FIXME: For now just handle fixed values.
    974             int maxHeight = INT_MAX;
    975             int height = child->overrideHeight() - child->borderAndPaddingHeight();
     974            LayoutUnit maxHeight = numeric_limits<LayoutUnit>::max();
     975            LayoutUnit height = child->overrideHeight() - child->borderAndPaddingHeight();
    976976            if (!child->style()->maxHeight().isUndefined() && child->style()->maxHeight().isFixed())
    977977                maxHeight = child->style()->maxHeight().value();
    978             if (maxHeight == INT_MAX)
     978            if (maxHeight == numeric_limits<LayoutUnit>::max())
    979979                return maxHeight;
    980             return max(0, maxHeight - height);
     980            return max<LayoutUnit>(0, maxHeight - height);
    981981        }
    982982    }
     
    984984    // FIXME: For now just handle fixed values.
    985985    if (isHorizontal()) {
    986         int minWidth = child->minPreferredLogicalWidth();
    987         int width = child->overrideWidth() - child->borderAndPaddingWidth();
     986        LayoutUnit minWidth = child->minPreferredLogicalWidth();
     987        LayoutUnit width = child->overrideWidth() - child->borderAndPaddingWidth();
    988988        if (child->style()->minWidth().isFixed())
    989989            minWidth = child->style()->minWidth().value();
     
    993993            minWidth = child->minPreferredLogicalWidth();
    994994
    995         int allowedShrinkage = min(0, minWidth - width);
     995        LayoutUnit allowedShrinkage = min<LayoutUnit>(0, minWidth - width);
    996996        return allowedShrinkage;
    997997    } else {
    998998        if (child->style()->minHeight().isFixed()) {
    999             int minHeight = child->style()->minHeight().value();
    1000             int height = child->overrideHeight() - child->borderAndPaddingHeight();
    1001             int allowedShrinkage = min(0, minHeight - height);
     999            LayoutUnit minHeight = child->style()->minHeight().value();
     1000            LayoutUnit height = child->overrideHeight() - child->borderAndPaddingHeight();
     1001            LayoutUnit allowedShrinkage = min<LayoutUnit>(0, minHeight - height);
    10021002            return allowedShrinkage;
    10031003        }
  • trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h

    r92004 r92638  
    5151    virtual bool isStretchingChildren() const { return m_stretchingChildren; }
    5252
    53     void placeChild(RenderBox* child, const IntPoint& location);
     53    void placeChild(RenderBox* child, const LayoutPoint& location);
    5454
    5555protected:
    56     int allowedChildFlex(RenderBox* child, bool expanding, unsigned group);
     56    LayoutUnit allowedChildFlex(RenderBox* child, bool expanding, unsigned group);
    5757
    5858    bool hasMultipleLines() const { return style()->boxLines() == MULTIPLE; }
Note: See TracChangeset for help on using the changeset viewer.