Chromium Code Reviews

Side by Side Diff: Source/core/rendering/RenderGrid.cpp

Issue 333563003: [CSS Grid Layout] Update grid-auto-flow to the new syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Small fix in add/removeChild to avoid dirtying the grid in stack Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 193 matching lines...)
204 RenderBlock::addChild(newChild, beforeChild); 204 RenderBlock::addChild(newChild, beforeChild);
205 205
206 if (gridIsDirty()) 206 if (gridIsDirty())
207 return; 207 return;
208 208
209 if (!newChild->isBox()) { 209 if (!newChild->isBox()) {
210 dirtyGrid(); 210 dirtyGrid();
211 return; 211 return;
212 } 212 }
213 213
214 if (style()->gridAutoFlow() != AutoFlowNone) { 214 // FIXME: Implement properly "stack" value in auto-placement algorithm.
215 if (style()->gridAutoFlow() != AutoFlowStackColumn && style()->gridAutoFlow( ) != AutoFlowStackRow) {
215 // The grid needs to be recomputed as it might contain auto-placed items that will change their position. 216 // The grid needs to be recomputed as it might contain auto-placed items that will change their position.
216 dirtyGrid(); 217 dirtyGrid();
217 return; 218 return;
218 } 219 }
219 220
220 RenderBox* newChildBox = toRenderBox(newChild); 221 RenderBox* newChildBox = toRenderBox(newChild);
221 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositionsFr omStyle(*style(), *newChildBox, ForRows); 222 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositionsFr omStyle(*style(), *newChildBox, ForRows);
222 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosition sFromStyle(*style(), *newChildBox, ForColumns); 223 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosition sFromStyle(*style(), *newChildBox, ForColumns);
223 if (!rowPositions || !columnPositions) { 224 if (!rowPositions || !columnPositions) {
224 // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully. 225 // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully.
(...skipping 28 matching lines...)
253 254
254 void RenderGrid::removeChild(RenderObject* child) 255 void RenderGrid::removeChild(RenderObject* child)
255 { 256 {
256 RenderBlock::removeChild(child); 257 RenderBlock::removeChild(child);
257 258
258 if (gridIsDirty()) 259 if (gridIsDirty())
259 return; 260 return;
260 261
261 ASSERT(child->isBox()); 262 ASSERT(child->isBox());
262 263
263 if (style()->gridAutoFlow() != AutoFlowNone) { 264 // FIXME: Implement properly "stack" value in auto-placement algorithm.
265 if (style()->gridAutoFlow() != AutoFlowStackColumn && style()->gridAutoFlow( ) != AutoFlowStackRow) {
264 // The grid needs to be recomputed as it might contain auto-placed items that will change their position. 266 // The grid needs to be recomputed as it might contain auto-placed items that will change their position.
265 dirtyGrid(); 267 dirtyGrid();
266 return; 268 return;
267 } 269 }
268 270
269 const RenderBox* childBox = toRenderBox(child); 271 const RenderBox* childBox = toRenderBox(child);
270 GridCoordinate coordinate = m_gridItemCoordinate.take(childBox); 272 GridCoordinate coordinate = m_gridItemCoordinate.take(childBox);
271 273
272 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row s.end(); ++row) { 274 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row s.end(); ++row) {
273 for (GridSpan::iterator column = coordinate.columns.begin(); column != c oordinate.columns.end(); ++column) { 275 for (GridSpan::iterator column = coordinate.columns.begin(); column != c oordinate.columns.end(); ++column) {
(...skipping 529 matching lines...)
803 else 805 else
804 specifiedMajorAxisAutoGridItems.append(child); 806 specifiedMajorAxisAutoGridItems.append(child);
805 continue; 807 continue;
806 } 808 }
807 insertItemIntoGrid(child, GridCoordinate(*rowPositions, *columnPositions )); 809 insertItemIntoGrid(child, GridCoordinate(*rowPositions, *columnPositions ));
808 } 810 }
809 811
810 ASSERT(gridRowCount() >= style()->gridTemplateRows().size()); 812 ASSERT(gridRowCount() >= style()->gridTemplateRows().size());
811 ASSERT(gridColumnCount() >= style()->gridTemplateColumns().size()); 813 ASSERT(gridColumnCount() >= style()->gridTemplateColumns().size());
812 814
813 if (autoFlow == AutoFlowNone) { 815 // FIXME: Implement properly "stack" value in auto-placement algorithm.
816 if (autoFlow == AutoFlowStackColumn || autoFlow == AutoFlowStackRow) {
814 // If we did collect some grid items, they won't be placed thus never la id out. 817 // If we did collect some grid items, they won't be placed thus never la id out.
815 ASSERT(!autoMajorAxisAutoGridItems.size()); 818 ASSERT(!autoMajorAxisAutoGridItems.size());
816 ASSERT(!specifiedMajorAxisAutoGridItems.size()); 819 ASSERT(!specifiedMajorAxisAutoGridItems.size());
817 return; 820 return;
818 } 821 }
819 822
820 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); 823 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems);
821 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); 824 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems);
822 825
823 m_grid.shrinkToFit(); 826 m_grid.shrinkToFit();
(...skipping 102 matching lines...)
926 if (!emptyGridArea) 929 if (!emptyGridArea)
927 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions); 930 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(g ridItem, autoPlacementMinorAxisDirection(), minorAxisPositions);
928 } 931 }
929 932
930 insertItemIntoGrid(gridItem, *emptyGridArea); 933 insertItemIntoGrid(gridItem, *emptyGridArea);
931 } 934 }
932 935
933 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const 936 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const
934 { 937 {
935 GridAutoFlow flow = style()->gridAutoFlow(); 938 GridAutoFlow flow = style()->gridAutoFlow();
936 ASSERT(flow != AutoFlowNone); 939 return (flow == AutoFlowColumn || flow == AutoFlowColumnDense || flow == Aut oFlowStackColumn) ? ForColumns : ForRows;
937 return (flow == AutoFlowColumn) ? ForColumns : ForRows;
938 } 940 }
939 941
940 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const 942 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const
941 { 943 {
942 GridAutoFlow flow = style()->gridAutoFlow(); 944 GridAutoFlow flow = style()->gridAutoFlow();
943 ASSERT(flow != AutoFlowNone); 945 return (flow == AutoFlowColumn || flow == AutoFlowColumnDense || flow == Aut oFlowStackColumn) ? ForRows : ForColumns;
944 return (flow == AutoFlowColumn) ? ForRows : ForColumns;
945 } 946 }
946 947
947 void RenderGrid::dirtyGrid() 948 void RenderGrid::dirtyGrid()
948 { 949 {
949 m_grid.resize(0); 950 m_grid.resize(0);
950 m_gridItemCoordinate.clear(); 951 m_gridItemCoordinate.clear();
951 m_gridIsDirty = true; 952 m_gridIsDirty = true;
952 m_gridItemsOverflowingGridArea.resize(0); 953 m_gridItemsOverflowingGridArea.resize(0);
953 m_gridItemsIndexesMap.clear(); 954 m_gridItemsIndexesMap.clear();
954 } 955 }
(...skipping 282 matching lines...)
1237 if (isOutOfFlowPositioned()) 1238 if (isOutOfFlowPositioned())
1238 return "RenderGrid (positioned)"; 1239 return "RenderGrid (positioned)";
1239 if (isAnonymous()) 1240 if (isAnonymous())
1240 return "RenderGrid (generated)"; 1241 return "RenderGrid (generated)";
1241 if (isRelPositioned()) 1242 if (isRelPositioned())
1242 return "RenderGrid (relative positioned)"; 1243 return "RenderGrid (relative positioned)";
1243 return "RenderGrid"; 1244 return "RenderGrid";
1244 } 1245 }
1245 1246
1246 } // namespace WebCore 1247 } // namespace WebCore
OLDNEW

Powered by Google App Engine