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

Side by Side Diff: Source/core/layout/LayoutGrid.cpp

Issue 1228983003: [CSS Grid Layout] Do not stretch always grid items with auto width (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Forgot to update the expectations file. Created 5 years, 5 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 | « Source/core/layout/LayoutGrid.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 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 SubtreeLayoutScope layoutScope(*child); 1268 SubtreeLayoutScope layoutScope(*child);
1269 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) 1269 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingB lockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != ov errideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight()))
1270 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged); 1270 layoutScope.setNeedsLayout(child, LayoutInvalidationReason::GridChan ged);
1271 1271
1272 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth); 1272 child->setOverrideContainingBlockContentLogicalWidth(overrideContainingB lockContentLogicalWidth);
1273 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight); 1273 child->setOverrideContainingBlockContentLogicalHeight(overrideContaining BlockContentLogicalHeight);
1274 1274
1275 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded 1275 // Stretching logic might force a child layout, so we need to run it bef ore the layoutIfNeeded
1276 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly 1276 // call to avoid unnecessary relayouts. This might imply that child marg ins, needed to correctly
1277 // determine the available space before stretching, are not set yet. 1277 // determine the available space before stretching, are not set yet.
1278 applyStretchAlignmentToChildIfNeeded(*child, overrideContainingBlockCont entLogicalHeight); 1278 applyStretchAlignmentToChildIfNeeded(*child);
1279 1279
1280 child->layoutIfNeeded(); 1280 child->layoutIfNeeded();
1281 1281
1282 #if ENABLE(ASSERT) 1282 #if ENABLE(ASSERT)
1283 const GridCoordinate& coordinate = cachedGridCoordinate(*child); 1283 const GridCoordinate& coordinate = cachedGridCoordinate(*child);
1284 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size()); 1284 ASSERT(coordinate.columns.resolvedInitialPosition.toInt() < sizingData.c olumnTracks.size());
1285 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size()); 1285 ASSERT(coordinate.rows.resolvedInitialPosition.toInt() < sizingData.rowT racks.size());
1286 #endif 1286 #endif
1287 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); 1287 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData));
1288 1288
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 ASSERT_NOT_REACHED(); 1446 ASSERT_NOT_REACHED();
1447 return 0; 1447 return 0;
1448 } 1448 }
1449 1449
1450 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child) 1450 static inline LayoutUnit constrainedChildIntrinsicContentLogicalHeight(const Lay outBox& child)
1451 { 1451 {
1452 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight(); 1452 LayoutUnit childIntrinsicContentLogicalHeight = child.intrinsicContentLogica lHeight();
1453 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight); 1453 return child.constrainLogicalHeightByMinMax(childIntrinsicContentLogicalHeig ht + child.borderAndPaddingLogicalHeight(), childIntrinsicContentLogicalHeight);
1454 } 1454 }
1455 1455
1456 bool LayoutGrid::allowedToStretchLogicalHeightForChild(const LayoutBox& child) c onst 1456 bool LayoutGrid::canShrinkToFitInRowAxisForChild(const LayoutBox& child) const
1457 { 1457 {
1458 return child.style()->logicalHeight().isAuto() && !child.style()->marginBefo reUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto(); 1458 return !hasAutoMinSizeInRowAxis(child) || child.minPreferredLogicalWidth() < = child.overrideContainingBlockContentLogicalWidth();
1459 }
1460
1461 bool LayoutGrid::hasAutoMinSizeInRowAxis(const LayoutBox& child) const
1462 {
1463 return isHorizontalWritingMode() ? style()->minWidth().isAuto() : child.styl e()->minHeight().isAuto();
Manuel Rego 2015/07/23 09:41:26 Hey, missing child.style() in the first call!
jfernandez 2015/07/23 11:01:04 Done.
1464 }
1465
1466 bool LayoutGrid::hasAutoSizeInColumnAxisForChild(const LayoutBox& child) const
1467 {
1468 return isHorizontalWritingMode() ? child.style()->height().isAuto() : child. style()->width().isAuto();
1469 }
1470
1471 bool LayoutGrid::hasAutoSizeInRowAxisForChild(const LayoutBox& child) const
1472 {
1473 return isHorizontalWritingMode() ? child.style()->width().isAuto() : child.s tyle()->height().isAuto();
1474 }
1475
1476 bool LayoutGrid::allowedToStretchChildAlongColumnAxis(const LayoutBox& child) co nst
1477 {
1478 return hasAutoSizeInColumnAxisForChild(child) && !child.style()->marginBefor eUsing(style()).isAuto() && !child.style()->marginAfterUsing(style()).isAuto();
1479 }
1480
1481 bool LayoutGrid::allowedToStretchChildAlongRowAxis(const LayoutBox& child) const
1482 {
1483 return hasAutoSizeInRowAxisForChild(child) && !child.style()->marginStartUsi ng(style()).isAuto() && !child.style()->marginEndUsing(style()).isAuto();
1459 } 1484 }
1460 1485
1461 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. 1486 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1462 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const 1487 bool LayoutGrid::needToStretchChildLogicalHeight(const LayoutBox& child) const
1463 { 1488 {
1464 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch) 1489 if (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPositi onStretch) != ItemPositionStretch)
1465 return false; 1490 return false;
1466 1491
1467 return isHorizontalWritingMode() && child.style()->height().isAuto(); 1492 return isHorizontalWritingMode() && child.style()->height().isAuto();
1468 } 1493 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 // Because we want to avoid multiple layouts, stretching logic might be perf ormed before 1541 // Because we want to avoid multiple layouts, stretching logic might be perf ormed before
1517 // children are laid out, so we can't use the child cached values. Hence, we need to 1542 // children are laid out, so we can't use the child cached values. Hence, we need to
1518 // compute margins in order to determine the available height before stretch ing. 1543 // compute margins in order to determine the available height before stretch ing.
1519 if (childMarginLogicalHeight == 0) 1544 if (childMarginLogicalHeight == 0)
1520 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child); 1545 childMarginLogicalHeight = computeMarginLogicalHeightForChild(child);
1521 1546
1522 return gridAreaBreadthForChild - childMarginLogicalHeight; 1547 return gridAreaBreadthForChild - childMarginLogicalHeight;
1523 } 1548 }
1524 1549
1525 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox. 1550 // FIXME: This logic is shared by LayoutFlexibleBox, so it should be moved to La youtBox.
1526 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child, LayoutUn it gridAreaBreadthForChild) 1551 void LayoutGrid::applyStretchAlignmentToChildIfNeeded(LayoutBox& child)
1527 { 1552 {
1528 if (!allowedToStretchLogicalHeightForChild(child) || ComputedStyle::resolveA lignment(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret ch) { 1553 child.clearOverrideSize();
1529 child.clearOverrideLogicalContentHeight(); 1554
1530 return; 1555 if (!allowedToStretchChildAlongRowAxis(child) || ComputedStyle::resolveJusti fication(styleRef(), child.styleRef(), ItemPositionStretch) != ItemPositionStret ch) {
1556 // TODO(lajava): how to handle orthogonality in this case ?.
1557 // TODO(lajava): grid track sizing and positioning do not support orthog onal modes yet.
1558 if (hasAutoSizeInRowAxisForChild(child) && canShrinkToFitInRowAxisForChi ld(child)) {
1559 LayoutUnit childWidthToFit = std::min(child.maxPreferredLogicalWidth (), child.overrideContainingBlockContentLogicalWidth() - child.marginLogicalWid th());
Manuel Rego 2015/07/23 09:41:26 Sorry but I've realized that the bug I reported fo
jfernandez 2015/07/23 11:01:04 Acknowledged.
1560 LayoutUnit desiredLogicalWidth = child.constrainLogicalHeightByMinMa x(childWidthToFit, -1);
1561 bool childNeedsRelayout = desiredLogicalWidth != child.logicalWidth( );
1562 child.setOverrideLogicalContentWidth(desiredLogicalWidth - child.bor derAndPaddingLogicalWidth());
1563 if (childNeedsRelayout) {
1564 child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
1565 }
1566 }
1531 } 1567 }
1532 1568
1533 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 1569 if (allowedToStretchChildAlongColumnAxis(child) && ComputedStyle::resolveAli gnment(styleRef(), child.styleRef(), ItemPositionStretch) == ItemPositionStretch ) {
1534 // FIXME: If the child has orthogonal flow, then it already has an override height set, so use it. 1570 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHor izontalWritingMode();
1535 // FIXME: grid track sizing and positioning do not support orthogonal modes yet. 1571 // FIXME: If the child has orthogonal flow, then it already has an overr ide height set, so use it.
1536 if (!hasOrthogonalWritingMode) { 1572 // FIXME: grid track sizing and positioning do not support orthogonal mo des yet.
1537 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildBefor eStretching(gridAreaBreadthForChild, child); 1573 if (!hasOrthogonalWritingMode) {
1538 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinMax(s tretchedLogicalHeight, -1); 1574 LayoutUnit stretchedLogicalHeight = availableAlignmentSpaceForChildB eforeStretching(child.overrideContainingBlockContentLogicalHeight(), child);
1575 LayoutUnit desiredLogicalHeight = child.constrainLogicalHeightByMinM ax(stretchedLogicalHeight, -1);
1539 1576
1540 // FIXME: Can avoid laying out here in some cases. See https://webkit.or g/b/87905. 1577 // FIXME: Can avoid laying out here in some cases. See https://webki t.org/b/87905.
1541 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeight(); 1578 bool childNeedsRelayout = desiredLogicalHeight != child.logicalHeigh t();
1542 if (childNeedsRelayout || !child.hasOverrideLogicalContentHeight())
1543 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b orderAndPaddingLogicalHeight()); 1579 child.setOverrideLogicalContentHeight(desiredLogicalHeight - child.b orderAndPaddingLogicalHeight());
1544 if (childNeedsRelayout) { 1580 if (childNeedsRelayout) {
1545 child.setLogicalHeight(0); 1581 child.setLogicalHeight(0);
1546 child.setNeedsLayout(LayoutInvalidationReason::GridChanged); 1582 child.setNeedsLayout(LayoutInvalidationReason::GridChanged);
1583 }
1547 } 1584 }
1548 } 1585 }
1549 } 1586 }
1550 1587
1551 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const 1588 GridAxisPosition LayoutGrid::columnAxisPositionForChild(const LayoutBox& child) const
1552 { 1589 {
1553 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode(); 1590 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizon talWritingMode();
1554 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode(); 1591 bool hasSameWritingMode = child.styleRef().writingMode() == styleRef().writi ngMode();
1555 1592
1556 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) { 1593 switch (ComputedStyle::resolveAlignment(styleRef(), child.styleRef(), ItemPo sitionStretch)) {
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 1892
1856 return LayoutPoint(columnPosition, rowPositionForChild(child)); 1893 return LayoutPoint(columnPosition, rowPositionForChild(child));
1857 } 1894 }
1858 1895
1859 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 1896 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
1860 { 1897 {
1861 GridPainter(*this).paintChildren(paintInfo, paintOffset); 1898 GridPainter(*this).paintChildren(paintInfo, paintOffset);
1862 } 1899 }
1863 1900
1864 } // namespace blink 1901 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698