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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
index 6d8864e4a0d6d97a786ebe9bb66b5cfebf6bd4b9..9f7b39bbb16bedbaa3beb539db684fe447a6fa34 100644
--- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp
@@ -443,7 +443,7 @@ void LayoutGrid::layoutBlock(bool relayoutChildren)
TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
- placeItemsOnGrid();
+ placeItemsOnGrid(TrackSizing);
GridSizingData sizingData(gridColumnCount(), gridRowCount());
@@ -511,7 +511,8 @@ LayoutUnit LayoutGrid::guttersSize(GridTrackSizingDirection direction, size_t sp
void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
{
- const_cast<LayoutGrid*>(this)->placeItemsOnGrid();
+ // TODO(svillar): check the comment in clearGridDataAndMarkAsDirty() to remove these two const_cast.
+ const_cast<LayoutGrid*>(this)->placeItemsOnGrid(IntrinsicSizeComputation);
GridSizingData sizingData(gridColumnCount(), gridRowCount());
sizingData.freeSpaceForDirection(ForColumns) = LayoutUnit();
@@ -525,6 +526,10 @@ void LayoutGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, Layo
LayoutUnit scrollbarWidth = LayoutUnit(scrollbarLogicalWidth());
minLogicalWidth += scrollbarWidth;
maxLogicalWidth += scrollbarWidth;
+
+ // Mark the grid as dirty as we need to recompute the auto repeat columns during layout.
+ if (m_autoRepeatColumns)
+ clearGridDataAndMarkAsDirty();
Manuel Rego 2016/07/11 09:47:42 But we're already setting m_autoRepeatColumns|Rows
svillar1 2016/07/11 10:34:48 If you don't mark the grid as empty here, placeIte
Manuel Rego 2016/07/11 11:10:56 True, I missed that.
}
void LayoutGrid::computeIntrinsicLogicalHeight(GridSizingData& sizingData)
@@ -1384,14 +1389,17 @@ size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection directi
return repetitions;
}
-void LayoutGrid::placeItemsOnGrid()
+void LayoutGrid::placeItemsOnGrid(SizingOperation inlineAxisSizingOperation)
{
if (!m_gridIsDirty)
return;
ASSERT(m_gridItemArea.isEmpty());
- m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
+ if (inlineAxisSizingOperation == IntrinsicSizeComputation)
+ m_autoRepeatColumns = styleRef().gridAutoRepeatColumns().isEmpty() ? 0 : 1;
+ else
+ m_autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns);
m_autoRepeatRows = computeAutoRepeatTracksCount(ForRows);
populateExplicitGridAndOrderIterator();
@@ -1615,6 +1623,21 @@ GridTrackSizingDirection LayoutGrid::autoPlacementMinorAxisDirection() const
return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns;
}
+void LayoutGrid::clearGridDataAndMarkAsDirty() const
+{
+ // TODO(svillar): The track sizing algorithm is used for preferredLogicalWidths
+ // computations. This means that some attributes of this class will be modified during that
+ // process. We should make the algorithm work against some interface that would allow us not to
+ // have to change these attributes while computing the intrinsic sizes.
+ m_grid.resize(0);
+ m_gridItemArea.clear();
+ m_gridItemsOverflowingGridArea.resize(0);
+ m_gridItemsIndexesMap.clear();
+ m_autoRepeatColumns = 0;
+ m_autoRepeatRows = 0;
+ m_gridIsDirty = true;
+}
+
void LayoutGrid::dirtyGrid()
{
if (m_gridIsDirty)
@@ -1627,11 +1650,7 @@ void LayoutGrid::dirtyGrid()
// the grid and its children are correctly laid out according to the new style rules.
setNeedsLayout(LayoutInvalidationReason::GridChanged);
- m_grid.resize(0);
- m_gridItemArea.clear();
- m_gridItemsOverflowingGridArea.resize(0);
- m_gridItemsIndexesMap.clear();
- m_gridIsDirty = true;
+ clearGridDataAndMarkAsDirty();
}
static const StyleContentAlignmentData& normalValueBehavior()

Powered by Google App Engine
This is Rietveld 408576698