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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 { | 412 { |
413 // If we have a horizontal flow, that means the main size is the width. | 413 // If we have a horizontal flow, that means the main size is the width. |
414 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. | 414 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. |
415 // For a vertical flow, main size is the height, so it's the inverse. | 415 // For a vertical flow, main size is the height, so it's the inverse. |
416 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. | 416 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. |
417 // Otherwise we need the logical height. | 417 // Otherwise we need the logical height. |
418 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { | 418 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { |
419 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. | 419 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. |
420 if (size.isIntrinsic()) | 420 if (size.isIntrinsic()) |
421 child.layoutIfNeeded(); | 421 child.layoutIfNeeded(); |
422 return child.computeContentLogicalHeight(size, child.logicalHeight() - c hild.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight(); | 422 return child.computeContentLogicalHeight(sizeType, size, child.logicalHe ight() - child.borderAndPaddingLogicalHeight()) + child.scrollbarLogicalHeight() ; |
423 } | 423 } |
424 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); | 424 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); |
425 } | 425 } |
426 | 426 |
427 WritingMode LayoutFlexibleBox::transformedWritingMode() const | 427 WritingMode LayoutFlexibleBox::transformedWritingMode() const |
428 { | 428 { |
429 WritingMode mode = style()->writingMode(); | 429 WritingMode mode = style()->writingMode(); |
430 if (!isColumnFlow()) | 430 if (!isColumnFlow()) |
431 return mode; | 431 return mode; |
432 | 432 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 } else { | 830 } else { |
831 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p())); | 831 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p())); |
832 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom())); | 832 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom())); |
833 } | 833 } |
834 } | 834 } |
835 } | 835 } |
836 | 836 |
837 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, Layo utUnit childSize) | 837 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(LayoutBox& child, Layo utUnit childSize) |
838 { | 838 { |
839 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight(); | 839 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight(); |
840 LayoutUnit maxExtent = -1; | |
840 if (max.isSpecifiedOrIntrinsic()) { | 841 if (max.isSpecifiedOrIntrinsic()) { |
841 LayoutUnit maxExtent = computeMainAxisExtentForChild(child, MaxSize, max ); | 842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); |
842 if (maxExtent != -1 && childSize > maxExtent) | 843 if (maxExtent != -1 && childSize > maxExtent) |
843 childSize = maxExtent; | 844 childSize = maxExtent; |
844 } | 845 } |
845 | 846 |
846 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); | 847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); |
847 LayoutUnit minExtent = 0; | 848 LayoutUnit minExtent = 0; |
848 if (min.isSpecifiedOrIntrinsic()) | 849 if (min.isSpecifiedOrIntrinsic()) { |
849 minExtent = computeMainAxisExtentForChild(child, MinSize, min); | 850 minExtent = computeMainAxisExtentForChild(child, MinSize, min); |
851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage | |
852 // min size, but we have an indefinite size in that axis. | |
853 minExtent = std::max(LayoutUnit(0), minExtent); | |
854 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { | |
855 // css-flexbox section 4.5 | |
856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); | |
857 ASSERT(contentSize >= 0); | |
858 if (maxExtent != -1 && contentSize > maxExtent) | |
859 contentSize = maxExtent; | |
860 | |
861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child); | |
862 if (hasClampedSize) { | |
863 Length flexBasis = flexBasisForChild(child); | |
Julien - ping for review
2015/04/06 17:06:47
const Length&?
cbiesinger
2015/04/06 21:34:16
Done.
| |
864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite()); | |
865 if (flexBasisIsDefinite) { | |
866 LayoutUnit resolvedFlexBasis = computeMainAxisExtentForChild(chi ld, MainOrPreferredSize, flexBasis); | |
867 ASSERT(resolvedFlexBasis >= 0); | |
868 LayoutUnit clampedSize = resolvedFlexBasis; | |
Julien - ping for review
2015/04/06 17:06:47
We don't seem to need |resolvedFlexBasis| as we di
cbiesinger
2015/04/06 21:34:16
clampedSize is basically std::min(resolvedFlexBasi
Julien - ping for review
2015/04/13 21:25:59
I think this would be clearer:
LayoutUnit clamped
cbiesinger
2015/04/13 23:23:12
Done.
| |
869 if (maxExtent != -1 && clampedSize > maxExtent) | |
870 clampedSize = maxExtent; | |
871 | |
872 minExtent = std::min(clampedSize, contentSize); | |
873 } else { | |
874 minExtent = contentSize; | |
875 } | |
876 } else { | |
877 minExtent = contentSize; | |
878 } | |
879 // TODO(cbiesinger): Implement aspect ratio handling (here, transferred size) - crbug.com/249112 | |
880 } | |
881 ASSERT(minExtent >= 0); | |
850 return std::max(childSize, minExtent); | 882 return std::max(childSize, minExtent); |
851 } | 883 } |
852 | 884 |
853 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexS hrink, LayoutUnit& sumHypotheticalMainSize, bool relayoutChildren) | 885 bool LayoutFlexibleBox::computeNextFlexLine(OrderedFlexItemList& orderedChildren , LayoutUnit& sumFlexBaseSize, double& totalFlexGrow, double& totalWeightedFlexS hrink, LayoutUnit& sumHypotheticalMainSize, bool relayoutChildren) |
854 { | 886 { |
855 orderedChildren.clear(); | 887 orderedChildren.clear(); |
856 sumFlexBaseSize = 0; | 888 sumFlexBaseSize = 0; |
857 totalFlexGrow = totalWeightedFlexShrink = 0; | 889 totalFlexGrow = totalWeightedFlexShrink = 0; |
858 sumHypotheticalMainSize = 0; | 890 sumHypotheticalMainSize = 0; |
859 | 891 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1051 } | 1083 } |
1052 | 1084 |
1053 bool LayoutFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const | 1085 bool LayoutFlexibleBox::needToStretchChildLogicalHeight(LayoutBox& child) const |
1054 { | 1086 { |
1055 if (alignmentForChild(child) != ItemPositionStretch) | 1087 if (alignmentForChild(child) != ItemPositionStretch) |
1056 return false; | 1088 return false; |
1057 | 1089 |
1058 return isHorizontalFlow() && child.style()->height().isAuto(); | 1090 return isHorizontalFlow() && child.style()->height().isAuto(); |
1059 } | 1091 } |
1060 | 1092 |
1093 EOverflow LayoutFlexibleBox::mainAxisOverflowForChild(LayoutBox& child) const | |
1094 { | |
1095 if (isHorizontalFlow()) | |
1096 return child.styleRef().overflowX(); | |
1097 return child.styleRef().overflowY(); | |
1098 } | |
1099 | |
1061 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts) | 1100 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, const Vector<LayoutUnit, 16>& childSizes, Layou tUnit availableFreeSpace, bool relayoutChildren, Vector<LineContext>& lineContex ts) |
1062 { | 1101 { |
1063 ASSERT(childSizes.size() == children.size()); | 1102 ASSERT(childSizes.size() == children.size()); |
1064 | 1103 |
1065 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); | 1104 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); |
1066 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); | 1105 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); |
1067 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; | 1106 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; |
1068 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent); | 1107 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, style()->j ustifyContent(), style()->justifyContentDistribution(), numberOfChildrenForJusti fyContent); |
1069 if (style()->flexDirection() == FlowRowReverse) | 1108 if (style()->flexDirection() == FlowRowReverse) |
1070 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); | 1109 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 ASSERT(child); | 1440 ASSERT(child); |
1402 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; | 1441 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; |
1403 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 1442 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
1404 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; | 1443 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; |
1405 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1444 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1406 } | 1445 } |
1407 } | 1446 } |
1408 } | 1447 } |
1409 | 1448 |
1410 } | 1449 } |
OLD | NEW |