Changeset 92638 in webkit
- Timestamp:
- Aug 8, 2011 2:53:39 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r92631 r92638 1 2011-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 1 21 2011-08-08 Emil A Eklund <eae@chromium.org> 2 22 -
trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp
r92004 r92638 136 136 continue; 137 137 138 int margin = marginWidthForChild(child);138 LayoutUnit margin = marginWidthForChild(child); 139 139 m_minPreferredLogicalWidth += child->minPreferredLogicalWidth() + margin; 140 140 m_maxPreferredLogicalWidth += child->maxPreferredLogicalWidth() + margin; … … 149 149 continue; 150 150 151 int margin = marginWidthForChild(child);152 int width = child->minPreferredLogicalWidth() + margin;151 LayoutUnit margin = marginWidthForChild(child); 152 LayoutUnit width = child->minPreferredLogicalWidth() + margin; 153 153 m_minPreferredLogicalWidth = max(width, m_minPreferredLogicalWidth); 154 154 … … 192 192 } 193 193 194 int borderAndPadding = borderAndPaddingLogicalWidth();194 LayoutUnit borderAndPadding = borderAndPaddingLogicalWidth(); 195 195 m_minPreferredLogicalWidth += borderAndPadding; 196 196 m_maxPreferredLogicalWidth += borderAndPadding; … … 209 209 LayoutStateMaintainer statePusher(view(), this, IntSize(x(), y()), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode()); 210 210 211 IntSize previousSize = size();211 LayoutSize previousSize = size(); 212 212 213 213 computeLogicalWidth(); … … 240 240 layoutVerticalBox(relayoutChildren); 241 241 242 int oldClientAfterEdge = clientLogicalBottom();242 LayoutUnit oldClientAfterEdge = clientLogicalBottom(); 243 243 computeLogicalHeight(); 244 244 … … 315 315 void RenderDeprecatedFlexibleBox::layoutHorizontalBox(bool relayoutChildren) 316 316 { 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(); 320 320 bool heightSpecified = false; 321 int oldHeight = 0;322 323 int remainingSpace = 0;321 LayoutUnit oldHeight = 0; 322 323 LayoutUnit remainingSpace = 0; 324 324 325 325 … … 343 343 // out within the box. We have to do a layout first in order to determine 344 344 // our box's intrinsic height. 345 int maxAscent = 0, maxDescent = 0;345 LayoutUnit maxAscent = 0, maxDescent = 0; 346 346 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 347 347 // make sure we relayout children if we need it. … … 363 363 // Update our height and overflow height. 364 364 if (style()->boxAlign() == BBASELINE) { 365 int ascent = child->firstLineBoxBaseline();365 LayoutUnit ascent = child->firstLineBoxBaseline(); 366 366 if (ascent == -1) 367 367 ascent = child->height() + child->marginBottom(); 368 368 ascent += child->marginTop(); 369 int descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent;369 LayoutUnit descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent; 370 370 371 371 // Update our maximum ascent. … … 412 412 // fill the height of a containing box by default. 413 413 // Now do a layout. 414 int oldChildHeight = child->height();414 LayoutUnit oldChildHeight = child->height(); 415 415 child->computeLogicalHeight(); 416 416 if (oldChildHeight != child->height()) … … 424 424 // We can place the child now, using our value of box-align. 425 425 xPos += child->marginLeft(); 426 int childY = yPos;426 LayoutUnit childY = yPos; 427 427 switch (style()->boxAlign()) { 428 428 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); 430 430 break; 431 431 case BBASELINE: { … … 468 468 for (unsigned int i = start; i <= end && remainingSpace; i++) { 469 469 // Always start off by assuming the group can get all the remaining space. 470 int groupRemainingSpace = remainingSpace;470 LayoutUnit groupRemainingSpace = remainingSpace; 471 471 do { 472 472 // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width … … 474 474 // computing the allowed growth before an object hits its min/max width (and thus 475 475 // forces a totalFlex recomputation). 476 int groupRemainingSpaceAtBeginning = groupRemainingSpace;476 LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace; 477 477 float totalFlex = 0.0f; 478 478 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { … … 480 480 totalFlex += child->style()->boxFlex(); 481 481 } 482 int spaceAvailableThisPass = groupRemainingSpace;482 LayoutUnit spaceAvailableThisPass = groupRemainingSpace; 483 483 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 484 int allowedFlex = allowedChildFlex(child, expanding, i);484 LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i); 485 485 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())); 487 487 spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 488 488 } … … 499 499 for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) { 500 500 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)); 502 502 if (spaceAdd) { 503 503 child->setOverrideSize(LayoutSize(child->overrideWidth() + spaceAdd, 0)); … … 515 515 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 516 516 // 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; 518 518 for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 519 519 if (allowedChildFlex(child, expanding, i)) { … … 542 542 || (!style()->isLeftToRightDirection() && style()->boxPack() != BEND))) { 543 543 // Children must be repositioned. 544 int offset = 0;544 LayoutUnit offset = 0; 545 545 if (style()->boxPack() == BJUSTIFY) { 546 546 // Determine the total number of children. … … 570 570 --totalChildren; 571 571 572 placeChild(child, child->location() + IntSize(offset, 0));572 placeChild(child, child->location() + LayoutSize(offset, 0)); 573 573 } 574 574 } … … 582 582 continue; 583 583 584 placeChild(child, child->location() + IntSize(offset, 0));584 placeChild(child, child->location() + LayoutSize(offset, 0)); 585 585 } 586 586 } … … 595 595 void RenderDeprecatedFlexibleBox::layoutVerticalBox(bool relayoutChildren) 596 596 { 597 int yPos = borderTop() + paddingTop();598 int toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight();597 LayoutUnit yPos = borderTop() + paddingTop(); 598 LayoutUnit toAdd = borderBottom() + paddingBottom() + horizontalScrollbarHeight(); 599 599 bool heightSpecified = false; 600 int oldHeight = 0;601 602 int remainingSpace = 0;600 LayoutUnit oldHeight = 0; 601 602 LayoutUnit remainingSpace = 0; 603 603 604 604 FlexBoxIterator iterator(this); … … 622 622 do { 623 623 setHeight(borderTop() + paddingTop()); 624 int minHeight = height() + toAdd;624 LayoutUnit minHeight = height() + toAdd; 625 625 626 626 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { … … 654 654 655 655 // We can place the child now, using our value of box-align. 656 int childX = borderLeft() + paddingLeft();656 LayoutUnit childX = borderLeft() + paddingLeft(); 657 657 switch (style()->boxAlign()) { 658 658 case BCENTER: 659 659 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); 661 661 break; 662 662 case BEND: … … 675 675 676 676 // Place the child. 677 placeChild(child, IntPoint(childX, height()));677 placeChild(child, LayoutPoint(childX, height())); 678 678 setHeight(height() + child->height() + child->marginBottom()); 679 679 } … … 714 714 for (unsigned int i = start; i <= end && remainingSpace; i++) { 715 715 // Always start off by assuming the group can get all the remaining space. 716 int groupRemainingSpace = remainingSpace;716 LayoutUnit groupRemainingSpace = remainingSpace; 717 717 do { 718 718 // Flexing consists of multiple passes, since we have to change ratios every time an object hits its max/min-width … … 720 720 // computing the allowed growth before an object hits its min/max width (and thus 721 721 // forces a totalFlex recomputation). 722 int groupRemainingSpaceAtBeginning = groupRemainingSpace;722 LayoutUnit groupRemainingSpaceAtBeginning = groupRemainingSpace; 723 723 float totalFlex = 0.0f; 724 724 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { … … 726 726 totalFlex += child->style()->boxFlex(); 727 727 } 728 int spaceAvailableThisPass = groupRemainingSpace;728 LayoutUnit spaceAvailableThisPass = groupRemainingSpace; 729 729 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 730 int allowedFlex = allowedChildFlex(child, expanding, i);730 LayoutUnit allowedFlex = allowedChildFlex(child, expanding, i); 731 731 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())); 733 733 spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 734 734 } … … 745 745 for (RenderBox* child = iterator.first(); child && spaceAvailableThisPass && totalFlex; child = iterator.next()) { 746 746 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)); 748 748 if (spaceAdd) { 749 749 child->setOverrideSize(LayoutSize(0, child->overrideHeight() + spaceAdd)); … … 761 761 if (groupRemainingSpace == groupRemainingSpaceAtBeginning) { 762 762 // 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; 764 764 for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 765 765 if (allowedChildFlex(child, expanding, i)) { … … 785 785 if (style()->boxPack() != BSTART && remainingSpace > 0) { 786 786 // Children must be repositioned. 787 int offset = 0;787 LayoutUnit offset = 0; 788 788 if (style()->boxPack() == BJUSTIFY) { 789 789 // Determine the total number of children. … … 813 813 remainingSpace -= (remainingSpace/totalChildren); 814 814 --totalChildren; 815 placeChild(child, child->location() + IntSize(0, offset));815 placeChild(child, child->location() + LayoutSize(0, offset)); 816 816 } 817 817 } … … 824 824 if (child->isPositioned()) 825 825 continue; 826 placeChild(child, child->location() + IntSize(0, offset));826 placeChild(child, child->location() + LayoutSize(0, offset)); 827 827 } 828 828 } … … 937 937 } 938 938 939 void RenderDeprecatedFlexibleBox::placeChild(RenderBox* child, const IntPoint& location)940 { 941 IntRect oldRect = child->frameRect();939 void RenderDeprecatedFlexibleBox::placeChild(RenderBox* child, const LayoutPoint& location) 940 { 941 LayoutRect oldRect = child->frameRect(); 942 942 943 943 // Place the child. … … 951 951 } 952 952 953 int RenderDeprecatedFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group)953 LayoutUnit RenderDeprecatedFlexibleBox::allowedChildFlex(RenderBox* child, bool expanding, unsigned int group) 954 954 { 955 955 if (child->isPositioned() || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group) … … 959 959 if (isHorizontal()) { 960 960 // 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(); 963 963 if (!child->style()->maxWidth().isUndefined() && child->style()->maxWidth().isFixed()) 964 964 maxWidth = child->style()->maxWidth().value(); … … 967 967 else if (child->style()->maxWidth().type() == MinIntrinsic) 968 968 maxWidth = child->minPreferredLogicalWidth(); 969 if (maxWidth == INT_MAX)969 if (maxWidth == numeric_limits<LayoutUnit>::max()) 970 970 return maxWidth; 971 return max (0, maxWidth - width);971 return max<LayoutUnit>(0, maxWidth - width); 972 972 } else { 973 973 // 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(); 976 976 if (!child->style()->maxHeight().isUndefined() && child->style()->maxHeight().isFixed()) 977 977 maxHeight = child->style()->maxHeight().value(); 978 if (maxHeight == INT_MAX)978 if (maxHeight == numeric_limits<LayoutUnit>::max()) 979 979 return maxHeight; 980 return max (0, maxHeight - height);980 return max<LayoutUnit>(0, maxHeight - height); 981 981 } 982 982 } … … 984 984 // FIXME: For now just handle fixed values. 985 985 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(); 988 988 if (child->style()->minWidth().isFixed()) 989 989 minWidth = child->style()->minWidth().value(); … … 993 993 minWidth = child->minPreferredLogicalWidth(); 994 994 995 int allowedShrinkage = min(0, minWidth - width);995 LayoutUnit allowedShrinkage = min<LayoutUnit>(0, minWidth - width); 996 996 return allowedShrinkage; 997 997 } else { 998 998 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); 1002 1002 return allowedShrinkage; 1003 1003 } -
trunk/Source/WebCore/rendering/RenderDeprecatedFlexibleBox.h
r92004 r92638 51 51 virtual bool isStretchingChildren() const { return m_stretchingChildren; } 52 52 53 void placeChild(RenderBox* child, const IntPoint& location);53 void placeChild(RenderBox* child, const LayoutPoint& location); 54 54 55 55 protected: 56 int allowedChildFlex(RenderBox* child, bool expanding, unsigned group);56 LayoutUnit allowedChildFlex(RenderBox* child, bool expanding, unsigned group); 57 57 58 58 bool hasMultipleLines() const { return style()->boxLines() == MULTIPLE; }
Note: See TracChangeset
for help on using the changeset viewer.