Changeset 86098 in webkit
- Timestamp:
- May 9, 2011 3:53:20 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r86093 r86098 1 2011-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 1 28 2011-05-09 Eric Seidel <eric@webkit.org> 2 29 -
trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp
r85973 r86098 39 39 public: 40 40 FlexBoxIterator(RenderFlexibleBox* parent) 41 : m_box(parent) 42 , m_lastOrdinal(1) 41 43 { 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; 45 46 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) { 49 49 // 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(); 51 51 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(); 54 54 child = child->nextSiblingBox(); 55 55 } 56 56 } 57 57 58 58 reset(); 59 59 } … … 61 61 void reset() 62 62 { 63 current= 0;64 currentOrdinal = forward ? 0 : lastOrdinal+1;63 m_currentChild = 0; 64 m_currentOrdinal = m_forward ? 0 : m_lastOrdinal + 1; 65 65 } 66 66 … … 70 70 return next(); 71 71 } 72 72 73 73 RenderBox* next() 74 74 { 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) 80 80 return 0; 81 current =box->firstChildBox();81 m_currentChild = m_box->firstChildBox(); 82 82 } else { 83 currentOrdinal--;84 if ( currentOrdinal == 0)83 --m_currentOrdinal; 84 if (!m_currentOrdinal) 85 85 return 0; 86 current =box->lastChildBox();86 m_currentChild = m_box->lastChildBox(); 87 87 } 88 88 } 89 89 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; 96 96 } 97 97 98 98 private: 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; 104 104 }; 105 105 106 106 RenderFlexibleBox::RenderFlexibleBox(Node* node) 107 :RenderBlock(node)107 : RenderBlock(node) 108 108 { 109 109 setChildrenInline(false); // All of our children must be block-level … … 115 115 } 116 116 117 static 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 117 132 void RenderFlexibleBox::calcHorizontalPrefWidths() 118 133 { 119 134 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) { 120 // positioned children don't affect the minmaxwidth135 // Positioned children and collapsed children don't affect the min/max width. 121 136 if (child->isPositioned() || child->style()->visibility() == COLLAPSE) 122 137 continue; 123 138 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); 136 140 m_minPreferredLogicalWidth += child->minPreferredLogicalWidth() + margin; 137 141 m_maxPreferredLogicalWidth += child->maxPreferredLogicalWidth() + margin; 138 } 142 } 139 143 } 140 144 … … 142 146 { 143 147 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. 145 149 if (child->isPositioned() || child->style()->visibility() == COLLAPSE) 146 150 continue; 147 151 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 } 165 159 } 166 160 … … 193 187 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->minWidth().value())); 194 188 } 195 189 196 190 if (style()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) { 197 191 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style()->maxWidth().value())); … … 218 212 int previousWidth = width(); 219 213 int previousHeight = height(); 220 214 221 215 computeLogicalWidth(); 222 216 computeLogicalHeight(); 223 217 224 218 m_overflow.clear(); 225 219 … … 273 267 setMaxMarginAfterValues(0, 0); 274 268 } 275 269 276 270 computeOverflow(oldClientAfterEdge); 277 271 … … 290 284 // Repaint with our new bounds if they are different from our old bounds. 291 285 repainter.repaintAfterLayout(); 292 286 293 287 setNeedsLayout(false); 294 288 } … … 297 291 static void gatherFlexChildrenInfo(FlexBoxIterator& iterator, bool relayoutChildren, unsigned int& highestFlexGroup, unsigned int& lowestFlexGroup, bool& haveFlex) 298 292 { 299 RenderBox* child = iterator.first(); 300 while (child) { 293 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 301 294 // Check to see if this child flexes. 302 295 if (!child->isPositioned() && child->style()->boxFlex() > 0.0f) { … … 315 308 highestFlexGroup = flexGroup; 316 309 } 317 child = iterator.next();318 310 } 319 311 } … … 336 328 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex); 337 329 338 RenderBox* child;339 340 330 RenderBlock::startDelayUpdateScrollInfo(); 341 331 … … 347 337 348 338 xPos = borderLeft() + paddingLeft(); 349 339 350 340 // Our first pass is done without flexing. We simply lay the children 351 341 // out within the box. We have to do a layout first in order to determine 352 342 // our box's intrinsic height. 353 343 int maxAscent = 0, maxDescent = 0; 354 child = iterator.first(); 355 while (child) { 344 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 356 345 // make sure we relayout children if we need it. 357 346 if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))) 358 347 child->setChildNeedsLayout(true, false); 359 360 if (child->isPositioned()) { 361 child = iterator.next(); 348 349 if (child->isPositioned()) 362 350 continue; 363 } 364 351 365 352 // Compute the child's vertical margins. 366 353 child->computeBlockDirectionMargins(this); 367 354 368 355 if (!child->needsLayout()) 369 356 child->markForPaginationRelayoutIfNeeded(); … … 371 358 // Now do the layout. 372 359 child->layoutIfNeeded(); 373 360 374 361 // Update our height and overflow height. 375 362 if (style()->boxAlign() == BBASELINE) { … … 379 366 ascent += child->marginTop(); 380 367 int descent = (child->marginTop() + child->height() + child->marginBottom()) - ascent; 381 368 382 369 // Update our maximum ascent. 383 370 maxAscent = max(maxAscent, ascent); 384 371 385 372 // Update our maximum descent. 386 373 maxDescent = max(maxDescent, descent); 387 374 388 375 // Now update our height. 389 376 setHeight(max(yPos + maxAscent + maxDescent, height())); … … 391 378 else 392 379 setHeight(max(height(), yPos + child->marginTop() + child->height() + child->marginBottom())); 393 394 child = iterator.next(); 395 } 396 380 } 381 397 382 if (!iterator.first() && hasLineIfEmpty()) 398 383 setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); 399 384 400 385 setHeight(height() + toAdd); 401 386 402 387 oldHeight = height(); 403 388 computeLogicalHeight(); … … 406 391 if (oldHeight != height()) 407 392 heightSpecified = true; 408 393 409 394 // Now that our height is actually known, we can place our boxes. 410 395 m_stretchingChildren = (style()->boxAlign() == BSTRETCH); 411 child = iterator.first(); 412 while (child) { 396 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 413 397 if (child->isPositioned()) { 414 398 child->containingBlock()->insertPositionedObject(child); … … 420 404 child->setChildNeedsLayout(true, false); 421 405 } 422 child = iterator.next();423 406 continue; 424 407 } 425 408 426 409 // We need to see if this child's height has changed, since we make block elements 427 410 // fill the height of a containing box by default. … … 431 414 if (oldChildHeight != child->height()) 432 415 child->setChildNeedsLayout(true, false); 433 416 434 417 if (!child->needsLayout()) 435 418 child->markForPaginationRelayoutIfNeeded(); 436 419 437 420 child->layoutIfNeeded(); 438 421 439 422 // We can place the child now, using our value of box-align. 440 423 xPos += child->marginLeft(); … … 442 425 switch (style()->boxAlign()) { 443 426 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); 445 428 break; 446 429 case BBASELINE: { … … 461 444 462 445 placeChild(child, xPos, childY); 463 446 464 447 xPos += child->width() + child->marginRight(); 465 466 child = iterator.next();467 448 } 468 449 469 450 remainingSpace = borderLeft() + paddingLeft() + contentWidth() - xPos; 470 451 471 452 m_stretchingChildren = false; 472 453 if (m_flexingChildren) … … 493 474 int groupRemainingSpaceAtBeginning = groupRemainingSpace; 494 475 float totalFlex = 0.0f; 495 child = iterator.first(); 496 while (child) { 476 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 497 477 if (allowedChildFlex(child, expanding, i)) 498 478 totalFlex += child->style()->boxFlex(); 499 child = iterator.next(); 500 } 501 child = iterator.first(); 479 } 502 480 int spaceAvailableThisPass = groupRemainingSpace; 503 while (child) {481 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 504 482 int allowedFlex = allowedChildFlex(child, expanding, i); 505 483 if (allowedFlex) { … … 507 485 spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 508 486 } 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. 513 490 if (!spaceAvailableThisPass || totalFlex == 0.0f) { 514 491 // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group. … … 518 495 519 496 // 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()) { 522 498 if (allowedChildFlex(child, expanding, i)) { 523 499 int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex)); … … 531 507 remainingSpace -= spaceAdd; 532 508 groupRemainingSpace -= spaceAdd; 533 509 534 510 totalFlex -= child->style()->boxFlex(); 535 511 } 536 child = iterator.next();537 512 } 538 513 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. 541 515 int spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 542 while (child && groupRemainingSpace) {516 for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 543 517 if (allowedChildFlex(child, expanding, i)) { 544 518 child->setOverrideSize(child->overrideWidth() + spaceAdd); … … 548 522 groupRemainingSpace -= spaceAdd; 549 523 } 550 child = iterator.next();551 524 } 552 525 } … … 571 544 // Determine the total number of children. 572 545 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()) 577 548 continue; 578 } 579 totalChildren++; 580 child = iterator.next(); 549 ++totalChildren; 581 550 } 582 551 … … 584 553 // justification level. 585 554 if (totalChildren > 1) { 586 totalChildren--;555 --totalChildren; 587 556 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()) 592 559 continue; 593 }594 560 595 561 if (firstChild) { 596 562 firstChild = false; 597 child = iterator.next();598 563 continue; 599 564 } … … 601 566 offset += remainingSpace/totalChildren; 602 567 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()); 607 571 } 608 572 } 609 573 } else { 610 574 if (style()->boxPack() == BCENTER) 611 offset += remainingSpace /2;575 offset += remainingSpace / 2; 612 576 else // END for LTR, START for RTL 613 577 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()) 618 580 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 626 587 // So that the computeLogicalHeight in layoutBlock() knows to relayout positioned objects because of 627 588 // a height change, we revert our height back to the intrinsic height before returning. … … 644 605 bool haveFlex = false; 645 606 gatherFlexChildrenInfo(iterator, relayoutChildren, highestFlexGroup, lowestFlexGroup, haveFlex); 646 647 RenderBox* child;648 607 649 608 // We confine the line clamp ugliness to vertical flexible boxes (thus keeping it out of … … 663 622 int minHeight = height() + toAdd; 664 623 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. 668 626 if (!haveLineClamp && (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())))) 669 627 child->setChildNeedsLayout(true, false); 670 628 671 629 if (child->isPositioned()) { 672 630 child->containingBlock()->insertPositionedObject(child); … … 678 636 child->setChildNeedsLayout(true, false); 679 637 } 680 child = iterator.next();681 638 continue; 682 } 683 639 } 640 684 641 // Compute the child's vertical margins. 685 642 child->computeBlockDirectionMargins(this); 686 643 687 644 // Add in the child's marginTop to our height. 688 645 setHeight(height() + child->marginTop()); 689 646 690 647 if (!child->needsLayout()) 691 648 child->markForPaginationRelayoutIfNeeded(); … … 693 650 // Now do a layout. 694 651 child->layoutIfNeeded(); 695 652 696 653 // We can place the child now, using our value of box-align. 697 654 int childX = borderLeft() + paddingLeft(); … … 699 656 case BCENTER: 700 657 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); 702 659 break; 703 660 case BEND: … … 714 671 break; 715 672 } 716 673 717 674 // Place the child. 718 675 placeChild(child, childX, height()); 719 676 setHeight(height() + child->height() + child->marginBottom()); 720 721 child = iterator.next();722 677 } 723 678 724 679 yPos = height(); 725 680 726 681 if (!iterator.first() && hasLineIfEmpty()) 727 682 setHeight(height() + lineHeight(true, style()->isHorizontalWritingMode() ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes)); 728 683 729 684 setHeight(height() + toAdd); 730 685 … … 741 696 742 697 remainingSpace = borderTop() + paddingTop() + contentHeight() - yPos; 743 698 744 699 if (m_flexingChildren) 745 700 haveFlex = false; // We're done. … … 765 720 int groupRemainingSpaceAtBeginning = groupRemainingSpace; 766 721 float totalFlex = 0.0f; 767 child = iterator.first(); 768 while (child) { 722 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 769 723 if (allowedChildFlex(child, expanding, i)) 770 724 totalFlex += child->style()->boxFlex(); 771 child = iterator.next(); 772 } 773 child = iterator.first(); 725 } 774 726 int spaceAvailableThisPass = groupRemainingSpace; 775 while (child) {727 for (RenderBox* child = iterator.first(); child; child = iterator.next()) { 776 728 int allowedFlex = allowedChildFlex(child, expanding, i); 777 729 if (allowedFlex) { … … 779 731 spaceAvailableThisPass = expanding ? min(spaceAvailableThisPass, projectedFlex) : max(spaceAvailableThisPass, projectedFlex); 780 732 } 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. 785 736 if (!spaceAvailableThisPass || totalFlex == 0.0f) { 786 737 // If we just couldn't grow/shrink any more, then it's time to transition to the next flex group. … … 788 739 continue; 789 740 } 790 741 791 742 // 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()) { 794 744 if (allowedChildFlex(child, expanding, i)) { 795 745 int spaceAdd = (int)(spaceAvailableThisPass * (child->style()->boxFlex()/totalFlex)); … … 803 753 remainingSpace -= spaceAdd; 804 754 groupRemainingSpace -= spaceAdd; 805 755 806 756 totalFlex -= child->style()->boxFlex(); 807 757 } 808 child = iterator.next();809 758 } 810 759 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. 813 761 int spaceAdd = groupRemainingSpace > 0 ? 1 : -1; 814 while (child && groupRemainingSpace) {762 for (RenderBox* child = iterator.first(); child && groupRemainingSpace; child = iterator.next()) { 815 763 if (allowedChildFlex(child, expanding, i)) { 816 764 child->setOverrideSize(child->overrideHeight() + spaceAdd); … … 820 768 groupRemainingSpace -= spaceAdd; 821 769 } 822 child = iterator.next();823 770 } 824 771 } … … 829 776 if (haveFlex && !m_flexingChildren) 830 777 haveFlex = false; 831 } 778 } 832 779 } while (haveFlex); 833 780 … … 840 787 // Determine the total number of children. 841 788 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()) 846 791 continue; 847 } 848 totalChildren++; 849 child = iterator.next(); 850 } 851 792 793 ++totalChildren; 794 } 795 852 796 // Iterate over the children and space them out according to the 853 797 // justification level. 854 798 if (totalChildren > 1) { 855 totalChildren--;799 --totalChildren; 856 800 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()) 861 803 continue; 862 } 863 804 864 805 if (firstChild) { 865 806 firstChild = false; 866 child = iterator.next();867 807 continue; 868 808 } … … 870 810 offset += remainingSpace/totalChildren; 871 811 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); 875 814 } 876 815 } 877 816 } else { 878 817 if (style()->boxPack() == BCENTER) 879 offset += remainingSpace /2;818 offset += remainingSpace / 2; 880 819 else // END 881 820 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()) 886 823 continue; 887 } 888 placeChild(child, child->x(), child->y()+offset); 889 child = iterator.next(); 824 placeChild(child, child->x(), child->y() + offset); 890 825 } 891 826 } … … 895 830 // a height change, we revert our height back to the intrinsic height before returning. 896 831 if (heightSpecified) 897 setHeight(oldHeight); 832 setHeight(oldHeight); 898 833 } 899 834 … … 930 865 if (child->isPositioned() || !child->style()->height().isAuto() || !child->isBlockFlow()) 931 866 continue; 932 867 933 868 RenderBlock* blockChild = toRenderBlock(child); 934 869 int lineCount = blockChild->lineCount(); 935 870 if (lineCount <= numVisibleLines) 936 871 continue; 937 872 938 873 int newHeight = blockChild->heightForLineCount(numVisibleLines); 939 874 if (newHeight == child->height()) 940 875 continue; 941 876 942 877 child->setChildNeedsLayout(true, false); 943 878 child->setOverrideSize(newHeight); … … 952 887 953 888 // Get the last line 954 RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount -1);889 RootInlineBox* lastLine = blockChild->lineAtIndex(lineCount - 1); 955 890 if (!lastLine) 956 891 continue; 957 892 958 RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines -1);893 RootInlineBox* lastVisibleLine = blockChild->lineAtIndex(numVisibleLines - 1); 959 894 if (!lastVisibleLine) 960 895 continue; … … 965 900 const Font& font = style(numVisibleLines == 1)->font(); 966 901 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 968 903 int totalWidth; 969 904 InlineBox* anchorBox = lastLine->lastChild(); … … 978 913 RenderBlock* destBlock = toRenderBlock(lastVisibleLine->renderer()); 979 914 RenderBlock* srcBlock = toRenderBlock(lastLine->renderer()); 980 915 981 916 // FIXME: Directions of src/destBlock could be different from our direction and from one another. 982 917 if (!srcBlock->style()->isLeftToRightDirection()) … … 1018 953 if (child->isPositioned() || child->style()->boxFlex() == 0.0f || child->style()->boxFlexGroup() != group) 1019 954 return 0; 1020 955 1021 956 if (expanding) { 1022 957 if (isHorizontal()) { 1023 958 // 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(); 1029 963 else if (child->style()->maxWidth().type() == Intrinsic) 1030 maxW = child->maxPreferredLogicalWidth();964 maxWidth = child->maxPreferredLogicalWidth(); 1031 965 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); 1036 970 } else { 1037 971 // 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); 1046 979 } 1047 980 } … … 1049 982 // FIXME: For now just handle fixed values. 1050 983 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(); 1053 986 if (child->style()->minWidth().isFixed()) 1054 minW = child->style()->minWidth().value();987 minWidth = child->style()->minWidth().value(); 1055 988 else if (child->style()->minWidth().type() == Intrinsic) 1056 minW = child->maxPreferredLogicalWidth();989 minWidth = child->maxPreferredLogicalWidth(); 1057 990 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); 1061 994 return allowedShrinkage; 1062 995 } else { 1063 996 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); 1067 1000 return allowedShrinkage; 1068 1001 } 1069 1002 } 1070 1003 1071 1004 return 0; 1072 1005 }
Note: See TracChangeset
for help on using the changeset viewer.