Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutFlexibleBox.cpp

Issue 1920453003: [css-flexbox] Implement new abspos handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 } 1347 }
1348 1348
1349 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout Unit childPreferredSize) 1349 void LayoutFlexibleBox::setOverrideMainAxisSizeForChild(LayoutBox& child, Layout Unit childPreferredSize)
1350 { 1350 {
1351 if (hasOrthogonalFlow(child)) 1351 if (hasOrthogonalFlow(child))
1352 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA ndPaddingLogicalHeight()); 1352 child.setOverrideLogicalContentHeight(childPreferredSize - child.borderA ndPaddingLogicalHeight());
1353 else 1353 else
1354 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn dPaddingLogicalWidth()); 1354 child.setOverrideLogicalContentWidth(childPreferredSize - child.borderAn dPaddingLogicalWidth());
1355 } 1355 }
1356 1356
1357 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child, Layout Unit mainAxisOffset, LayoutUnit crossAxisOffset, PositionedLayoutMode layoutMode ) 1357 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child)
1358 {
1359 const LayoutUnit availableSpace = mainAxisContentExtent(contentLogicalHeight ()) - mainAxisExtentForChild(child);
1360
1361 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior());
1362 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior());
1363 // TODO(cbiesinger): what should row-reverse/column-reverse do? https://list s.w3.org/Archives/Public/www-style/2016Apr/0387.html
1364 return initialJustifyContentOffset(availableSpace, position, distribution, 1 );
1365 }
1366
1367 LayoutUnit LayoutFlexibleBox::staticCrossAxisPositionForPositionedChild(const La youtBox& child)
1368 {
1369 LayoutUnit availableSpace = crossAxisContentExtent() - crossAxisExtentForChi ld(child);
1370 return alignmentOffset(availableSpace, alignmentForChild(child), LayoutUnit( ), LayoutUnit(), styleRef().flexWrap() == FlexWrapReverse);
1371 }
1372
1373 LayoutUnit LayoutFlexibleBox::staticInlinePositionForPositionedChild(const Layou tBox& child)
1374 {
1375 LayoutUnit staticInlineOffset = flowAwareBorderStart() + flowAwarePaddingSta rt();
1376 return staticInlineOffset + (isColumnFlow() ?
1377 staticCrossAxisPositionForPositionedChild(child) :
1378 staticMainAxisPositionForPositionedChild(child));
1379 }
1380
1381 LayoutUnit LayoutFlexibleBox::staticBlockPositionForPositionedChild(const Layout Box& child)
1382 {
1383 LayoutUnit staticBlockOffset = flowAwareBorderBefore() + flowAwarePaddingBef ore();
1384 return staticBlockOffset + (isColumnFlow() ?
1385 staticMainAxisPositionForPositionedChild(child) :
1386 staticCrossAxisPositionForPositionedChild(child));
1387 }
1388
1389 bool LayoutFlexibleBox::setStaticPositionForPositionedLayout(LayoutBox& child)
1390 {
1391 bool positionChanged = false;
1392 PaintLayer* childLayer = child.layer();
1393 if (child.styleRef().hasStaticInlinePosition(styleRef().isHorizontalWritingM ode())) {
1394 LayoutUnit inlinePosition = staticInlinePositionForPositionedChild(child );
1395 if (childLayer->staticInlinePosition() != inlinePosition) {
1396 childLayer->setStaticInlinePosition(inlinePosition);
1397 positionChanged = true;
1398 }
1399 }
1400 if (child.styleRef().hasStaticBlockPosition(styleRef().isHorizontalWritingMo de())) {
1401 LayoutUnit blockPosition = staticBlockPositionForPositionedChild(child);
1402 if (childLayer->staticBlockPosition() != blockPosition) {
1403 childLayer->setStaticBlockPosition(blockPosition);
1404 positionChanged = true;
1405 }
1406 }
1407 return positionChanged;
1408 }
1409
1410 void LayoutFlexibleBox::prepareChildForPositionedLayout(LayoutBox& child)
1358 { 1411 {
1359 ASSERT(child.isOutOfFlowPositioned()); 1412 ASSERT(child.isOutOfFlowPositioned());
1360 child.containingBlock()->insertPositionedObject(&child); 1413 child.containingBlock()->insertPositionedObject(&child);
1361 PaintLayer* childLayer = child.layer(); 1414 PaintLayer* childLayer = child.layer();
1362 LayoutUnit inlinePosition = isColumnFlow() ? crossAxisOffset : mainAxisOffse t; 1415 LayoutUnit staticInlinePosition = flowAwareBorderStart() + flowAwarePaddingS tart();
1363 if (layoutMode == FlipForRowReverse && style()->flexDirection() == FlowRowRe verse) 1416 if (childLayer->staticInlinePosition() != staticInlinePosition) {
1364 inlinePosition = mainAxisExtent() - mainAxisOffset; 1417 childLayer->setStaticInlinePosition(staticInlinePosition);
1365 childLayer->setStaticInlinePosition(inlinePosition); 1418 if (child.style()->hasStaticInlinePosition(style()->isHorizontalWritingM ode()))
1419 child.setChildNeedsLayout(MarkOnlyThis);
1420 }
1366 1421
1367 LayoutUnit staticBlockPosition = isColumnFlow() ? mainAxisOffset : crossAxis Offset; 1422 LayoutUnit staticBlockPosition = flowAwareBorderBefore() + flowAwarePaddingB efore();
1368 if (childLayer->staticBlockPosition() != staticBlockPosition) { 1423 if (childLayer->staticBlockPosition() != staticBlockPosition) {
1369 childLayer->setStaticBlockPosition(staticBlockPosition); 1424 childLayer->setStaticBlockPosition(staticBlockPosition);
1370 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de())) 1425 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de()))
1371 child.setChildNeedsLayout(MarkOnlyThis); 1426 child.setChildNeedsLayout(MarkOnlyThis);
1372 } 1427 }
1373 } 1428 }
1374 1429
1375 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const 1430 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const
1376 { 1431 {
1377 ItemPosition align = ComputedStyle::resolveAlignment(styleRef(), child.style Ref(), ItemPositionStretch); 1432 ItemPosition align = ComputedStyle::resolveAlignment(styleRef(), child.style Ref(), ItemPositionStretch);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 1534
1480 LayoutUnit totalMainExtent = mainAxisExtent(); 1535 LayoutUnit totalMainExtent = mainAxisExtent();
1481 LayoutUnit maxAscent, maxDescent; // Used when align-items: baseline. 1536 LayoutUnit maxAscent, maxDescent; // Used when align-items: baseline.
1482 LayoutUnit maxChildCrossAxisExtent; 1537 LayoutUnit maxChildCrossAxisExtent;
1483 size_t seenInFlowPositionedChildren = 0; 1538 size_t seenInFlowPositionedChildren = 0;
1484 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow(); 1539 bool shouldFlipMainAxis = !isColumnFlow() && !isLeftToRightFlow();
1485 for (size_t i = 0; i < children.size(); ++i) { 1540 for (size_t i = 0; i < children.size(); ++i) {
1486 LayoutBox* child = children[i]; 1541 LayoutBox* child = children[i];
1487 1542
1488 if (child->isOutOfFlowPositioned()) { 1543 if (child->isOutOfFlowPositioned()) {
1489 prepareChildForPositionedLayout(*child, mainAxisOffset, crossAxisOff set, FlipForRowReverse); 1544 prepareChildForPositionedLayout(*child);
1490 continue; 1545 continue;
1491 } 1546 }
1492 1547
1493 // FIXME Investigate if this can be removed based on other flags. crbug. com/370010 1548 // FIXME Investigate if this can be removed based on other flags. crbug. com/370010
1494 child->setMayNeedPaintInvalidation(); 1549 child->setMayNeedPaintInvalidation();
1495 1550
1496 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding ExtentForChild(*child); 1551 LayoutUnit childPreferredSize = childSizes[i] + mainAxisBorderAndPadding ExtentForChild(*child);
1497 setOverrideMainAxisSizeForChild(*child, childPreferredSize); 1552 setOverrideMainAxisSizeForChild(*child, childPreferredSize);
1498 if (childPreferredSize != mainAxisExtentForChild(*child)) { 1553 if (childPreferredSize != mainAxisExtentForChild(*child)) {
1499 child->setChildNeedsLayout(MarkOnlyThis); 1554 child->setChildNeedsLayout(MarkOnlyThis);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 // just moving the children to a new position. 1632 // just moving the children to a new position.
1578 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1633 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1579 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd(); 1634 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd();
1580 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent); 1635 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent);
1581 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight(); 1636 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight();
1582 1637
1583 size_t seenInFlowPositionedChildren = 0; 1638 size_t seenInFlowPositionedChildren = 0;
1584 for (size_t i = 0; i < children.size(); ++i) { 1639 for (size_t i = 0; i < children.size(); ++i) {
1585 LayoutBox* child = children[i]; 1640 LayoutBox* child = children[i];
1586 1641
1587 if (child->isOutOfFlowPositioned()) { 1642 if (child->isOutOfFlowPositioned())
1588 child->layer()->setStaticBlockPosition(mainAxisOffset);
1589 continue; 1643 continue;
1590 } 1644
1591 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor Child(*child); 1645 mainAxisOffset -= mainAxisExtentForChild(*child) + flowAwareMarginEndFor Child(*child);
1592 1646
1593 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx isOffset + flowAwareMarginBeforeForChild(*child))); 1647 setFlowAwareLocationForChild(*child, LayoutPoint(mainAxisOffset, crossAx isOffset + flowAwareMarginBeforeForChild(*child)));
1594 1648
1595 mainAxisOffset -= flowAwareMarginStartForChild(*child); 1649 mainAxisOffset -= flowAwareMarginStartForChild(*child);
1596 1650
1597 ++seenInFlowPositionedChildren; 1651 ++seenInFlowPositionedChildren;
1598 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent) 1652 if (seenInFlowPositionedChildren < numberOfChildrenForJustifyContent)
1599 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp ace, distribution, numberOfChildrenForJustifyContent); 1653 mainAxisOffset -= justifyContentSpaceBetweenChildren(availableFreeSp ace, distribution, numberOfChildrenForJustifyContent);
1600 } 1654 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 1711
1658 if (distribution == ContentDistributionStretch && availableCrossAxisSpac e > 0) 1712 if (distribution == ContentDistributionStretch && availableCrossAxisSpac e > 0)
1659 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size()); 1713 lineContexts[lineNumber].crossAxisExtent += availableCrossAxisSpace / static_cast<unsigned>(lineContexts.size());
1660 1714
1661 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, distribution, lineContexts.size()); 1715 lineOffset += alignContentSpaceBetweenChildren(availableCrossAxisSpace, distribution, lineContexts.size());
1662 } 1716 }
1663 } 1717 }
1664 1718
1665 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta) 1719 void LayoutFlexibleBox::adjustAlignmentForChild(LayoutBox& child, LayoutUnit del ta)
1666 { 1720 {
1667 if (child.isOutOfFlowPositioned()) { 1721 if (child.isOutOfFlowPositioned())
1668 LayoutUnit staticInlinePosition = child.layer()->staticInlinePosition();
1669 LayoutUnit staticBlockPosition = child.layer()->staticBlockPosition();
1670 LayoutUnit mainAxis = isColumnFlow() ? staticBlockPosition : staticInlin ePosition;
1671 LayoutUnit crossAxis = isColumnFlow() ? staticInlinePosition : staticBlo ckPosition;
1672 crossAxis += delta;
1673 prepareChildForPositionedLayout(child, mainAxis, crossAxis, NoFlipForRow Reverse);
1674 return; 1722 return;
1675 }
1676 1723
1677 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta)); 1724 setFlowAwareLocationForChild(child, flowAwareLocationForChild(child) + Layou tSize(LayoutUnit(), delta));
1678 } 1725 }
1679 1726
1680 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts) 1727 void LayoutFlexibleBox::alignChildren(const Vector<LineContext>& lineContexts)
1681 { 1728 {
1682 // Keep track of the space between the baseline edge and the after edge of t he box for each line. 1729 // Keep track of the space between the baseline edge and the after edge of t he box for each line.
1683 Vector<LayoutUnit> minMarginAfterBaselines; 1730 Vector<LayoutUnit> minMarginAfterBaselines;
1684 1731
1685 LayoutBox* child = m_orderIterator.first(); 1732 LayoutBox* child = m_orderIterator.first();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 ASSERT(child); 1838 ASSERT(child);
1792 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1839 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1793 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1840 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1794 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1841 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1795 adjustAlignmentForChild(*child, newOffset - originalOffset); 1842 adjustAlignmentForChild(*child, newOffset - originalOffset);
1796 } 1843 }
1797 } 1844 }
1798 } 1845 }
1799 1846
1800 } // namespace blink 1847 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698