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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. | 439 // That's the logical width for horizontal writing modes, and the logical he ight in vertical writing modes. |
440 // For a vertical flow, main size is the height, so it's the inverse. | 440 // For a vertical flow, main size is the height, so it's the inverse. |
441 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. | 441 // So we need the logical width if we have a horizontal flow and horizontal writing mode, or vertical flow and vertical writing mode. |
442 // Otherwise we need the logical height. | 442 // Otherwise we need the logical height. |
443 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { | 443 if (isHorizontalFlow() != child.styleRef().isHorizontalWritingMode()) { |
444 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. | 444 // We don't have to check for "auto" here - computeContentLogicalHeight will just return -1 for that case anyway. |
445 // It's safe to access scrollbarLogicalHeight here because computeNextFl exLine will have already | 445 // It's safe to access scrollbarLogicalHeight here because computeNextFl exLine will have already |
446 // forced layout on the child. | 446 // forced layout on the child. |
447 return child.computeContentLogicalHeight(sizeType, size, child.contentLo gicalHeight()) + child.scrollbarLogicalHeight(); | 447 return child.computeContentLogicalHeight(sizeType, size, child.contentLo gicalHeight()) + child.scrollbarLogicalHeight(); |
448 } | 448 } |
449 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - child.borderAndPaddingLogicalWidth(); | 449 // computeLogicalWidth always re-computes the intrinsic widths. However, whe n our logical width is auto, |
450 // we can just use our cached value. So let's do that here. (Compare code in LayoutBlock::computePreferredLogicalWidths) | |
451 LayoutUnit borderAndPadding = child.borderAndPaddingLogicalWidth(); | |
452 if (size.type() == MinContent && styleRef().logicalWidth().isAuto()) | |
leviw_travelin_and_unemployed
2015/10/28 01:24:56
if (styleRef().logicalWidth().isAuto) {
if (size
cbiesinger
2015/10/28 01:55:24
Done, except for the "else if" part -- the style g
| |
453 return child.minPreferredLogicalWidth() - borderAndPadding; | |
454 if (size.type() == MaxContent && styleRef().logicalWidth().isAuto()) | |
455 return child.maxPreferredLogicalWidth() - borderAndPadding; | |
456 return child.computeLogicalWidthUsing(sizeType, size, contentLogicalWidth(), this) - borderAndPadding; | |
450 } | 457 } |
451 | 458 |
452 WritingMode LayoutFlexibleBox::transformedWritingMode() const | 459 WritingMode LayoutFlexibleBox::transformedWritingMode() const |
453 { | 460 { |
454 WritingMode mode = style()->writingMode(); | 461 WritingMode mode = style()->writingMode(); |
455 if (!isColumnFlow()) | 462 if (!isColumnFlow()) |
456 return mode; | 463 return mode; |
457 | 464 |
458 switch (mode) { | 465 switch (mode) { |
459 case TopToBottomWritingMode: | 466 case TopToBottomWritingMode: |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 if (isHorizontalFlow()) { | 870 if (isHorizontalFlow()) { |
864 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft())); | 871 child->setMarginLeft(computeChildMarginValue(child->style()->marginL eft())); |
865 child->setMarginRight(computeChildMarginValue(child->style()->margin Right())); | 872 child->setMarginRight(computeChildMarginValue(child->style()->margin Right())); |
866 } else { | 873 } else { |
867 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p())); | 874 child->setMarginTop(computeChildMarginValue(child->style()->marginTo p())); |
868 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom())); | 875 child->setMarginBottom(computeChildMarginValue(child->style()->margi nBottom())); |
869 } | 876 } |
870 } | 877 } |
871 } | 878 } |
872 | 879 |
873 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(const LayoutBox& child , LayoutUnit childSize, bool childShrunk) | 880 LayoutUnit LayoutFlexibleBox::adjustChildSizeForMinAndMax(const LayoutBox& child , LayoutUnit childSize) |
874 { | 881 { |
875 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight(); | 882 Length max = isHorizontalFlow() ? child.style()->maxWidth() : child.style()- >maxHeight(); |
876 LayoutUnit maxExtent = -1; | 883 LayoutUnit maxExtent = -1; |
877 if (max.isSpecifiedOrIntrinsic()) { | 884 if (max.isSpecifiedOrIntrinsic()) { |
878 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); | 885 maxExtent = computeMainAxisExtentForChild(child, MaxSize, max); |
879 ASSERT(maxExtent >= -1); | 886 ASSERT(maxExtent >= -1); |
880 if (maxExtent != -1 && childSize > maxExtent) | 887 if (maxExtent != -1 && childSize > maxExtent) |
881 childSize = maxExtent; | 888 childSize = maxExtent; |
882 } | 889 } |
883 | 890 |
884 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); | 891 Length min = isHorizontalFlow() ? child.style()->minWidth() : child.style()- >minHeight(); |
885 LayoutUnit minExtent = 0; | 892 LayoutUnit minExtent = 0; |
886 if (min.isSpecifiedOrIntrinsic()) { | 893 if (min.isSpecifiedOrIntrinsic()) { |
887 minExtent = computeMainAxisExtentForChild(child, MinSize, min); | 894 minExtent = computeMainAxisExtentForChild(child, MinSize, min); |
888 // computeMainAxisExtentForChild can return -1 when the child has a perc entage | 895 // computeMainAxisExtentForChild can return -1 when the child has a perc entage |
889 // min size, but we have an indefinite size in that axis. | 896 // min size, but we have an indefinite size in that axis. |
890 minExtent = std::max(LayoutUnit(), minExtent); | 897 minExtent = std::max(LayoutUnit(), minExtent); |
891 } else if (childShrunk && min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { | 898 } else if (min.isAuto() && mainAxisOverflowForChild(child) == OVISIBLE) { |
892 // css-flexbox section 4.5 | 899 // css-flexbox section 4.5 |
893 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); | 900 LayoutUnit contentSize = computeMainAxisExtentForChild(child, MinSize, L ength(MinContent)); |
894 ASSERT(contentSize >= 0); | 901 ASSERT(contentSize >= 0); |
895 if (maxExtent != -1 && contentSize > maxExtent) | 902 if (maxExtent != -1 && contentSize > maxExtent) |
896 contentSize = maxExtent; | 903 contentSize = maxExtent; |
897 | 904 |
898 Length mainSize = isHorizontalFlow() ? child.styleRef().width() : child. styleRef().height(); | 905 Length mainSize = isHorizontalFlow() ? child.styleRef().width() : child. styleRef().height(); |
899 if (mainAxisLengthIsDefinite(child, mainSize)) { | 906 if (mainAxisLengthIsDefinite(child, mainSize)) { |
900 LayoutUnit resolvedMainSize = computeMainAxisExtentForChild(child, M ainOrPreferredSize, mainSize); | 907 LayoutUnit resolvedMainSize = computeMainAxisExtentForChild(child, M ainOrPreferredSize, mainSize); |
901 ASSERT(resolvedMainSize >= 0); | 908 ASSERT(resolvedMainSize >= 0); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 childSizes.append(0); | 994 childSizes.append(0); |
988 continue; | 995 continue; |
989 } | 996 } |
990 | 997 |
991 if (inflexibleItems.contains(child)) { | 998 if (inflexibleItems.contains(child)) { |
992 childSizes.append(inflexibleItems.get(child)); | 999 childSizes.append(inflexibleItems.get(child)); |
993 } else { | 1000 } else { |
994 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild (*child); | 1001 LayoutUnit childInnerFlexBaseSize = computeInnerFlexBaseSizeForChild (*child); |
995 LayoutUnit childSize = childInnerFlexBaseSize; | 1002 LayoutUnit childSize = childInnerFlexBaseSize; |
996 double extraSpace = 0; | 1003 double extraSpace = 0; |
997 bool childShrunk = false; | |
998 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) { | 1004 if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == Posit iveFlexibility && std::isfinite(totalFlexGrow)) { |
999 if (totalFlexGrow < 1) | 1005 if (totalFlexGrow < 1) |
1000 extraSpace = availableFreeSpace * child->style()->flexGrow() ; | 1006 extraSpace = availableFreeSpace * child->style()->flexGrow() ; |
1001 else | 1007 else |
1002 extraSpace = availableFreeSpace * child->style()->flexGrow() / totalFlexGrow; | 1008 extraSpace = availableFreeSpace * child->style()->flexGrow() / totalFlexGrow; |
1003 } else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && flexSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && chi ld->style()->flexShrink()) { | 1009 } else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && flexSign == NegativeFlexibility && std::isfinite(totalWeightedFlexShrink) && chi ld->style()->flexShrink()) { |
1004 extraSpace = availableFreeSpace * child->style()->flexShrink() * childInnerFlexBaseSize / totalWeightedFlexShrink; | 1010 extraSpace = availableFreeSpace * child->style()->flexShrink() * childInnerFlexBaseSize / totalWeightedFlexShrink; |
1005 childShrunk = true; | |
1006 } | 1011 } |
1007 if (std::isfinite(extraSpace)) | 1012 if (std::isfinite(extraSpace)) |
1008 childSize += LayoutUnit::fromFloatRound(extraSpace); | 1013 childSize += LayoutUnit::fromFloatRound(extraSpace); |
1009 | 1014 |
1010 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize, childShrunk); | 1015 LayoutUnit adjustedChildSize = adjustChildSizeForMinAndMax(*child, c hildSize); |
1011 ASSERT(adjustedChildSize >= 0); | 1016 ASSERT(adjustedChildSize >= 0); |
1012 childSizes.append(adjustedChildSize); | 1017 childSizes.append(adjustedChildSize); |
1013 usedFreeSpace += adjustedChildSize - childInnerFlexBaseSize; | 1018 usedFreeSpace += adjustedChildSize - childInnerFlexBaseSize; |
1014 | 1019 |
1015 LayoutUnit violation = adjustedChildSize - childSize; | 1020 LayoutUnit violation = adjustedChildSize - childSize; |
1016 if (violation > 0) | 1021 if (violation > 0) |
1017 minViolations.append(Violation(child, adjustedChildSize, childIn nerFlexBaseSize)); | 1022 minViolations.append(Violation(child, adjustedChildSize, childIn nerFlexBaseSize)); |
1018 else if (violation < 0) | 1023 else if (violation < 0) |
1019 maxViolations.append(Violation(child, adjustedChildSize, childIn nerFlexBaseSize)); | 1024 maxViolations.append(Violation(child, adjustedChildSize, childIn nerFlexBaseSize)); |
1020 totalViolation += violation; | 1025 totalViolation += violation; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1511 ASSERT(child); | 1516 ASSERT(child); |
1512 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; | 1517 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; |
1513 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 1518 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
1514 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; | 1519 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; |
1515 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1520 adjustAlignmentForChild(*child, newOffset - originalOffset); |
1516 } | 1521 } |
1517 } | 1522 } |
1518 } | 1523 } |
1519 | 1524 |
1520 } | 1525 } |
OLD | NEW |