| 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 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 { | 1299 { |
| 1300 if (availableFreeSpace > 0 && numberOfChildren > 1) { | 1300 if (availableFreeSpace > 0 && numberOfChildren > 1) { |
| 1301 if (justifyContentDistribution == ContentDistributionSpaceBetween) | 1301 if (justifyContentDistribution == ContentDistributionSpaceBetween) |
| 1302 return availableFreeSpace / (numberOfChildren - 1); | 1302 return availableFreeSpace / (numberOfChildren - 1); |
| 1303 if (justifyContentDistribution == ContentDistributionSpaceAround) | 1303 if (justifyContentDistribution == ContentDistributionSpaceAround) |
| 1304 return availableFreeSpace / numberOfChildren; | 1304 return availableFreeSpace / numberOfChildren; |
| 1305 } | 1305 } |
| 1306 return LayoutUnit(); | 1306 return LayoutUnit(); |
| 1307 } | 1307 } |
| 1308 | 1308 |
| 1309 static LayoutUnit alignmentOffset(LayoutUnit availableFreeSpace, ItemPosition po
sition, LayoutUnit ascent, LayoutUnit maxAscent, bool isWrapReverse) |
| 1310 { |
| 1311 switch (position) { |
| 1312 case ItemPositionAuto: |
| 1313 ASSERT_NOT_REACHED(); |
| 1314 break; |
| 1315 case ItemPositionStretch: |
| 1316 // Actual stretching must be handled by the caller. |
| 1317 // Since wrap-reverse flips cross start and cross end, stretch children
should be aligned with the cross end. |
| 1318 // This matters because applyStretchAlignment doesn't always stretch or
stretch fully (explicit cross size given, |
| 1319 // or stretching constrained by max-height/max-width). |
| 1320 // For flex-start and flex-end this is handled by alignmentForChild(). |
| 1321 if (isWrapReverse) |
| 1322 return availableFreeSpace; |
| 1323 break; |
| 1324 case ItemPositionFlexStart: |
| 1325 break; |
| 1326 case ItemPositionFlexEnd: |
| 1327 return availableFreeSpace; |
| 1328 case ItemPositionCenter: |
| 1329 return availableFreeSpace / 2; |
| 1330 case ItemPositionBaseline: |
| 1331 // FIXME: If we get here in columns, we want the use the descent, except
we currently can't get the ascent/descent of orthogonal children. |
| 1332 // https://bugs.webkit.org/show_bug.cgi?id=98076 |
| 1333 return maxAscent - ascent; |
| 1334 case ItemPositionLastBaseline: |
| 1335 case ItemPositionSelfStart: |
| 1336 case ItemPositionSelfEnd: |
| 1337 case ItemPositionStart: |
| 1338 case ItemPositionEnd: |
| 1339 case ItemPositionLeft: |
| 1340 case ItemPositionRight: |
| 1341 // FIXME: Implement these (https://crbug.com/507690). The extended gramm
ar |
| 1342 // is not enabled by default so we shouldn't hit this codepath. |
| 1343 ASSERT_NOT_REACHED(); |
| 1344 break; |
| 1345 } |
| 1346 return LayoutUnit(); |
| 1347 } |
| 1348 |
| 1309 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout
Unit childPreferredSize) | 1349 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout
Unit childPreferredSize) |
| 1310 { | 1350 { |
| 1311 if (hasOrthogonalFlow(child)) | 1351 if (hasOrthogonalFlow(child)) |
| 1312 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); | 1352 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA
ndPaddingLogicalHeight()); |
| 1313 else | 1353 else |
| 1314 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn
dPaddingLogicalWidth()); | 1354 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn
dPaddingLogicalWidth()); |
| 1315 } | 1355 } |
| 1316 | 1356 |
| 1317 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child, Layout
Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode
) | 1357 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child, Layout
Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode
) |
| 1318 { | 1358 { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1652 ASSERT(child); | 1692 ASSERT(child); |
| 1653 if (child->isOutOfFlowPositioned()) { | 1693 if (child->isOutOfFlowPositioned()) { |
| 1654 if (style()->flexWrap() == FlexWrapReverse) | 1694 if (style()->flexWrap() == FlexWrapReverse) |
| 1655 adjustAlignmentForChild(*child, lineCrossAxisExtent); | 1695 adjustAlignmentForChild(*child, lineCrossAxisExtent); |
| 1656 continue; | 1696 continue; |
| 1657 } | 1697 } |
| 1658 | 1698 |
| 1659 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, *child)))) | 1699 if (updateAutoMarginsInCrossAxis(*child, std::max(LayoutUnit(), avai
lableAlignmentSpaceForChild(lineCrossAxisExtent, *child)))) |
| 1660 continue; | 1700 continue; |
| 1661 | 1701 |
| 1662 switch (alignmentForChild(*child)) { | 1702 ItemPosition position = alignmentForChild(*child); |
| 1663 case ItemPositionAuto: | 1703 if (position == ItemPositionStretch) |
| 1664 ASSERT_NOT_REACHED(); | |
| 1665 break; | |
| 1666 case ItemPositionStretch: { | |
| 1667 applyStretchAlignmentToChild(*child, lineCrossAxisExtent); | 1704 applyStretchAlignmentToChild(*child, lineCrossAxisExtent); |
| 1668 // Since wrap-reverse flips cross start and cross end, strech ch
ildren should be aligned with the cross end. | 1705 LayoutUnit availableSpace = availableAlignmentSpaceForChild(lineCros
sAxisExtent, *child); |
| 1669 if (style()->flexWrap() == FlexWrapReverse) | 1706 LayoutUnit offset = alignmentOffset(availableSpace, position, margin
BoxAscentForChild(*child), maxAscent, styleRef().flexWrap() == FlexWrapReverse); |
| 1670 adjustAlignmentForChild(*child, availableAlignmentSpaceForCh
ild(lineCrossAxisExtent, *child)); | 1707 adjustAlignmentForChild(*child, offset); |
| 1671 break; | 1708 if (position == ItemPositionBaseline && styleRef().flexWrap() == Fle
xWrapReverse) |
| 1672 } | 1709 minMarginAfterBaseline = std::min(minMarginAfterBaseline, availa
bleAlignmentSpaceForChild(lineCrossAxisExtent, *child) - offset); |
| 1673 case ItemPositionFlexStart: | |
| 1674 break; | |
| 1675 case ItemPositionFlexEnd: | |
| 1676 adjustAlignmentForChild(*child, availableAlignmentSpaceForChild(
lineCrossAxisExtent, *child)); | |
| 1677 break; | |
| 1678 case ItemPositionCenter: | |
| 1679 adjustAlignmentForChild(*child, availableAlignmentSpaceForChild(
lineCrossAxisExtent, *child) / 2); | |
| 1680 break; | |
| 1681 case ItemPositionBaseline: { | |
| 1682 // FIXME: If we get here in columns, we want the use the descent
, except we currently can't get the ascent/descent of orthogonal children. | |
| 1683 // https://bugs.webkit.org/show_bug.cgi?id=98076 | |
| 1684 LayoutUnit ascent = marginBoxAscentForChild(*child); | |
| 1685 LayoutUnit startOffset = maxAscent - ascent; | |
| 1686 adjustAlignmentForChild(*child, startOffset); | |
| 1687 | |
| 1688 if (style()->flexWrap() == FlexWrapReverse) | |
| 1689 minMarginAfterBaseline = std::min(minMarginAfterBaseline, av
ailableAlignmentSpaceForChild(lineCrossAxisExtent, *child) - startOffset); | |
| 1690 break; | |
| 1691 } | |
| 1692 case ItemPositionLastBaseline: | |
| 1693 case ItemPositionSelfStart: | |
| 1694 case ItemPositionSelfEnd: | |
| 1695 case ItemPositionStart: | |
| 1696 case ItemPositionEnd: | |
| 1697 case ItemPositionLeft: | |
| 1698 case ItemPositionRight: | |
| 1699 // FIXME: Implement these (https://crbug.com/507690). The extend
ed grammar | |
| 1700 // is not enabled by default so we shouldn't hit this codepath. | |
| 1701 ASSERT_NOT_REACHED(); | |
| 1702 break; | |
| 1703 } | |
| 1704 } | 1710 } |
| 1705 minMarginAfterBaselines.append(minMarginAfterBaseline); | 1711 minMarginAfterBaselines.append(minMarginAfterBaseline); |
| 1706 } | 1712 } |
| 1707 | 1713 |
| 1708 if (style()->flexWrap() != FlexWrapReverse) | 1714 if (style()->flexWrap() != FlexWrapReverse) |
| 1709 return; | 1715 return; |
| 1710 | 1716 |
| 1711 // wrap-reverse flips the cross axis start and end. For baseline alignment,
this means we | 1717 // wrap-reverse flips the cross axis start and end. For baseline alignment,
this means we |
| 1712 // need to align the after edge of baseline elements with the after edge of
the flex line. | 1718 // need to align the after edge of baseline elements with the after edge of
the flex line. |
| 1713 child = m_orderIterator.first(); | 1719 child = m_orderIterator.first(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 ASSERT(child); | 1791 ASSERT(child); |
| 1786 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; | 1792 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE
xtent; |
| 1787 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; | 1793 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset
- crossAxisStartEdge; |
| 1788 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; | 1794 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi
sExtent; |
| 1789 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1795 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1790 } | 1796 } |
| 1791 } | 1797 } |
| 1792 } | 1798 } |
| 1793 | 1799 |
| 1794 } // namespace blink | 1800 } // namespace blink |
| OLD | NEW |