Chromium Code Reviews| 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 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 } | 1307 } |
| 1308 | 1308 |
| 1309 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout Unit childPreferredSize) | 1309 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout Unit childPreferredSize) |
| 1310 { | 1310 { |
| 1311 if (hasOrthogonalFlow(child)) | 1311 if (hasOrthogonalFlow(child)) |
| 1312 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA ndPaddingLogicalHeight()); | 1312 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA ndPaddingLogicalHeight()); |
| 1313 else | 1313 else |
| 1314 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn dPaddingLogicalWidth()); | 1314 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn dPaddingLogicalWidth()); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child, Layout Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode ) | 1317 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child) |
| 1318 { | |
| 1319 const LayoutUnit mainAxisExtent = mainAxisContentExtent(contentLogicalHeight ()); | |
| 1320 | |
| 1321 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior()); | |
| 1322 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior()); | |
| 1323 // TODO(cbiesinger): Support the other values for these properties (we're no t shipping them yet) | |
| 1324 // TODO(cbiesinger): what should row-reverse/column-reverse do? https://list s.w3.org/Archives/Public/www-style/2016Apr/0387.html | |
| 1325 switch (position) { | |
| 1326 case ContentPositionFlexEnd: | |
| 1327 return (mainAxisExtent - mainAxisExtentForChild(child)); | |
| 1328 case ContentPositionCenter: | |
| 1329 return (mainAxisExtent - mainAxisExtentForChild(child)) / 2; | |
| 1330 default: | |
| 1331 break; | |
| 1332 } | |
| 1333 switch (distribution) { | |
|
eae
2016/04/25 02:37:28
Probably easier to use a regular if statement here
cbiesinger
2016/04/26 18:21:56
I realized I can simplify this by reusing code, so
| |
| 1334 case ContentDistributionSpaceAround: | |
| 1335 return (mainAxisExtent - mainAxisExtentForChild(child)) / 2; | |
| 1336 default: | |
| 1337 break; | |
| 1338 } | |
| 1339 return LayoutUnit(); | |
| 1340 } | |
| 1341 | |
| 1342 LayoutUnit LayoutFlexibleBox::staticCrossAxisPositionForPositionedChild(const La youtBox& child) | |
| 1343 { | |
| 1344 switch (alignmentForChild(child)) { | |
| 1345 case ItemPositionAuto: | |
| 1346 case ItemPositionStretch: | |
| 1347 return LayoutUnit(); // static position is unaffected by stretching | |
| 1348 case ItemPositionBaseline: | |
| 1349 case ItemPositionLastBaseline: | |
| 1350 return LayoutUnit(); | |
| 1351 case ItemPositionCenter: | |
| 1352 return (crossAxisContentExtent() - crossAxisExtentForChild(child)) / 2; | |
| 1353 case ItemPositionStart: | |
| 1354 case ItemPositionFlexStart: | |
| 1355 // These are equivalent here because alignmentForChild maps | |
| 1356 // flex-start to flex-end when they would be different. | |
| 1357 return LayoutUnit(); | |
| 1358 case ItemPositionEnd: | |
| 1359 case ItemPositionFlexEnd: | |
| 1360 return (crossAxisContentExtent() - crossAxisExtentForChild(child)); | |
| 1361 case ItemPositionSelfStart: | |
| 1362 // TODO(cbiesinger): Support this value (not shipped yet) | |
| 1363 return LayoutUnit(); | |
| 1364 case ItemPositionSelfEnd: | |
| 1365 // TODO(cbiesinger): Support this value (not shipped yet) | |
| 1366 return LayoutUnit(); | |
| 1367 case ItemPositionLeft: | |
| 1368 if (!isHorizontalFlow()) | |
| 1369 return LayoutUnit(); | |
| 1370 if (styleRef().isLeftToRightDirection()) | |
| 1371 return LayoutUnit(); | |
| 1372 return (crossAxisContentExtent() - crossAxisExtentForChild(child)); | |
| 1373 case ItemPositionRight: | |
| 1374 if (!isHorizontalFlow()) | |
| 1375 return LayoutUnit(); | |
| 1376 if (!styleRef().isLeftToRightDirection()) | |
| 1377 return LayoutUnit(); | |
| 1378 return (crossAxisContentExtent() - crossAxisExtentForChild(child)); | |
| 1379 } | |
| 1380 return LayoutUnit(); | |
| 1381 } | |
| 1382 | |
| 1383 LayoutUnit LayoutFlexibleBox::staticInlinePositionForPositionedChild(const Layou tBox& child) | |
| 1384 { | |
| 1385 LayoutUnit staticInlineOffset = flowAwareBorderStart() + flowAwarePaddingSta rt(); | |
| 1386 if (isColumnFlow()) | |
|
eae
2016/04/25 02:37:28
(optional) There is a bit of code duplication here
cbiesinger
2016/04/26 18:21:56
I like the second idea, thanks! Changed, modulo so
| |
| 1387 return staticInlineOffset + staticCrossAxisPositionForPositionedChild(ch ild); | |
| 1388 return staticInlineOffset + staticMainAxisPositionForPositionedChild(child); | |
| 1389 } | |
| 1390 | |
| 1391 LayoutUnit LayoutFlexibleBox::staticBlockPositionForPositionedChild(const Layout Box& child) | |
| 1392 { | |
| 1393 LayoutUnit staticBlockOffset = flowAwareBorderBefore() + flowAwarePaddingBef ore(); | |
| 1394 if (isColumnFlow()) | |
| 1395 return staticBlockOffset + staticMainAxisPositionForPositionedChild(chil d); | |
| 1396 return staticBlockOffset + staticCrossAxisPositionForPositionedChild(child); | |
| 1397 } | |
| 1398 | |
| 1399 bool LayoutFlexibleBox::setStaticPositionForPositionedLayout(LayoutBox& child) | |
| 1400 { | |
| 1401 bool positionChanged = false; | |
| 1402 PaintLayer* childLayer = child.layer(); | |
| 1403 if (child.styleRef().hasStaticInlinePosition(styleRef().isHorizontalWritingM ode())) { | |
| 1404 LayoutUnit inlinePosition = staticInlinePositionForPositionedChild(child ); | |
| 1405 if (childLayer->staticInlinePosition() != inlinePosition) { | |
| 1406 childLayer->setStaticInlinePosition(inlinePosition); | |
| 1407 positionChanged = true; | |
| 1408 } | |
| 1409 } | |
| 1410 if (child.styleRef().hasStaticBlockPosition(styleRef().isHorizontalWritingMo de())) { | |
| 1411 LayoutUnit blockPosition = staticBlockPositionForPositionedChild(child); | |
| 1412 if (childLayer->staticBlockPosition() != blockPosition) { | |
| 1413 childLayer->setStaticBlockPosition(blockPosition); | |
| 1414 positionChanged = true; | |
| 1415 } | |
| 1416 } | |
| 1417 return positionChanged; | |
| 1418 } | |
| 1419 | |
| 1420 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child) | |
| 1318 { | 1421 { |
| 1319 ASSERT(child.isOutOfFlowPositioned()); | 1422 ASSERT(child.isOutOfFlowPositioned()); |
| 1320 child.containingBlock()->insertPositionedObject(&child); | 1423 child.containingBlock()->insertPositionedObject(&child); |
| 1321 PaintLayer* childLayer = child.layer(); | 1424 PaintLayer* childLayer = child.layer(); |
| 1322 LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffse t; | 1425 LayoutUnit staticInlinePosition = flowAwareBorderStart() + flowAwarePaddingS tart(); |
| 1323 if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowRe verse) | 1426 if (childLayer->staticInlinePosition() != staticInlinePosition) { |
| 1324 inlinePosition = mainAxisExtent() - mainAxisOffset; | 1427 childLayer->setStaticInlinePosition(staticInlinePosition); |
| 1325 childLayer->setStaticInlinePosition(inlinePosition); | 1428 if (child.style()->hasStaticInlinePosition(style()->isHorizontalWritingM ode())) |
| 1429 child.setChildNeedsLayout(MarkOnlyThis); | |
| 1430 } | |
| 1326 | 1431 |
| 1327 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis Offset; | 1432 LayoutUnit staticBlockPosition = flowAwareBorderBefore() + flowAwarePaddingB efore(); |
| 1328 if (childLayer->staticBlockPosition() != staticBlockPosition) { | 1433 if (childLayer->staticBlockPosition() != staticBlockPosition) { |
| 1329 childLayer->setStaticBlockPosition(staticBlockPosition); | 1434 childLayer->setStaticBlockPosition(staticBlockPosition); |
| 1330 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de())) | 1435 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de())) |
| 1331 child.setChildNeedsLayout(MarkOnlyThis); | 1436 child.setChildNeedsLayout(MarkOnlyThis); |
| 1332 } | 1437 } |
| 1333 } | 1438 } |
| 1334 | 1439 |
| 1335 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const | 1440 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const |
| 1336 { | 1441 { |
| 1337 ItemPosition align = ComputedStyle::resolveAlignment(styleRef(), child.style Ref(), ItemPositionStretch); | 1442 ItemPosition align = ComputedStyle::resolveAlignment(styleRef(), child.style Ref(), ItemPositionStretch); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 | 1544 |
| 1440 LayoutUnit totalMainExtent = mainAxisExtent(); | 1545 LayoutUnit totalMainExtent = mainAxisExtent(); |
| 1441 LayoutUnit maxAscent, maxDescent; // Used when align-items: baseline. | 1546 LayoutUnit maxAscent, maxDescent; // Used when align-items: baseline. |
| 1442 LayoutUnit maxChildCrossAxisExtent; | 1547 LayoutUnit maxChildCrossAxisExtent; |
| 1443 size_t seenInFlowPositionedChildren = 0; | 1548 size_t seenInFlowPositionedChildren = 0; |
| 1444 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); | 1549 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); |
| 1445 for (size_t i = 0; i < children.size(); ++i) { | 1550 for (size_t i = 0; i < children.size(); ++i) { |
| 1446 LayoutBox* child = children[i]; | 1551 LayoutBox* child = children[i]; |
| 1447 | 1552 |
| 1448 if (child->isOutOfFlowPositioned()) { | 1553 if (child->isOutOfFlowPositioned()) { |
| 1449 prepareChildForPositionedLayout(*child, mainAxisOffset, crossAxisOff set, FlipForRowReverse); | 1554 prepareChildForPositionedLayout(*child); |
| 1450 continue; | 1555 continue; |
| 1451 } | 1556 } |
| 1452 | 1557 |
| 1453 // FIXME Investigate if this can be removed based on other flags. crbug. com/370010 | 1558 // FIXME Investigate if this can be removed based on other flags. crbug. com/370010 |
| 1454 child->setMayNeedPaintInvalidation(); | 1559 child->setMayNeedPaintInvalidation(); |
| 1455 | 1560 |
| 1456 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding ExtentForChild(*child); | 1561 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding ExtentForChild(*child); |
| 1457 setOverrideMainAxisSizeForChild(*child, childPreferredSize); | 1562 setOverrideMainAxisSizeForChild(*child, childPreferredSize); |
| 1458 if (childPreferredSize != mainAxisExtentForChild(*child)) { | 1563 if (childPreferredSize != mainAxisExtentForChild(*child)) { |
| 1459 child->setChildNeedsLayout(MarkOnlyThis); | 1564 child->setChildNeedsLayout(MarkOnlyThis); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 // just moving the children to a new position. | 1642 // just moving the children to a new position. |
| 1538 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); | 1643 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); |
| 1539 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd(); | 1644 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd(); |
| 1540 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent); | 1645 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent); |
| 1541 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight(); | 1646 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight(); |
| 1542 | 1647 |
| 1543 size_t seenInFlowPositionedChildren = 0; | 1648 size_t seenInFlowPositionedChildren = 0; |
| 1544 for (size_t i = 0; i < children.size(); ++i) { | 1649 for (size_t i = 0; i < children.size(); ++i) { |
| 1545 LayoutBox* child = children[i]; | 1650 LayoutBox* child = children[i]; |
| 1546 | 1651 |
| 1547 if (child->isOutOfFlowPositioned()) { | 1652 if (child->isOutOfFlowPositioned()) |
| 1548 child->layer()->setStaticBlockPosition(mainAxisOffset); | |
| 1549 continue; | 1653 continue; |
| 1550 } | 1654 |
| 1551 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor Child(*child); | 1655 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor Child(*child); |
| 1552 | 1656 |
| 1553 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx isOffset + flowAwareMarginBeforeForChild(*child))); | 1657 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx isOffset + flowAwareMarginBeforeForChild(*child))); |
| 1554 | 1658 |
| 1555 mainAxisOffset -= flowAwareMarginStartForChild(*child); | 1659 mainAxisOffset -= flowAwareMarginStartForChild(*child); |
| 1556 | 1660 |
| 1557 ++seenInFlowPositionedChildren; | 1661 ++seenInFlowPositionedChildren; |
| 1558 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) | 1662 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) |
| 1559 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp ace, distribution, numberOfChildrenForJustifyContent); | 1663 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp ace, distribution, numberOfChildrenForJustifyContent); |
| 1560 } | 1664 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1617 | 1721 |
| 1618 if (distribution == ContentDistributionStretch && availableCrossAxisSpac e > 0) | 1722 if (distribution == ContentDistributionStretch && availableCrossAxisSpac e > 0) |
| 1619 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size()); | 1723 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size()); |
| 1620 | 1724 |
| 1621 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, distribution, lineContexts.size()); | 1725 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, distribution, lineContexts.size()); |
| 1622 } | 1726 } |
| 1623 } | 1727 } |
| 1624 | 1728 |
| 1625 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta) | 1729 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta) |
| 1626 { | 1730 { |
| 1627 if (child.isOutOfFlowPositioned()) { | 1731 if (child.isOutOfFlowPositioned()) |
| 1628 LayoutUnit staticInlinePosition = child.layer()->staticInlinePosition(); | |
| 1629 LayoutUnit staticBlockPosition = child.layer()->staticBlockPosition(); | |
| 1630 LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlin ePosition; | |
| 1631 LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlo ckPosition; | |
| 1632 crossAxis += delta; | |
| 1633 prepareChildForPositionedLayout(child, mainAxis, crossAxis, NoFlipForRow Reverse); | |
| 1634 return; | 1732 return; |
| 1635 } | |
| 1636 | 1733 |
| 1637 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta)); | 1734 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta)); |
| 1638 } | 1735 } |
| 1639 | 1736 |
| 1640 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) | 1737 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) |
| 1641 { | 1738 { |
| 1642 // Keep track of the space between the baseline edge and the after edge of t he box for each line. | 1739 // Keep track of the space between the baseline edge and the after edge of t he box for each line. |
| 1643 Vector<LayoutUnit> minMarginAfterBaselines; | 1740 Vector<LayoutUnit> minMarginAfterBaselines; |
| 1644 | 1741 |
| 1645 LayoutBox* child = m_orderIterator.first(); | 1742 LayoutBox* child = m_orderIterator.first(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 ASSERT(child); | 1882 ASSERT(child); |
| 1786 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; | 1883 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; |
| 1787 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; | 1884 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; |
| 1788 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; | 1885 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; |
| 1789 adjustAlignmentForChild(*child, newOffset - originalOffset); | 1886 adjustAlignmentForChild(*child, newOffset - originalOffset); |
| 1790 } | 1887 } |
| 1791 } | 1888 } |
| 1792 } | 1889 } |
| 1793 | 1890 |
| 1794 } // namespace blink | 1891 } // namespace blink |
| OLD | NEW |