| 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 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 m_orderIterator.first(); | 956 m_orderIterator.first(); |
| 957 for (LayoutBox* child = m_orderIterator.currentChild(); child; | 957 for (LayoutBox* child = m_orderIterator.currentChild(); child; |
| 958 child = m_orderIterator.next()) { | 958 child = m_orderIterator.next()) { |
| 959 | 959 |
| 960 if (child->isOutOfFlowPositioned()) { | 960 if (child->isOutOfFlowPositioned()) { |
| 961 // Out-of-flow children are not flex items, so we skip them here. | 961 // Out-of-flow children are not flex items, so we skip them here. |
| 962 prepareChildForPositionedLayout(*child); | 962 prepareChildForPositionedLayout(*child); |
| 963 continue; | 963 continue; |
| 964 } | 964 } |
| 965 | 965 |
| 966 allItems.append(constructFlexItem(*child, layoutType)); | 966 allItems.push_back(constructFlexItem(*child, layoutType)); |
| 967 } | 967 } |
| 968 | 968 |
| 969 const LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); | 969 const LayoutUnit lineBreakLength = mainAxisContentExtent(LayoutUnit::max()); |
| 970 FlexLayoutAlgorithm flexAlgorithm(style(), lineBreakLength, allItems); | 970 FlexLayoutAlgorithm flexAlgorithm(style(), lineBreakLength, allItems); |
| 971 LayoutUnit crossAxisOffset = | 971 LayoutUnit crossAxisOffset = |
| 972 flowAwareBorderBefore() + flowAwarePaddingBefore(); | 972 flowAwareBorderBefore() + flowAwarePaddingBefore(); |
| 973 Vector<FlexItem> lineItems; | 973 Vector<FlexItem> lineItems; |
| 974 size_t nextIndex = 0; | 974 size_t nextIndex = 0; |
| 975 while (flexAlgorithm.ComputeNextFlexLine( | 975 while (flexAlgorithm.ComputeNextFlexLine( |
| 976 nextIndex, lineItems, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, | 976 nextIndex, lineItems, sumFlexBaseSize, totalFlexGrow, totalFlexShrink, |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 DCHECK(!flexItem.frozen) << i; | 1413 DCHECK(!flexItem.frozen) << i; |
| 1414 float flexFactor = (flexSign == PositiveFlexibility) | 1414 float flexFactor = (flexSign == PositiveFlexibility) |
| 1415 ? child->style()->flexGrow() | 1415 ? child->style()->flexGrow() |
| 1416 : child->style()->flexShrink(); | 1416 : child->style()->flexShrink(); |
| 1417 if (flexFactor == 0 || | 1417 if (flexFactor == 0 || |
| 1418 (flexSign == PositiveFlexibility && | 1418 (flexSign == PositiveFlexibility && |
| 1419 flexItem.flexBaseContentSize > flexItem.hypotheticalMainContentSize) || | 1419 flexItem.flexBaseContentSize > flexItem.hypotheticalMainContentSize) || |
| 1420 (flexSign == NegativeFlexibility && | 1420 (flexSign == NegativeFlexibility && |
| 1421 flexItem.flexBaseContentSize < flexItem.hypotheticalMainContentSize)) { | 1421 flexItem.flexBaseContentSize < flexItem.hypotheticalMainContentSize)) { |
| 1422 flexItem.flexedContentSize = flexItem.hypotheticalMainContentSize; | 1422 flexItem.flexedContentSize = flexItem.hypotheticalMainContentSize; |
| 1423 newInflexibleItems.append(&flexItem); | 1423 newInflexibleItems.push_back(&flexItem); |
| 1424 } | 1424 } |
| 1425 } | 1425 } |
| 1426 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, | 1426 freezeViolations(newInflexibleItems, remainingFreeSpace, totalFlexGrow, |
| 1427 totalFlexShrink, totalWeightedFlexShrink); | 1427 totalFlexShrink, totalWeightedFlexShrink); |
| 1428 } | 1428 } |
| 1429 | 1429 |
| 1430 // Returns true if we successfully ran the algorithm and sized the flex items. | 1430 // Returns true if we successfully ran the algorithm and sized the flex items. |
| 1431 bool LayoutFlexibleBox::resolveFlexibleLengths( | 1431 bool LayoutFlexibleBox::resolveFlexibleLengths( |
| 1432 FlexSign flexSign, | 1432 FlexSign flexSign, |
| 1433 Vector<FlexItem>& children, | 1433 Vector<FlexItem>& children, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1474 childSize += LayoutUnit::fromFloatRound(extraSpace); | 1474 childSize += LayoutUnit::fromFloatRound(extraSpace); |
| 1475 | 1475 |
| 1476 LayoutUnit adjustedChildSize = | 1476 LayoutUnit adjustedChildSize = |
| 1477 adjustChildSizeForMinAndMax(*child, childSize); | 1477 adjustChildSizeForMinAndMax(*child, childSize); |
| 1478 DCHECK_GE(adjustedChildSize, 0); | 1478 DCHECK_GE(adjustedChildSize, 0); |
| 1479 flexItem.flexedContentSize = adjustedChildSize; | 1479 flexItem.flexedContentSize = adjustedChildSize; |
| 1480 usedFreeSpace += adjustedChildSize - flexItem.flexBaseContentSize; | 1480 usedFreeSpace += adjustedChildSize - flexItem.flexBaseContentSize; |
| 1481 | 1481 |
| 1482 LayoutUnit violation = adjustedChildSize - childSize; | 1482 LayoutUnit violation = adjustedChildSize - childSize; |
| 1483 if (violation > 0) | 1483 if (violation > 0) |
| 1484 minViolations.append(&flexItem); | 1484 minViolations.push_back(&flexItem); |
| 1485 else if (violation < 0) | 1485 else if (violation < 0) |
| 1486 maxViolations.append(&flexItem); | 1486 maxViolations.push_back(&flexItem); |
| 1487 totalViolation += violation; | 1487 totalViolation += violation; |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 if (totalViolation) | 1490 if (totalViolation) |
| 1491 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, | 1491 freezeViolations(totalViolation < 0 ? maxViolations : minViolations, |
| 1492 remainingFreeSpace, totalFlexGrow, totalFlexShrink, | 1492 remainingFreeSpace, totalFlexGrow, totalFlexShrink, |
| 1493 totalWeightedFlexShrink); | 1493 totalWeightedFlexShrink); |
| 1494 else | 1494 else |
| 1495 remainingFreeSpace -= usedFreeSpace; | 1495 remainingFreeSpace -= usedFreeSpace; |
| 1496 | 1496 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 if (style()->flexDirection() == FlowColumnReverse) { | 1885 if (style()->flexDirection() == FlowColumnReverse) { |
| 1886 // We have to do an extra pass for column-reverse to reposition the flex | 1886 // We have to do an extra pass for column-reverse to reposition the flex |
| 1887 // items since the start depends on the height of the flexbox, which we | 1887 // items since the start depends on the height of the flexbox, which we |
| 1888 // only know after we've positioned all the flex items. | 1888 // only know after we've positioned all the flex items. |
| 1889 updateLogicalHeight(); | 1889 updateLogicalHeight(); |
| 1890 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); | 1890 layoutColumnReverse(children, crossAxisOffset, availableFreeSpace); |
| 1891 } | 1891 } |
| 1892 | 1892 |
| 1893 if (m_numberOfInFlowChildrenOnFirstLine == -1) | 1893 if (m_numberOfInFlowChildrenOnFirstLine == -1) |
| 1894 m_numberOfInFlowChildrenOnFirstLine = children.size(); | 1894 m_numberOfInFlowChildrenOnFirstLine = children.size(); |
| 1895 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, | 1895 lineContexts.push_back(LineContext(crossAxisOffset, maxChildCrossAxisExtent, |
| 1896 maxAscent, std::move(children))); | 1896 maxAscent, std::move(children))); |
| 1897 crossAxisOffset += maxChildCrossAxisExtent; | 1897 crossAxisOffset += maxChildCrossAxisExtent; |
| 1898 } | 1898 } |
| 1899 | 1899 |
| 1900 void LayoutFlexibleBox::layoutColumnReverse(const Vector<FlexItem>& children, | 1900 void LayoutFlexibleBox::layoutColumnReverse(const Vector<FlexItem>& children, |
| 1901 LayoutUnit crossAxisOffset, | 1901 LayoutUnit crossAxisOffset, |
| 1902 LayoutUnit availableFreeSpace) { | 1902 LayoutUnit availableFreeSpace) { |
| 1903 ContentPosition position = styleRef().resolvedJustifyContentPosition( | 1903 ContentPosition position = styleRef().resolvedJustifyContentPosition( |
| 1904 contentAlignmentNormalBehavior()); | 1904 contentAlignmentNormalBehavior()); |
| 1905 ContentDistributionType distribution = | 1905 ContentDistributionType distribution = |
| 1906 styleRef().resolvedJustifyContentDistribution( | 1906 styleRef().resolvedJustifyContentDistribution( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 maxAscent, styleRef().flexWrap() == FlexWrapReverse); | 2056 maxAscent, styleRef().flexWrap() == FlexWrapReverse); |
| 2057 adjustAlignmentForChild(*flexItem.box, offset); | 2057 adjustAlignmentForChild(*flexItem.box, offset); |
| 2058 if (position == ItemPositionBaseline && | 2058 if (position == ItemPositionBaseline && |
| 2059 styleRef().flexWrap() == FlexWrapReverse) { | 2059 styleRef().flexWrap() == FlexWrapReverse) { |
| 2060 minMarginAfterBaseline = std::min( | 2060 minMarginAfterBaseline = std::min( |
| 2061 minMarginAfterBaseline, availableAlignmentSpaceForChild( | 2061 minMarginAfterBaseline, availableAlignmentSpaceForChild( |
| 2062 lineCrossAxisExtent, *flexItem.box) - | 2062 lineCrossAxisExtent, *flexItem.box) - |
| 2063 offset); | 2063 offset); |
| 2064 } | 2064 } |
| 2065 } | 2065 } |
| 2066 minMarginAfterBaselines.append(minMarginAfterBaseline); | 2066 minMarginAfterBaselines.push_back(minMarginAfterBaseline); |
| 2067 } | 2067 } |
| 2068 | 2068 |
| 2069 if (style()->flexWrap() != FlexWrapReverse) | 2069 if (style()->flexWrap() != FlexWrapReverse) |
| 2070 return; | 2070 return; |
| 2071 | 2071 |
| 2072 // wrap-reverse flips the cross axis start and end. For baseline alignment, | 2072 // wrap-reverse flips the cross axis start and end. For baseline alignment, |
| 2073 // this means we need to align the after edge of baseline elements with the | 2073 // this means we need to align the after edge of baseline elements with the |
| 2074 // after edge of the flex line. | 2074 // after edge of the flex line. |
| 2075 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) { | 2075 for (size_t lineNumber = 0; lineNumber < lineContexts.size(); ++lineNumber) { |
| 2076 const LineContext& lineContext = lineContexts[lineNumber]; | 2076 const LineContext& lineContext = lineContexts[lineNumber]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 LayoutUnit originalOffset = | 2183 LayoutUnit originalOffset = |
| 2184 lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 2184 lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
| 2185 LayoutUnit newOffset = | 2185 LayoutUnit newOffset = |
| 2186 contentExtent - originalOffset - lineCrossAxisExtent; | 2186 contentExtent - originalOffset - lineCrossAxisExtent; |
| 2187 adjustAlignmentForChild(*flexItem.box, newOffset - originalOffset); | 2187 adjustAlignmentForChild(*flexItem.box, newOffset - originalOffset); |
| 2188 } | 2188 } |
| 2189 } | 2189 } |
| 2190 } | 2190 } |
| 2191 | 2191 |
| 2192 } // namespace blink | 2192 } // namespace blink |
| OLD | NEW |