Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutFlexibleBox.cpp

Issue 1647313003: Continue converting to explicit LayoutUnit constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@explicitContstructors
Patch Set: Add TODO Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 previousMaxContentFlexFraction = countIntrinsicSizeForAlgorithmChange(ma xPreferredLogicalWidth, child, previousMaxContentFlexFraction); 136 previousMaxContentFlexFraction = countIntrinsicSizeForAlgorithmChange(ma xPreferredLogicalWidth, child, previousMaxContentFlexFraction);
137 } 137 }
138 138
139 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth); 139 maxLogicalWidth = std::max(minLogicalWidth, maxLogicalWidth);
140 140
141 // Due to negative margins, it is possible that we calculated a negative int rinsic width. Make sure that we 141 // Due to negative margins, it is possible that we calculated a negative int rinsic width. Make sure that we
142 // never return a negative width. 142 // never return a negative width.
143 minLogicalWidth = std::max(LayoutUnit(), minLogicalWidth); 143 minLogicalWidth = std::max(LayoutUnit(), minLogicalWidth);
144 maxLogicalWidth = std::max(LayoutUnit(), maxLogicalWidth); 144 maxLogicalWidth = std::max(LayoutUnit(), maxLogicalWidth);
145 145
146 LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth(); 146 LayoutUnit scrollbarWidth(intrinsicScrollbarLogicalWidth());
147 maxLogicalWidth += scrollbarWidth; 147 maxLogicalWidth += scrollbarWidth;
148 minLogicalWidth += scrollbarWidth; 148 minLogicalWidth += scrollbarWidth;
149 } 149 }
150 150
151 float LayoutFlexibleBox::countIntrinsicSizeForAlgorithmChange(LayoutUnit maxPref erredLogicalWidth, LayoutBox* child, float previousMaxContentFlexFraction) const 151 float LayoutFlexibleBox::countIntrinsicSizeForAlgorithmChange(LayoutUnit maxPref erredLogicalWidth, LayoutBox* child, float previousMaxContentFlexFraction) const
152 { 152 {
153 // Determine whether the new version of the intrinsic size algorithm of the flexbox 153 // Determine whether the new version of the intrinsic size algorithm of the flexbox
154 // spec would produce a different result than our above algorithm. 154 // spec would produce a different result than our above algorithm.
155 // The algorithm produces a different result iff the max-content flex fracti on 155 // The algorithm produces a different result iff the max-content flex fracti on
156 // (as defined in the new algorithm) is not identical for each flex item. 156 // (as defined in the new algorithm) is not identical for each flex item.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 318
319 if (style()->flexWrap() == FlexWrapReverse) 319 if (style()->flexWrap() == FlexWrapReverse)
320 flipForWrapReverse(lineContexts, crossAxisStartEdge); 320 flipForWrapReverse(lineContexts, crossAxisStartEdge);
321 321
322 // direction:rtl + flex-direction:column means the cross-axis direction is f lipped. 322 // direction:rtl + flex-direction:column means the cross-axis direction is f lipped.
323 flipForRightToLeftColumn(); 323 flipForRightToLeftColumn();
324 } 324 }
325 325
326 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning() 326 LayoutUnit LayoutFlexibleBox::clientLogicalBottomAfterRepositioning()
327 { 327 {
328 LayoutUnit maxChildLogicalBottom = 0; 328 LayoutUnit maxChildLogicalBottom;
329 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) { 329 for (LayoutBox* child = firstChildBox(); child; child = child->nextSiblingBo x()) {
330 if (child->isOutOfFlowPositioned()) 330 if (child->isOutOfFlowPositioned())
331 continue; 331 continue;
332 LayoutUnit childLogicalBottom = logicalTopForChild(*child) + logicalHeig htForChild(*child) + marginAfterForChild(*child); 332 LayoutUnit childLogicalBottom = logicalTopForChild(*child) + logicalHeig htForChild(*child) + marginAfterForChild(*child);
333 maxChildLogicalBottom = std::max(maxChildLogicalBottom, childLogicalBott om); 333 maxChildLogicalBottom = std::max(maxChildLogicalBottom, childLogicalBott om);
334 } 334 }
335 return std::max(clientLogicalBottom(), maxChildLogicalBottom + paddingAfter( )); 335 return std::max(clientLogicalBottom(), maxChildLogicalBottom + paddingAfter( ));
336 } 336 }
337 337
338 bool LayoutFlexibleBox::hasOrthogonalFlow(const LayoutBox& child) const 338 bool LayoutFlexibleBox::hasOrthogonalFlow(const LayoutBox& child) const
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 case RightToLeftWritingMode: 484 case RightToLeftWritingMode:
485 return style()->isLeftToRightDirection() ? TransformedWritingMode::TopTo BottomWritingMode : TransformedWritingMode::BottomToTopWritingMode; 485 return style()->isLeftToRightDirection() ? TransformedWritingMode::TopTo BottomWritingMode : TransformedWritingMode::BottomToTopWritingMode;
486 } 486 }
487 ASSERT_NOT_REACHED(); 487 ASSERT_NOT_REACHED();
488 return TransformedWritingMode::TopToBottomWritingMode; 488 return TransformedWritingMode::TopToBottomWritingMode;
489 } 489 }
490 490
491 LayoutUnit LayoutFlexibleBox::flowAwareBorderStart() const 491 LayoutUnit LayoutFlexibleBox::flowAwareBorderStart() const
492 { 492 {
493 if (isHorizontalFlow()) 493 if (isHorizontalFlow())
494 return isLeftToRightFlow() ? borderLeft() : borderRight(); 494 return LayoutUnit(isLeftToRightFlow() ? borderLeft() : borderRight());
495 return isLeftToRightFlow() ? borderTop() : borderBottom(); 495 return LayoutUnit(isLeftToRightFlow() ? borderTop() : borderBottom());
496 } 496 }
497 497
498 LayoutUnit LayoutFlexibleBox::flowAwareBorderEnd() const 498 LayoutUnit LayoutFlexibleBox::flowAwareBorderEnd() const
499 { 499 {
500 if (isHorizontalFlow()) 500 if (isHorizontalFlow())
501 return isLeftToRightFlow() ? borderRight() : borderLeft(); 501 return LayoutUnit(isLeftToRightFlow() ? borderRight() : borderLeft());
502 return isLeftToRightFlow() ? borderBottom() : borderTop(); 502 return LayoutUnit(isLeftToRightFlow() ? borderBottom() : borderTop());
503 } 503 }
504 504
505 LayoutUnit LayoutFlexibleBox::flowAwareBorderBefore() const 505 LayoutUnit LayoutFlexibleBox::flowAwareBorderBefore() const
506 { 506 {
507 switch (transformedWritingMode()) { 507 switch (transformedWritingMode()) {
508 case TransformedWritingMode::TopToBottomWritingMode: 508 case TransformedWritingMode::TopToBottomWritingMode:
509 return borderTop(); 509 return LayoutUnit(borderTop());
510 case TransformedWritingMode::BottomToTopWritingMode: 510 case TransformedWritingMode::BottomToTopWritingMode:
511 return borderBottom(); 511 return LayoutUnit(borderBottom());
512 case TransformedWritingMode::LeftToRightWritingMode: 512 case TransformedWritingMode::LeftToRightWritingMode:
513 return borderLeft(); 513 return LayoutUnit(borderLeft());
514 case TransformedWritingMode::RightToLeftWritingMode: 514 case TransformedWritingMode::RightToLeftWritingMode:
515 return borderRight(); 515 return LayoutUnit(borderRight());
516 } 516 }
517 ASSERT_NOT_REACHED(); 517 ASSERT_NOT_REACHED();
518 return borderTop(); 518 return LayoutUnit(borderTop());
519 } 519 }
520 520
521 LayoutUnit LayoutFlexibleBox::flowAwareBorderAfter() const 521 LayoutUnit LayoutFlexibleBox::flowAwareBorderAfter() const
522 { 522 {
523 switch (transformedWritingMode()) { 523 switch (transformedWritingMode()) {
524 case TransformedWritingMode::TopToBottomWritingMode: 524 case TransformedWritingMode::TopToBottomWritingMode:
525 return borderBottom(); 525 return LayoutUnit(borderBottom());
526 case TransformedWritingMode::BottomToTopWritingMode: 526 case TransformedWritingMode::BottomToTopWritingMode:
527 return borderTop(); 527 return LayoutUnit(borderTop());
528 case TransformedWritingMode::LeftToRightWritingMode: 528 case TransformedWritingMode::LeftToRightWritingMode:
529 return borderRight(); 529 return LayoutUnit(borderRight());
530 case TransformedWritingMode::RightToLeftWritingMode: 530 case TransformedWritingMode::RightToLeftWritingMode:
531 return borderLeft(); 531 return LayoutUnit(borderLeft());
532 } 532 }
533 ASSERT_NOT_REACHED(); 533 ASSERT_NOT_REACHED();
534 return borderTop(); 534 return LayoutUnit(borderTop());
535 } 535 }
536 536
537 LayoutUnit LayoutFlexibleBox::flowAwarePaddingStart() const 537 LayoutUnit LayoutFlexibleBox::flowAwarePaddingStart() const
538 { 538 {
539 if (isHorizontalFlow()) 539 if (isHorizontalFlow())
540 return isLeftToRightFlow() ? paddingLeft() : paddingRight(); 540 return isLeftToRightFlow() ? paddingLeft() : paddingRight();
541 return isLeftToRightFlow() ? paddingTop() : paddingBottom(); 541 return isLeftToRightFlow() ? paddingTop() : paddingBottom();
542 } 542 }
543 543
544 LayoutUnit LayoutFlexibleBox::flowAwarePaddingEnd() const 544 LayoutUnit LayoutFlexibleBox::flowAwarePaddingEnd() const
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return marginTop(); 610 return marginTop();
611 } 611 }
612 612
613 LayoutUnit LayoutFlexibleBox::crossAxisMarginExtentForChild(const LayoutBox& chi ld) const 613 LayoutUnit LayoutFlexibleBox::crossAxisMarginExtentForChild(const LayoutBox& chi ld) const
614 { 614 {
615 return isHorizontalFlow() ? child.marginHeight() : child.marginWidth(); 615 return isHorizontalFlow() ? child.marginHeight() : child.marginWidth();
616 } 616 }
617 617
618 LayoutUnit LayoutFlexibleBox::crossAxisScrollbarExtent() const 618 LayoutUnit LayoutFlexibleBox::crossAxisScrollbarExtent() const
619 { 619 {
620 return isHorizontalFlow() ? horizontalScrollbarHeight() : verticalScrollbarW idth(); 620 return LayoutUnit(isHorizontalFlow() ? horizontalScrollbarHeight() : vertica lScrollbarWidth());
621 } 621 }
622 622
623 LayoutUnit LayoutFlexibleBox::crossAxisScrollbarExtentForChild(const LayoutBox& child) const 623 LayoutUnit LayoutFlexibleBox::crossAxisScrollbarExtentForChild(const LayoutBox& child) const
624 { 624 {
625 return isHorizontalFlow() ? child.horizontalScrollbarHeight() : child.vertic alScrollbarWidth(); 625 return LayoutUnit(isHorizontalFlow() ? child.horizontalScrollbarHeight() : c hild.verticalScrollbarWidth());
626 } 626 }
627 627
628 LayoutPoint LayoutFlexibleBox::flowAwareLocationForChild(const LayoutBox& child) const 628 LayoutPoint LayoutFlexibleBox::flowAwareLocationForChild(const LayoutBox& child) const
629 { 629 {
630 return isHorizontalFlow() ? child.location() : child.location().transposedPo int(); 630 return isHorizontalFlow() ? child.location() : child.location().transposedPo int();
631 } 631 }
632 632
633 bool LayoutFlexibleBox::useChildAspectRatio(const LayoutBox& child) const 633 bool LayoutFlexibleBox::useChildAspectRatio(const LayoutBox& child) const
634 { 634 {
635 if (!hasAspectRatio(child)) 635 if (!hasAspectRatio(child))
(...skipping 10 matching lines...) Expand all
646 return crossAxisLengthIsDefinite(child, crossSize); 646 return crossAxisLengthIsDefinite(child, crossSize);
647 } 647 }
648 648
649 LayoutUnit LayoutFlexibleBox::computeMainSizeFromAspectRatioUsing(const LayoutBo x& child, Length crossSizeLength) const 649 LayoutUnit LayoutFlexibleBox::computeMainSizeFromAspectRatioUsing(const LayoutBo x& child, Length crossSizeLength) const
650 { 650 {
651 ASSERT(hasAspectRatio(child)); 651 ASSERT(hasAspectRatio(child));
652 ASSERT(child.intrinsicSize().height() != 0); 652 ASSERT(child.intrinsicSize().height() != 0);
653 653
654 LayoutUnit crossSize; 654 LayoutUnit crossSize;
655 if (crossSizeLength.isFixed()) { 655 if (crossSizeLength.isFixed()) {
656 crossSize = crossSizeLength.value(); 656 crossSize = LayoutUnit(crossSizeLength.value());
657 } else { 657 } else {
658 ASSERT(crossSizeLength.hasPercent()); 658 ASSERT(crossSizeLength.hasPercent());
659 crossSize = hasOrthogonalFlow(child) ? 659 crossSize = hasOrthogonalFlow(child) ?
660 adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(crossSizeLeng th, contentWidth())) : 660 adjustBorderBoxLogicalWidthForBoxSizing(valueForLength(crossSizeLeng th, contentWidth())) :
661 child.computePercentageLogicalHeight(crossSizeLength); 661 child.computePercentageLogicalHeight(crossSizeLength);
662 } 662 }
663 663
664 const LayoutSize& childIntrinsicSize = child.intrinsicSize(); 664 const LayoutSize& childIntrinsicSize = child.intrinsicSize();
665 double ratio = childIntrinsicSize.width().toFloat() / childIntrinsicSize.hei ght().toFloat(); 665 double ratio = childIntrinsicSize.width().toFloat() / childIntrinsicSize.hei ght().toFloat();
666 if (isHorizontalFlow()) 666 if (isHorizontalFlow())
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 if (childNeedsRelayout) { 1586 if (childNeedsRelayout) {
1587 child.setLogicalHeight(0); 1587 child.setLogicalHeight(0);
1588 // We cache the child's intrinsic content logical height to avoid it being reset to the stretched height. 1588 // We cache the child's intrinsic content logical height to avoid it being reset to the stretched height.
1589 // FIXME: This is fragile. LayoutBoxes should be smart enough to det ermine their intrinsic content logical 1589 // FIXME: This is fragile. LayoutBoxes should be smart enough to det ermine their intrinsic content logical
1590 // height correctly even when there's an overrideHeight. 1590 // height correctly even when there's an overrideHeight.
1591 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicConte ntLogicalHeight(); 1591 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicConte ntLogicalHeight();
1592 child.forceChildLayout(); 1592 child.forceChildLayout();
1593 child.setIntrinsicContentLogicalHeight(childIntrinsicContentLogicalH eight); 1593 child.setIntrinsicContentLogicalHeight(childIntrinsicContentLogicalH eight);
1594 } 1594 }
1595 } else if (hasOrthogonalFlow(child) && child.style()->logicalWidth().isAuto( )) { 1595 } else if (hasOrthogonalFlow(child) && child.style()->logicalWidth().isAuto( )) {
1596 LayoutUnit childWidth = std::max<LayoutUnit>(0, lineCrossAxisExtent - cr ossAxisMarginExtentForChild(child)); 1596 LayoutUnit childWidth = (lineCrossAxisExtent - crossAxisMarginExtentForC hild(child)).clampNegativeToZero();
1597 childWidth = child.constrainLogicalWidthByMinMax(childWidth, childWidth, this); 1597 childWidth = child.constrainLogicalWidthByMinMax(childWidth, childWidth, this);
1598 1598
1599 if (childWidth != child.logicalWidth()) { 1599 if (childWidth != child.logicalWidth()) {
1600 child.setOverrideLogicalContentWidth(childWidth - child.borderAndPad dingLogicalWidth()); 1600 child.setOverrideLogicalContentWidth(childWidth - child.borderAndPad dingLogicalWidth());
1601 child.forceChildLayout(); 1601 child.forceChildLayout();
1602 } 1602 }
1603 } 1603 }
1604 } 1604 }
1605 1605
1606 void LayoutFlexibleBox::flipForRightToLeftColumn() 1606 void LayoutFlexibleBox::flipForRightToLeftColumn()
(...skipping 22 matching lines...) Expand all
1629 ASSERT(child); 1629 ASSERT(child);
1630 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1630 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1631 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1631 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1632 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1632 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1633 adjustAlignmentForChild(*child, newOffset - originalOffset); 1633 adjustAlignmentForChild(*child, newOffset - originalOffset);
1634 } 1634 }
1635 } 1635 }
1636 } 1636 }
1637 1637
1638 } // namespace blink 1638 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698