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 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 if (isHorizontalFlow()) { | 827 if (isHorizontalFlow()) { |
828 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft())); | 828 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft())); |
829 child->setMarginRight(computeChildMarginValue(child->style()->margin Right())); | 829 child->setMarginRight(computeChildMarginValue(child->style()->margin Right())); |
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, bool childShrunk) |
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 LayoutUnit maxExtent = -1; |
841 if (max.isSpecifiedOrIntrinsic()) { | 841 if (max.isSpecifiedOrIntrinsic()) { |
842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); | 842 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); |
843 if (maxExtent != -1 && childSize > maxExtent) | 843 if (maxExtent != -1 && childSize > maxExtent) |
844 childSize = maxExtent; | 844 childSize = maxExtent; |
845 } | 845 } |
846 | 846 |
847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); | 847 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); |
848 LayoutUnit minExtent = 0; | 848 LayoutUnit minExtent = 0; |
849 if (min.isSpecifiedOrIntrinsic()) { | 849 if (min.isSpecifiedOrIntrinsic()) { |
850 minExtent = computeMainAxisExtentForChild(child, MinSize, min); | 850 minExtent = computeMainAxisExtentForChild(child, MinSize, min); |
851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage | 851 // computeMainAxisExtentForChild can return -1 when the child has a perc entage |
852 // min size, but we have an indefinite size in that axis. | 852 // min size, but we have an indefinite size in that axis. |
853 minExtent = std::max(LayoutUnit(), minExtent); | 853 minExtent = std::max(LayoutUnit(), minExtent); |
854 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { | 854 } else if (childShrunk && min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { |
855 // css-flexbox section 4.5 | 855 // css-flexbox section 4.5 |
856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); | 856 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); |
857 ASSERT(contentSize >= 0); | 857 ASSERT(contentSize >= 0); |
858 if (maxExtent != -1 && contentSize > maxExtent) | 858 if (maxExtent != -1 && contentSize > maxExtent) |
859 contentSize = maxExtent; | 859 contentSize = maxExtent; |
860 | 860 |
861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child); | 861 bool hasClampedSize = !childPreferredMainAxisContentExtentRequiresLayout (child); |
862 if (hasClampedSize) { | 862 if (hasClampedSize) { |
863 const Length& flexBasis = flexBasisForChild(child); | 863 const Length& flexBasis = flexBasisForChild(child); |
864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite()); | 864 bool flexBasisIsDefinite = flexBasis.isFixed() || (flexBasis.isPerce nt() && mainAxisExtentIsDefinite()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 if (child->isOutOfFlowPositioned()) { | 898 if (child->isOutOfFlowPositioned()) { |
899 orderedChildren.append(child); | 899 orderedChildren.append(child); |
900 continue; | 900 continue; |
901 } | 901 } |
902 | 902 |
903 LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild( *child, relayoutChildren); | 903 LayoutUnit childMainAxisExtent = preferredMainAxisContentExtentForChild( *child, relayoutChildren); |
904 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx tentForChild(*child) | 904 LayoutUnit childMainAxisMarginBorderPadding = mainAxisBorderAndPaddingEx tentForChild(*child) |
905 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight() ); | 905 + (isHorizontalFlow() ? child->marginWidth() : child->marginHeight() ); |
906 LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMargin BorderPadding; | 906 LayoutUnit childFlexBaseSize = childMainAxisExtent + childMainAxisMargin BorderPadding; |
907 | 907 |
908 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa x(*child, childMainAxisExtent); | 908 LayoutUnit childMinMaxAppliedMainAxisExtent = adjustChildSizeForMinAndMa x(*child, childMainAxisExtent, false); |
leviw_travelin_and_unemployed
2015/04/17 19:17:40
Maybe make the parameter default to false to avoid
cbiesinger
2015/04/17 19:39:25
Done.
| |
909 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding; | 909 LayoutUnit childHypotheticalMainSize = childMinMaxAppliedMainAxisExtent + childMainAxisMarginBorderPadding; |
910 | 910 |
911 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem) | 911 if (isMultiline() && sumHypotheticalMainSize + childHypotheticalMainSize > lineBreakLength && lineHasInFlowItem) |
912 break; | 912 break; |
913 orderedChildren.append(child); | 913 orderedChildren.append(child); |
914 lineHasInFlowItem = true; | 914 lineHasInFlowItem = true; |
915 sumFlexBaseSize += childFlexBaseSize; | 915 sumFlexBaseSize += childFlexBaseSize; |
916 totalFlexGrow += child->style()->flexGrow(); | 916 totalFlexGrow += child->style()->flexGrow(); |
917 totalWeightedFlexShrink += child->style()->flexShrink() * childMainAxisE xtent; | 917 totalWeightedFlexShrink += child->style()->flexShrink() * childMainAxisE xtent; |
918 sumHypotheticalMainSize += childHypotheticalMainSize; | 918 sumHypotheticalMainSize += childHypotheticalMainSize; |
(...skipping 28 matching lines...) Expand all Loading... | |
947 childSizes.append(0); | 947 childSizes.append(0); |
948 continue; | 948 continue; |
949 } | 949 } |
950 | 950 |
951 if (inflexibleItems.contains(child)) { | 951 if (inflexibleItems.contains(child)) { |
952 childSizes.append(inflexibleItems.get(child)); | 952 childSizes.append(inflexibleItems.get(child)); |
953 } else { | 953 } else { |
954 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi ld(*child); | 954 LayoutUnit preferredChildSize = preferredMainAxisContentExtentForChi ld(*child); |
955 LayoutUnit childSize = preferredChildSize; | 955 LayoutUnit childSize = preferredChildSize; |
956 double extraSpace = 0; | 956 double extraSpace = 0; |
957 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) | 957 bool childShrunk = false; |
958 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) { | |
958 extraSpace = availableFreeSpace * child->style()->flexGrow() / t otalFlexGrow; | 959 extraSpace = availableFreeSpace * child->style()->flexGrow() / t otalFlexGrow; |
959 else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && fl exSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink)) | 960 } else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && flexSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && chi ld->style()->flexShrink()) { |
960 extraSpace = availableFreeSpace * child->style()->flexShrink() * preferredChildSize / totalWeightedFlexShrink; | 961 extraSpace = availableFreeSpace * child->style()->flexShrink() * preferredChildSize / totalWeightedFlexShrink; |
962 childShrunk = true; | |
963 } | |
961 if (std::isfinite(extraSpace)) | 964 if (std::isfinite(extraSpace)) |
962 childSize += LayoutUnit::fromFloatRound(extraSpace); | 965 childSize += LayoutUnit::fromFloatRound(extraSpace); |
963 | 966 |
964 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize); | 967 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize, childShrunk); |
965 ASSERT(adjustedChildSize >= 0); | 968 ASSERT(adjustedChildSize >= 0); |
966 childSizes.append(adjustedChildSize); | 969 childSizes.append(adjustedChildSize); |
967 usedFreeSpace += adjustedChildSize - preferredChildSize; | 970 usedFreeSpace += adjustedChildSize - preferredChildSize; |
968 | 971 |
969 LayoutUnit violation = adjustedChildSize - childSize; | 972 LayoutUnit violation = adjustedChildSize - childSize; |
970 if (violation > 0) | 973 if (violation > 0) |
971 minViolations.append(Violation(child, adjustedChildSize)); | 974 minViolations.append(Violation(child, adjustedChildSize)); |
972 else if (violation < 0) | 975 else if (violation < 0) |
973 maxViolations.append(Violation(child, adjustedChildSize)); | 976 maxViolations.append(Violation(child, adjustedChildSize)); |
974 totalViolation += violation; | 977 totalViolation += violation; |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1439 ASSERT(child); | 1442 ASSERT(child); |
1440 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; | 1443 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; |
1441 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 1444 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
1442 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; | 1445 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; |
1443 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1446 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1444 } | 1447 } |
1445 } | 1448 } |
1446 } | 1449 } |
1447 | 1450 |
1448 } | 1451 } |
OLD | NEW |