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

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

Issue 1709963002: [css-align] New CSS Value 'normal' for Self Alignment (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Getting back the FullScreen fix, missed during the rebase. Created 4 years, 4 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
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 int LayoutFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di rection, LinePositionMode mode) const 201 int LayoutFlexibleBox::baselinePosition(FontBaseline, bool, LineDirectionMode di rection, LinePositionMode mode) const
202 { 202 {
203 DCHECK_EQ(mode, PositionOnContainingLine); 203 DCHECK_EQ(mode, PositionOnContainingLine);
204 int baseline = firstLineBoxBaseline(); 204 int baseline = firstLineBoxBaseline();
205 if (baseline == -1) 205 if (baseline == -1)
206 baseline = synthesizedBaselineFromContentBox(*this, direction); 206 baseline = synthesizedBaselineFromContentBox(*this, direction);
207 207
208 return beforeMarginInLineDirection(direction) + baseline; 208 return beforeMarginInLineDirection(direction) + baseline;
209 } 209 }
210 210
211 static const StyleContentAlignmentData& normalValueBehavior() 211 static const StyleContentAlignmentData& contentAlignmentNormalBehavior()
212 { 212 {
213 // The justify-content property applies along the main axis, but since flexi ng 213 // The justify-content property applies along the main axis, but since flexi ng
214 // in the main axis is controlled by flex, stretch behaves as flex-start (ig noring 214 // in the main axis is controlled by flex, stretch behaves as flex-start (ig noring
215 // the specified fallback alignment, if any). 215 // the specified fallback alignment, if any).
216 // https://drafts.csswg.org/css-align/#distribution-flex 216 // https://drafts.csswg.org/css-align/#distribution-flex
217 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; 217 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch};
218 return normalBehavior; 218 return normalBehavior;
219 } 219 }
220 220
221 int LayoutFlexibleBox::firstLineBoxBaseline() const 221 int LayoutFlexibleBox::firstLineBoxBaseline() const
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return flexDirection == (style()->isLeftToRightDirection() ? FlowRowReve rse : FlowRow); 325 return flexDirection == (style()->isLeftToRightDirection() ? FlowRowReve rse : FlowRow);
326 return flexDirection == FlowColumnReverse; 326 return flexDirection == FlowColumnReverse;
327 } 327 }
328 328
329 void LayoutFlexibleBox::removeChild(LayoutObject* child) 329 void LayoutFlexibleBox::removeChild(LayoutObject* child)
330 { 330 {
331 LayoutBlock::removeChild(child); 331 LayoutBlock::removeChild(child);
332 m_intrinsicSizeAlongMainAxis.remove(child); 332 m_intrinsicSizeAlongMainAxis.remove(child);
333 } 333 }
334 334
335 // TODO (lajava): Is this function still needed ? Every time the flex container' s align-items value changes we
336 // propagate the diff to its children (see ComputedStyle::stylePropagationDiff).
335 void LayoutFlexibleBox::styleDidChange(StyleDifference diff, const ComputedStyle * oldStyle) 337 void LayoutFlexibleBox::styleDidChange(StyleDifference diff, const ComputedStyle * oldStyle)
336 { 338 {
337 LayoutBlock::styleDidChange(diff, oldStyle); 339 LayoutBlock::styleDidChange(diff, oldStyle);
338 340
339 if (oldStyle && oldStyle->alignItemsPosition() == ItemPositionStretch && dif f.needsFullLayout()) { 341 if (oldStyle && oldStyle->alignItemsPosition() == ItemPositionStretch && dif f.needsFullLayout()) {
340 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space. 342 // Flex items that were previously stretching need to be relayed out so we can compute new available cross axis space.
341 // This is only necessary for stretching since other alignment values do n't change the size of the box. 343 // This is only necessary for stretching since other alignment values do n't change the size of the box.
342 for (LayoutBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) { 344 for (LayoutBox* child = firstChildBox(); child; child = child->nextSibli ngBox()) {
343 ItemPosition previousAlignment = ComputedStyle::resolveAlignment(*ol dStyle, child->styleRef(), ItemPositionStretch); 345 ItemPosition previousAlignment = child->styleRef().resolvedAlignSelf (selfAlignmentNormalBehavior(), oldStyle).position();
344 if (previousAlignment == ItemPositionStretch && previousAlignment != ComputedStyle::resolveAlignment(styleRef(), child->styleRef(), ItemPositionStre tch)) 346 if (previousAlignment == ItemPositionStretch && previousAlignment != child->styleRef().resolvedAlignSelf(selfAlignmentNormalBehavior(), style()).pos ition())
345 child->setChildNeedsLayout(MarkOnlyThis); 347 child->setChildNeedsLayout(MarkOnlyThis);
346 } 348 }
347 } 349 }
348 } 350 }
349 351
350 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren) 352 void LayoutFlexibleBox::layoutBlock(bool relayoutChildren)
351 { 353 {
352 DCHECK(needsLayout()); 354 DCHECK(needsLayout());
353 355
354 if (!relayoutChildren && simplifiedLayout()) 356 if (!relayoutChildren && simplifiedLayout())
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 if (justifyContentDistribution == ContentDistributionSpaceAround) 1393 if (justifyContentDistribution == ContentDistributionSpaceAround)
1392 return availableFreeSpace / numberOfChildren; 1394 return availableFreeSpace / numberOfChildren;
1393 } 1395 }
1394 return LayoutUnit(); 1396 return LayoutUnit();
1395 } 1397 }
1396 1398
1397 static LayoutUnit alignmentOffset(LayoutUnit availableFreeSpace, ItemPosition po sition, LayoutUnit ascent, LayoutUnit maxAscent, bool isWrapReverse) 1399 static LayoutUnit alignmentOffset(LayoutUnit availableFreeSpace, ItemPosition po sition, LayoutUnit ascent, LayoutUnit maxAscent, bool isWrapReverse)
1398 { 1400 {
1399 switch (position) { 1401 switch (position) {
1400 case ItemPositionAuto: 1402 case ItemPositionAuto:
1403 case ItemPositionNormal:
1401 NOTREACHED(); 1404 NOTREACHED();
1402 break; 1405 break;
1403 case ItemPositionStretch: 1406 case ItemPositionStretch:
1404 // Actual stretching must be handled by the caller. 1407 // Actual stretching must be handled by the caller.
1405 // Since wrap-reverse flips cross start and cross end, stretch children should be aligned with the cross end. 1408 // Since wrap-reverse flips cross start and cross end, stretch children should be aligned with the cross end.
1406 // This matters because applyStretchAlignment doesn't always stretch or stretch fully (explicit cross size given, 1409 // This matters because applyStretchAlignment doesn't always stretch or stretch fully (explicit cross size given,
1407 // or stretching constrained by max-height/max-width). 1410 // or stretching constrained by max-height/max-width).
1408 // For flex-start and flex-end this is handled by alignmentForChild(). 1411 // For flex-start and flex-end this is handled by alignmentForChild().
1409 if (isWrapReverse) 1412 if (isWrapReverse)
1410 return availableFreeSpace; 1413 return availableFreeSpace;
(...skipping 28 matching lines...) Expand all
1439 if (hasOrthogonalFlow(child)) 1442 if (hasOrthogonalFlow(child))
1440 child.setOverrideLogicalContentHeight(childPreferredSize); 1443 child.setOverrideLogicalContentHeight(childPreferredSize);
1441 else 1444 else
1442 child.setOverrideLogicalContentWidth(childPreferredSize); 1445 child.setOverrideLogicalContentWidth(childPreferredSize);
1443 } 1446 }
1444 1447
1445 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child) 1448 LayoutUnit LayoutFlexibleBox::staticMainAxisPositionForPositionedChild(const Lay outBox& child)
1446 { 1449 {
1447 const LayoutUnit availableSpace = mainAxisContentExtent(contentLogicalHeight ()) - mainAxisExtentForChild(child); 1450 const LayoutUnit availableSpace = mainAxisContentExtent(contentLogicalHeight ()) - mainAxisExtentForChild(child);
1448 1451
1449 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior()); 1452 ContentPosition position = styleRef().resolvedJustifyContentPosition(content AlignmentNormalBehavior());
1450 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior()); 1453 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(contentAlignmentNormalBehavior());
1451 LayoutUnit offset = initialJustifyContentOffset(availableSpace, position, di stribution, 1); 1454 LayoutUnit offset = initialJustifyContentOffset(availableSpace, position, di stribution, 1);
1452 if (styleRef().flexDirection() == FlowRowReverse || styleRef().flexDirection () == FlowColumnReverse) 1455 if (styleRef().flexDirection() == FlowRowReverse || styleRef().flexDirection () == FlowColumnReverse)
1453 offset = availableSpace - offset; 1456 offset = availableSpace - offset;
1454 return offset; 1457 return offset;
1455 } 1458 }
1456 1459
1457 LayoutUnit LayoutFlexibleBox::staticCrossAxisPositionForPositionedChild(const La youtBox& child) 1460 LayoutUnit LayoutFlexibleBox::staticCrossAxisPositionForPositionedChild(const La youtBox& child)
1458 { 1461 {
1459 LayoutUnit availableSpace = crossAxisContentExtent() - crossAxisExtentForChi ld(child); 1462 LayoutUnit availableSpace = crossAxisContentExtent() - crossAxisExtentForChi ld(child);
1460 return alignmentOffset(availableSpace, alignmentForChild(child), LayoutUnit( ), LayoutUnit(), styleRef().flexWrap() == FlexWrapReverse); 1463 return alignmentOffset(availableSpace, alignmentForChild(child), LayoutUnit( ), LayoutUnit(), styleRef().flexWrap() == FlexWrapReverse);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 LayoutUnit staticBlockPosition = flowAwareBorderBefore() + flowAwarePaddingB efore(); 1513 LayoutUnit staticBlockPosition = flowAwareBorderBefore() + flowAwarePaddingB efore();
1511 if (childLayer->staticBlockPosition() != staticBlockPosition) { 1514 if (childLayer->staticBlockPosition() != staticBlockPosition) {
1512 childLayer->setStaticBlockPosition(staticBlockPosition); 1515 childLayer->setStaticBlockPosition(staticBlockPosition);
1513 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de())) 1516 if (child.style()->hasStaticBlockPosition(style()->isHorizontalWritingMo de()))
1514 child.setChildNeedsLayout(MarkOnlyThis); 1517 child.setChildNeedsLayout(MarkOnlyThis);
1515 } 1518 }
1516 } 1519 }
1517 1520
1518 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const 1521 ItemPosition LayoutFlexibleBox::alignmentForChild(const LayoutBox& child) const
1519 { 1522 {
1520 ItemPosition align = ComputedStyle::resolveAlignment(styleRef(), child.style Ref(), ItemPositionStretch); 1523 ItemPosition align = child.styleRef().resolvedAlignSelf(selfAlignmentNormalB ehavior(), child.isAnonymous() ? style() : nullptr).position();
1524 DCHECK(align != ItemPositionAuto && align != ItemPositionNormal);
1521 1525
1522 if (align == ItemPositionBaseline && hasOrthogonalFlow(child)) 1526 if (align == ItemPositionBaseline && hasOrthogonalFlow(child))
1523 align = ItemPositionFlexStart; 1527 align = ItemPositionFlexStart;
1524 1528
1525 if (style()->flexWrap() == FlexWrapReverse) { 1529 if (style()->flexWrap() == FlexWrapReverse) {
1526 if (align == ItemPositionFlexStart) 1530 if (align == ItemPositionFlexStart)
1527 align = ItemPositionFlexEnd; 1531 align = ItemPositionFlexEnd;
1528 else if (align == ItemPositionFlexEnd) 1532 else if (align == ItemPositionFlexEnd)
1529 align = ItemPositionFlexStart; 1533 align = ItemPositionFlexStart;
1530 } 1534 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 1604
1601 EOverflow LayoutFlexibleBox::crossAxisOverflowForChild(const LayoutBox& child) c onst 1605 EOverflow LayoutFlexibleBox::crossAxisOverflowForChild(const LayoutBox& child) c onst
1602 { 1606 {
1603 if (isHorizontalFlow()) 1607 if (isHorizontalFlow())
1604 return child.styleRef().overflowY(); 1608 return child.styleRef().overflowY();
1605 return child.styleRef().overflowX(); 1609 return child.styleRef().overflowX();
1606 } 1610 }
1607 1611
1608 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, LayoutUnit availableFreeSpace, bool relayoutChi ldren, SubtreeLayoutScope& layoutScope, Vector<LineContext>& lineContexts) 1612 void LayoutFlexibleBox::layoutAndPlaceChildren(LayoutUnit& crossAxisOffset, cons t OrderedFlexItemList& children, LayoutUnit availableFreeSpace, bool relayoutChi ldren, SubtreeLayoutScope& layoutScope, Vector<LineContext>& lineContexts)
1609 { 1613 {
1610 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior()); 1614 ContentPosition position = styleRef().resolvedJustifyContentPosition(content AlignmentNormalBehavior());
1611 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior()); 1615 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(contentAlignmentNormalBehavior());
1612 1616
1613 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1617 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1614 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace); 1618 LayoutUnit autoMarginOffset = autoMarginOffsetInMainAxis(children, available FreeSpace);
1615 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ; 1619 LayoutUnit mainAxisOffset = flowAwareBorderStart() + flowAwarePaddingStart() ;
1616 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent); 1620 mainAxisOffset += initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent);
1617 if (style()->flexDirection() == FlowRowReverse && shouldPlaceBlockDirectionS crollbarOnLogicalLeft()) 1621 if (style()->flexDirection() == FlowRowReverse && shouldPlaceBlockDirectionS crollbarOnLogicalLeft())
1618 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight(); 1622 mainAxisOffset += isHorizontalFlow() ? verticalScrollbarWidth() : horizo ntalScrollbarHeight();
1619 1623
1620 LayoutUnit totalMainExtent = mainAxisExtent(); 1624 LayoutUnit totalMainExtent = mainAxisExtent();
1621 if (!shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 1625 if (!shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 } 1706 }
1703 1707
1704 if (m_numberOfInFlowChildrenOnFirstLine == -1) 1708 if (m_numberOfInFlowChildrenOnFirstLine == -1)
1705 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren; 1709 m_numberOfInFlowChildrenOnFirstLine = seenInFlowPositionedChildren;
1706 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch ildren.size(), maxAscent)); 1710 lineContexts.append(LineContext(crossAxisOffset, maxChildCrossAxisExtent, ch ildren.size(), maxAscent));
1707 crossAxisOffset += maxChildCrossAxisExtent; 1711 crossAxisOffset += maxChildCrossAxisExtent;
1708 } 1712 }
1709 1713
1710 void LayoutFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace) 1714 void LayoutFlexibleBox::layoutColumnReverse(const OrderedFlexItemList& children, LayoutUnit crossAxisOffset, LayoutUnit availableFreeSpace)
1711 { 1715 {
1712 ContentPosition position = styleRef().resolvedJustifyContentPosition(normalV alueBehavior()); 1716 ContentPosition position = styleRef().resolvedJustifyContentPosition(content AlignmentNormalBehavior());
1713 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(normalValueBehavior()); 1717 ContentDistributionType distribution = styleRef().resolvedJustifyContentDist ribution(contentAlignmentNormalBehavior());
1714 1718
1715 // This is similar to the logic in layoutAndPlaceChildren, except we place t he children 1719 // This is similar to the logic in layoutAndPlaceChildren, except we place t he children
1716 // starting from the end of the flexbox. We also don't need to layout anythi ng since we're 1720 // starting from the end of the flexbox. We also don't need to layout anythi ng since we're
1717 // just moving the children to a new position. 1721 // just moving the children to a new position.
1718 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children); 1722 size_t numberOfChildrenForJustifyContent = numberOfInFlowPositionedChildren( children);
1719 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd(); 1723 LayoutUnit mainAxisOffset = logicalHeight() - flowAwareBorderEnd() - flowAwa rePaddingEnd();
1720 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent); 1724 mainAxisOffset -= initialJustifyContentOffset(availableFreeSpace, position, distribution, numberOfChildrenForJustifyContent);
1721 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight(); 1725 mainAxisOffset -= isHorizontalFlow() ? verticalScrollbarWidth() : horizontal ScrollbarHeight();
1722 1726
1723 size_t seenInFlowPositionedChildren = 0; 1727 size_t seenInFlowPositionedChildren = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 return availableFreeSpace / numberOfLines; 1769 return availableFreeSpace / numberOfLines;
1766 } 1770 }
1767 return LayoutUnit(); 1771 return LayoutUnit();
1768 } 1772 }
1769 1773
1770 void LayoutFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts) 1774 void LayoutFlexibleBox::alignFlexLines(Vector<LineContext>& lineContexts)
1771 { 1775 {
1772 if (!lineContexts.size()) 1776 if (!lineContexts.size())
1773 return; 1777 return;
1774 1778
1775 ContentPosition position = styleRef().resolvedAlignContentPosition(normalVal ueBehavior()); 1779 ContentPosition position = styleRef().resolvedAlignContentPosition(contentAl ignmentNormalBehavior());
1776 ContentDistributionType distribution = styleRef().resolvedAlignContentDistri bution(normalValueBehavior()); 1780 ContentDistributionType distribution = styleRef().resolvedAlignContentDistri bution(contentAlignmentNormalBehavior());
1777 1781
1778 // If we have a single line flexbox the line height is all the available spa ce. 1782 // If we have a single line flexbox the line height is all the available spa ce.
1779 // For flex-direction: row, this means we need to use the height, so we do t his after calling updateLogicalHeight. 1783 // For flex-direction: row, this means we need to use the height, so we do t his after calling updateLogicalHeight.
1780 if (!isMultiline()) { 1784 if (!isMultiline()) {
1781 lineContexts[0].crossAxisExtent = crossAxisContentExtent(); 1785 lineContexts[0].crossAxisExtent = crossAxisContentExtent();
1782 return; 1786 return;
1783 } 1787 }
1784 1788
1785 if (position == ContentPositionFlexStart) 1789 if (position == ContentPositionFlexStart)
1786 return; 1790 return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 DCHECK(child); 1931 DCHECK(child);
1928 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent; 1932 LayoutUnit lineCrossAxisExtent = lineContexts[lineNumber].crossAxisE xtent;
1929 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge; 1933 LayoutUnit originalOffset = lineContexts[lineNumber].crossAxisOffset - crossAxisStartEdge;
1930 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent; 1934 LayoutUnit newOffset = contentExtent - originalOffset - lineCrossAxi sExtent;
1931 adjustAlignmentForChild(*child, newOffset - originalOffset); 1935 adjustAlignmentForChild(*child, newOffset - originalOffset);
1932 } 1936 }
1933 } 1937 }
1934 } 1938 }
1935 1939
1936 } // namespace blink 1940 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutFlexibleBox.h ('k') | third_party/WebKit/Source/core/layout/LayoutFullScreen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698