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

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

Issue 2135703002: [css-grid] Fix crash when using auto repeat for indefinite widths (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test improvements Created 4 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
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 // may trigger relayout). 436 // may trigger relayout).
437 LayoutState state(*this, locationOffset()); 437 LayoutState state(*this, locationOffset());
438 438
439 LayoutSize previousSize = size(); 439 LayoutSize previousSize = size();
440 440
441 updateLogicalWidth(); 441 updateLogicalWidth();
442 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), LayoutUnit(-1)) == LayoutUnit(-1); 442 bool logicalHeightWasIndefinite = computeContentLogicalHeight(MainOrPref erredSize, style()->logicalHeight(), LayoutUnit(-1)) == LayoutUnit(-1);
443 443
444 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); 444 TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
445 445
446 placeItemsOnGrid(); 446 placeItemsOnGrid(TrackSizing);
447 447
448 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 448 GridSizingData sizingData(gridColumnCount(), gridRowCount());
449 449
450 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns. 450 // 1- First, the track sizing algorithm is used to resolve the sizes of the grid columns.
451 // At this point the logical width is always definite as the above call to updateLogicalWidth() 451 // At this point the logical width is always definite as the above call to updateLogicalWidth()
452 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code 452 // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
453 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve 453 // paths inside updateLogicalHeight() require a previous call to setLogi calHeight() to resolve
454 // heights properly (like for positioned items for example). 454 // heights properly (like for positioned items for example).
455 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); 455 LayoutUnit availableSpaceForColumns = availableLogicalWidth();
456 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns); 456 computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForC olumns);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 { 504 {
505 if (span <= 1) 505 if (span <= 1)
506 return LayoutUnit(); 506 return LayoutUnit();
507 507
508 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap(); 508 const Length& trackGap = direction == ForColumns ? styleRef().gridColumnGap( ) : styleRef().gridRowGap();
509 return valueForLength(trackGap, LayoutUnit()) * (span - 1); 509 return valueForLength(trackGap, LayoutUnit()) * (span - 1);
510 } 510 }
511 511
512 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const 512 void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo utUnit& maxLogicalWidth) const
513 { 513 {
514 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(); 514 // TODO(svillar): check the comment in clearGridDataAndMarkAsDirty() to remo ve these two const_cast.
515 const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation);
515 516
516 GridSizingData sizingData(gridColumnCount(), gridRowCount()); 517 GridSizingData sizingData(gridColumnCount(), gridRowCount());
517 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit(); 518 sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit();
518 sizingData.sizingOperation = IntrinsicSizeComputation; 519 sizingData.sizingOperation = IntrinsicSizeComputation;
519 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth); 520 const_cast<LayoutGrid*>(this)->computeUsedBreadthOfGridTracks(ForColumns, si zingData, minLogicalWidth, maxLogicalWidth);
520 521
521 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size()); 522 LayoutUnit totalGuttersSize = guttersSize(ForColumns, sizingData.columnTrack s.size());
522 minLogicalWidth += totalGuttersSize; 523 minLogicalWidth += totalGuttersSize;
523 maxLogicalWidth += totalGuttersSize; 524 maxLogicalWidth += totalGuttersSize;
524 525
525 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth()); 526 LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
526 minLogicalWidth += scrollbarWidth; 527 minLogicalWidth += scrollbarWidth;
527 maxLogicalWidth += scrollbarWidth; 528 maxLogicalWidth += scrollbarWidth;
529
530 // Mark the grid as dirty as we need to recompute the auto repeat columns du ring layout.
531 if (m_autoRepeatColumns)
532 clearGridDataAndMarkAsDirty();
528 } 533 }
529 534
530 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData) 535 void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData)
531 { 536 {
532 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData)); 537 ASSERT(tracksAreWiderThanMinTrackBreadth(ForColumns, sizingData));
533 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit(); 538 sizingData.freeSpaceForDirection(ForRows) = LayoutUnit();
534 sizingData.sizingOperation = IntrinsicSizeComputation; 539 sizingData.sizingOperation = IntrinsicSizeComputation;
535 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight); 540 computeUsedBreadthOfGridTracks(ForRows, sizingData, m_minContentHeight, m_ma xContentHeight);
536 541
537 LayoutUnit totalGuttersSize = guttersSize(ForRows, gridRowCount()); 542 LayoutUnit totalGuttersSize = guttersSize(ForRows, gridRowCount());
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1382
1378 // Provided the grid container does not have a definite size or max-size in the relevant axis, 1383 // Provided the grid container does not have a definite size or max-size in the relevant axis,
1379 // if the min size is definite then the number of repetitions is the largest possible positive 1384 // if the min size is definite then the number of repetitions is the largest possible positive
1380 // integer that fulfills that minimum requirement. 1385 // integer that fulfills that minimum requirement.
1381 if (needsToFulfillMinimumSize) 1386 if (needsToFulfillMinimumSize)
1382 ++repetitions; 1387 ++repetitions;
1383 1388
1384 return repetitions; 1389 return repetitions;
1385 } 1390 }
1386 1391
1387 void LayoutGrid::placeItemsOnGrid() 1392 void LayoutGrid::placeItemsOnGrid(SizingOperation inlineAxisSizingOperation)
jfernandez 2016/07/11 12:52:22 Why we need to know whether is inline or block axi
svillar 2016/07/11 14:18:43 Well I tried to make a bit explicit that the sizin
1388 { 1393 {
1389 if (!m_gridIsDirty) 1394 if (!m_gridIsDirty)
1390 return; 1395 return;
1391 1396
1392 ASSERT(m_gridItemArea.isEmpty()); 1397 ASSERT(m_gridItemArea.isEmpty());
1393 1398
1394 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns); 1399 if (inlineAxisSizingOperation == IntrinsicSizeComputation)
1400 m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().isEmpty() ? 0 : 1;
jfernandez 2016/07/11 12:52:22 Why 1 ? Hadn't we avoid that kind of harcoded 1 va
svillar 2016/07/11 14:18:43 Because that's what the spec says (https://drafts.
1401 else
1402 m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
1395 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows); 1403 m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows);
1396 1404
1397 populateExplicitGridAndOrderIterator(); 1405 populateExplicitGridAndOrderIterator();
1398 1406
1399 // We clear the dirty bit here as the grid sizes have been updated. 1407 // We clear the dirty bit here as the grid sizes have been updated.
1400 m_gridIsDirty = false; 1408 m_gridIsDirty = false;
1401 1409
1402 Vector<LayoutBox*> autoMajorAxisAutoGridItems; 1410 Vector<LayoutBox*> autoMajorAxisAutoGridItems;
1403 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems; 1411 Vector<LayoutBox*> specifiedMajorAxisAutoGridItems;
1404 m_hasAnyOrthogonalChild = false; 1412 m_hasAnyOrthogonalChild = false;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const 1616 GridTrackSizingDirection LayoutGrid::autoPlacementMajorAxisDirection() const
1609 { 1617 {
1610 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows; 1618 return style()->isGridAutoFlowDirectionColumn() ? ForColumns : ForRows;
1611 } 1619 }
1612 1620
1613 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const 1621 GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const
1614 { 1622 {
1615 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; 1623 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns;
1616 } 1624 }
1617 1625
1626 void LayoutGrid::clearGridDataAndMarkAsDirty() const
1627 {
Manuel Rego 2016/07/11 11:10:57 Maybe add a similar if to the one in dirtyGrid():
svillar 2016/07/11 11:48:00 I think I'm adding an ASSERT there.
1628 // TODO(svillar): The track sizing algorithm is used for preferredLogicalWid ths
1629 // computations. This means that some attributes of this class will be modif ied during that
1630 // process. We should make the algorithm work against some interface that wo uld allow us not to
1631 // have to change these attributes while computing the intrinsic sizes.
1632 m_grid.resize(0);
1633 m_gridItemArea.clear();
1634 m_gridItemsOverflowingGridArea.resize(0);
1635 m_gridItemsIndexesMap.clear();
1636 m_autoRepeatColumns = 0;
1637 m_autoRepeatRows = 0;
1638 m_gridIsDirty = true;
1639 }
1640
1618 void LayoutGrid::dirtyGrid() 1641 void LayoutGrid::dirtyGrid()
Manuel Rego 2016/07/11 11:10:57 Shouldn't we rename this method? We've now: * dir
svillar 2016/07/11 11:48:00 The reason why I added a new method is because dir
1619 { 1642 {
1620 if (m_gridIsDirty) 1643 if (m_gridIsDirty)
1621 return; 1644 return;
1622 1645
1623 // Even if this could be redundant, it could be seen as a defensive strategy against 1646 // Even if this could be redundant, it could be seen as a defensive strategy against
1624 // style changes events happening during the layout phase or even while the painting process 1647 // style changes events happening during the layout phase or even while the painting process
1625 // is still ongoing. 1648 // is still ongoing.
1626 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure 1649 // Forcing a new layout for the Grid layout would cancel any ongoing paintin g and ensure
1627 // the grid and its children are correctly laid out according to the new sty le rules. 1650 // the grid and its children are correctly laid out according to the new sty le rules.
1628 setNeedsLayout(LayoutInvalidationReason::GridChanged); 1651 setNeedsLayout(LayoutInvalidationReason::GridChanged);
1629 1652
1630 m_grid.resize(0); 1653 clearGridDataAndMarkAsDirty();
1631 m_gridItemArea.clear();
1632 m_gridItemsOverflowingGridArea.resize(0);
1633 m_gridItemsIndexesMap.clear();
1634 m_gridIsDirty = true;
1635 } 1654 }
1636 1655
1637 static const StyleContentAlignmentData& normalValueBehavior() 1656 static const StyleContentAlignmentData& normalValueBehavior()
1638 { 1657 {
1639 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch}; 1658 static const StyleContentAlignmentData normalBehavior = {ContentPositionNorm al, ContentDistributionStretch};
1640 return normalBehavior; 1659 return normalBehavior;
1641 } 1660 }
1642 1661
1643 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData) 1662 void LayoutGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData& sizingData)
1644 { 1663 {
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation; 2382 return isOrthogonalChild(child) ? childLocation.transposedPoint() : childLoc ation;
2364 } 2383 }
2365 2384
2366 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const 2385 void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) const
2367 { 2386 {
2368 if (!m_gridItemArea.isEmpty()) 2387 if (!m_gridItemArea.isEmpty())
2369 GridPainter(*this).paintChildren(paintInfo, paintOffset); 2388 GridPainter(*this).paintChildren(paintInfo, paintOffset);
2370 } 2389 }
2371 2390
2372 } // namespace blink 2391 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698