OLD | NEW |
---|---|
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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 | 404 |
405 LayoutUnit LayoutFlexibleBox::computeMainAxisExtentForChild(LayoutBox& child, Si zeType sizeType, const Length& size) | 405 LayoutUnit LayoutFlexibleBox::computeMainAxisExtentForChild(LayoutBox& child, Si zeType sizeType, const Length& size) |
406 { | 406 { |
407 // If we have a horizontal flow, that means the main size is the width. | 407 // If we have a horizontal flow, that means the main size is the width. |
408 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. | 408 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. |
409 // For a vertical flow, main size is the height, so it's the inverse. | 409 // For a vertical flow, main size is the height, so it's the inverse. |
410 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. | 410 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. |
411 // Otherwise we need the logical height. | 411 // Otherwise we need the logical height. |
412 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { | 412 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { |
413 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. | 413 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. |
414 if (size.isIntrinsic()) | 414 // It's safe to access scrollbarLogicalHeight here because computeNextFl exLine will have already |
415 child.layoutIfNeeded(); | 415 // forced layout on the child. |
416 return child.computeContentLogicalHeight(sizeType, size, child.logicalHe ight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight() ; | 416 return child.computeContentLogicalHeight(sizeType, size, child.logicalHe ight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight() ; |
417 } | 417 } |
418 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); | 418 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); |
419 } | 419 } |
420 | 420 |
421 WritingMode LayoutFlexibleBox::transformedWritingMode() const | 421 WritingMode LayoutFlexibleBox::transformedWritingMode() const |
422 { | 422 { |
423 WritingMode mode = style()->writingMode(); | 423 WritingMode mode = style()->writingMode(); |
424 if (!isColumnFlow()) | 424 if (!isColumnFlow()) |
425 return mode; | 425 return mode; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 if (flexBasis.hasPercent()) { | 598 if (flexBasis.hasPercent()) { |
599 return isColumnFlow() ? | 599 return isColumnFlow() ? |
600 child.computePercentageLogicalHeight(flexBasis) != -1 : | 600 child.computePercentageLogicalHeight(flexBasis) != -1 : |
601 hasDefiniteLogicalWidth(); | 601 hasDefiniteLogicalWidth(); |
602 } | 602 } |
603 return true; | 603 return true; |
604 } | 604 } |
605 | 605 |
606 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(LayoutBox& child) const | 606 bool LayoutFlexibleBox::childFlexBaseSizeRequiresLayout(LayoutBox& child) const |
607 { | 607 { |
608 return !mainAxisLengthIsDefinite(child, flexBasisForChild(child)) && hasOrth ogonalFlow(child); | 608 return !mainAxisLengthIsDefinite(child, flexBasisForChild(child)) && ( |
609 hasOrthogonalFlow(child) || crossAxisOverflowForChild(child) == OAUTO); | |
609 } | 610 } |
610 | 611 |
611 LayoutUnit LayoutFlexibleBox::computeInnerFlexBaseSizeForChild(LayoutBox& child, ChildLayoutType childLayoutType) | 612 LayoutUnit LayoutFlexibleBox::computeInnerFlexBaseSizeForChild(LayoutBox& child, ChildLayoutType childLayoutType) |
612 { | 613 { |
613 child.clearOverrideSize(); | 614 child.clearOverrideSize(); |
614 | 615 |
615 if (child.isImage() || child.isVideo() || child.isCanvas()) | 616 if (child.isImage() || child.isVideo() || child.isCanvas()) |
616 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); | 617 UseCounter::count(document(), UseCounter::AspectRatioFlexItem); |
617 | 618 |
618 Length flexBasis = flexBasisForChild(child); | 619 Length flexBasis = flexBasisForChild(child); |
619 if (!mainAxisLengthIsDefinite(child, flexBasis)) { | 620 if (!mainAxisLengthIsDefinite(child, flexBasis)) { |
620 LayoutUnit mainAxisExtent; | 621 LayoutUnit mainAxisExtent; |
621 if (hasOrthogonalFlow(child)) { | 622 if (childFlexBaseSizeRequiresLayout(child)) { |
622 if (childLayoutType == NeverLayout) | 623 if (childLayoutType == NeverLayout) |
623 return LayoutUnit(); | 624 return LayoutUnit(); |
624 | 625 |
625 if (child.needsLayout() || childLayoutType == ForceLayout || !m_intr insicSizeAlongMainAxis.contains(&child)) { | 626 if (child.needsLayout() || childLayoutType == ForceLayout || !m_intr insicSizeAlongMainAxis.contains(&child)) { |
626 m_intrinsicSizeAlongMainAxis.remove(&child); | 627 m_intrinsicSizeAlongMainAxis.remove(&child); |
627 child.forceChildLayout(); | 628 child.forceChildLayout(); |
628 m_intrinsicSizeAlongMainAxis.set(&child, child.logicalHeight()); | 629 m_intrinsicSizeAlongMainAxis.set(&child, hasOrthogonalFlow(child ) ? child.logicalHeight() : child.logicalWidth()); |
629 } | 630 } |
630 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child); | 631 mainAxisExtent = m_intrinsicSizeAlongMainAxis.get(&child); |
631 } else { | 632 } else { |
632 mainAxisExtent = child.maxPreferredLogicalWidth(); | 633 mainAxisExtent = child.maxPreferredLogicalWidth(); |
633 } | 634 } |
634 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0); | 635 ASSERT(mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child) >= 0); |
635 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); | 636 return mainAxisExtent - mainAxisBorderAndPaddingExtentForChild(child); |
636 } | 637 } |
637 return std::max(LayoutUnit(), computeMainAxisExtentForChild(child, MainOrPre ferredSize, flexBasis)); | 638 return std::max(LayoutUnit(), computeMainAxisExtentForChild(child, MainOrPre ferredSize, flexBasis)); |
638 } | 639 } |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); | 892 LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); |
892 | 893 |
893 bool lineHasInFlowItem = false; | 894 bool lineHasInFlowItem = false; |
894 | 895 |
895 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord erIterator.next()) { | 896 for (LayoutBox* child = m_orderIterator.currentChild(); child; child = m_ord erIterator.next()) { |
896 if (child->isOutOfFlowPositioned()) { | 897 if (child->isOutOfFlowPositioned()) { |
897 orderedChildren.append(child); | 898 orderedChildren.append(child); |
898 continue; | 899 continue; |
899 } | 900 } |
900 | 901 |
902 // If this condition is true, then computeMainAxisExtentForChild will ca ll | |
leviw_travelin_and_unemployed
2015/08/20 18:53:06
Extract into a named function?
szager1
2015/08/20 21:53:29
Done.
| |
903 // child.contentLogicalHeight() and child.scrollbarLogicalHeight(), so.. . | |
904 if (isHorizontalFlow() != child->styleRef().isHorizontalWritingMode()) { | |
905 // ... if the child has intrinsic min/max/preferred size, run layout on it now to make | |
906 // sure its logical height and scroll bars are up-to-date. | |
907 Length childFlexBasis = flexBasisForChild(*child); | |
908 Length childMinSize = isHorizontalFlow() ? child->style()->minWidth( ) : child->style()->minHeight(); | |
909 Length childMaxSize = isHorizontalFlow() ? child->style()->maxWidth( ) : child->style()->maxHeight(); | |
910 if (childFlexBasis.isIntrinsic() || childMinSize.isIntrinsic() || ch ildMaxSize.isIntrinsic()) | |
911 child->layoutIfNeeded(); | |
912 } | |
913 | |
901 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(*ch ild, relayoutChildren ? ForceLayout : LayoutIfNeeded); | 914 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild(*ch ild, relayoutChildren ? ForceLayout : LayoutIfNeeded); |
902 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx tentForChild(*child) | 915 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx tentForChild(*child) |
903 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight() ); | 916 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight() ); |
904 LayoutUnit childOuterFlexBaseSize = childInnerFlexBaseSize + childMainAx isMarginBorderPadding; | 917 LayoutUnit childOuterFlexBaseSize = childInnerFlexBaseSize + childMainAx isMarginBorderPadding; |
905 | 918 |
906 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa x(*child, childInnerFlexBaseSize); | 919 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa x(*child, childInnerFlexBaseSize); |
907 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding; | 920 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding; |
908 | 921 |
909 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem) | 922 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem) |
910 break; | 923 break; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1095 return isHorizontalFlow() && child.style()->height().isAuto(); | 1108 return isHorizontalFlow() && child.style()->height().isAuto(); |
1096 } | 1109 } |
1097 | 1110 |
1098 EOverflow LayoutFlexibleBox::mainAxisOverflowForChild(LayoutBox& child) const | 1111 EOverflow LayoutFlexibleBox::mainAxisOverflowForChild(LayoutBox& child) const |
1099 { | 1112 { |
1100 if (isHorizontalFlow()) | 1113 if (isHorizontalFlow()) |
1101 return child.styleRef().overflowX(); | 1114 return child.styleRef().overflowX(); |
1102 return child.styleRef().overflowY(); | 1115 return child.styleRef().overflowY(); |
1103 } | 1116 } |
1104 | 1117 |
1118 EOverflow LayoutFlexibleBox::crossAxisOverflowForChild(LayoutBox& child) const | |
1119 { | |
1120 if (isHorizontalFlow()) | |
1121 return child.styleRef().overflowY(); | |
1122 return child.styleRef().overflowX(); | |
1123 } | |
1105 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, SubtreeLayoutScope& layoutScope , Vector<LineContext>& lineContexts) | 1124 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, SubtreeLayoutScope& layoutScope , Vector<LineContext>& lineContexts) |
1106 { | 1125 { |
1107 ASSERT(childSizes.size() == children.size()); | 1126 ASSERT(childSizes.size() == children.size()); |
1108 | 1127 |
1109 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); | 1128 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); |
1110 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); | 1129 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); |
1111 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; | 1130 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; |
1112 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContentPosition(), style()->justifyContentDistribution(), numberOfChildren ForJustifyContent); | 1131 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContentPosition(), style()->justifyContentDistribution(), numberOfChildren ForJustifyContent); |
1113 if (style()->flexDirection() == FlowRowReverse) | 1132 if (style()->flexDirection() == FlowRowReverse) |
1114 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); | 1133 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 ASSERT(child); | 1465 ASSERT(child); |
1447 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; | 1466 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; |
1448 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 1467 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
1449 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; | 1468 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; |
1450 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1469 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1451 } | 1470 } |
1452 } | 1471 } |
1453 } | 1472 } |
1454 | 1473 |
1455 } | 1474 } |
OLD | NEW |