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

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

Issue 826893002: [CSS Grid Layout] Remove stack from grid-auto-flow syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased patch Created 5 years, 11 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 { 233 {
234 ASSERT(!childrenInline()); 234 ASSERT(!childrenInline());
235 } 235 }
236 236
237 RenderGrid::~RenderGrid() 237 RenderGrid::~RenderGrid()
238 { 238 {
239 } 239 }
240 240
241 void RenderGrid::addChild(RenderObject* newChild, RenderObject* beforeChild) 241 void RenderGrid::addChild(RenderObject* newChild, RenderObject* beforeChild)
242 { 242 {
243 // If the new requested beforeChild is not one of our children is because it 's wrapped by an anonymous container. If
244 // we do not special case this situation we could end up calling addChild() twice for the newChild, one with the
245 // initial beforeChild and another one with its parent.
246 if (beforeChild && beforeChild->parent() != this) {
247 ASSERT(beforeChild->parent()->isAnonymous());
248 beforeChild = splitAnonymousBoxesAroundChild(beforeChild);
249 dirtyGrid();
250 }
251
252 RenderBlock::addChild(newChild, beforeChild); 243 RenderBlock::addChild(newChild, beforeChild);
253 244
254 if (gridIsDirty()) 245 if (gridIsDirty())
255 return; 246 return;
256 247
257 if (!newChild->isBox()) { 248 // The grid needs to be recomputed as it might contain auto-placed items tha t will change their position.
258 dirtyGrid(); 249 dirtyGrid();
259 return; 250 return;
260 }
261
262 // Positioned items shouldn't take up space or otherwise participate in the layout of the grid.
263 if (newChild->isOutOfFlowPositioned())
264 return;
265
266 // If the new child has been inserted inside an existent anonymous block, we can simply ignore it as the anonymous
267 // block is an already known grid item.
268 if (newChild->parent() != this)
269 return;
270
271 // FIXME: Implement properly "stack" value in auto-placement algorithm.
272 if (!style()->isGridAutoFlowAlgorithmStack()) {
273 // The grid needs to be recomputed as it might contain auto-placed items that will change their position.
274 dirtyGrid();
275 return;
276 }
277
278 RenderBox* newChildBox = toRenderBox(newChild);
279 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositionsFr omStyle(*style(), *newChildBox, ForRows);
280 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosition sFromStyle(*style(), *newChildBox, ForColumns);
281 if (!rowPositions || !columnPositions) {
282 // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully.
283 dirtyGrid();
284 return;
285 } else {
286 insertItemIntoGrid(*newChildBox, GridCoordinate(*rowPositions, *columnPo sitions));
287 addChildToIndexesMap(*newChildBox);
288 }
289 }
290
291 void RenderGrid::addChildToIndexesMap(RenderBox& child)
292 {
293 ASSERT(!m_gridItemsIndexesMap.contains(&child));
294 RenderBox* sibling = child.nextInFlowSiblingBox();
295 bool lastSibling = !sibling;
296
297 if (lastSibling)
298 sibling = child.previousInFlowSiblingBox();
299
300 size_t index = 0;
301 if (sibling)
302 index = lastSibling ? m_gridItemsIndexesMap.get(sibling) + 1 : m_gridIte msIndexesMap.get(sibling);
303
304 if (sibling && !lastSibling) {
305 for (; sibling; sibling = sibling->nextInFlowSiblingBox())
306 m_gridItemsIndexesMap.set(sibling, m_gridItemsIndexesMap.get(sibling ) + 1);
307 }
308
309 m_gridItemsIndexesMap.set(&child, index);
310 } 251 }
311 252
312 void RenderGrid::removeChild(RenderObject* child) 253 void RenderGrid::removeChild(RenderObject* child)
313 { 254 {
314 RenderBlock::removeChild(child); 255 RenderBlock::removeChild(child);
315 256
316 if (gridIsDirty()) 257 if (gridIsDirty())
317 return; 258 return;
318 259
319 ASSERT(child->isBox()); 260 // The grid needs to be recomputed as it might contain auto-placed items tha t will change their position.
320 261 dirtyGrid();
321 // FIXME: Implement properly "stack" value in auto-placement algorithm. 262 return;
322 if (!style()->isGridAutoFlowAlgorithmStack()) {
323 // The grid needs to be recomputed as it might contain auto-placed items that will change their position.
324 dirtyGrid();
325 return;
326 }
327
328 if (child->isOutOfFlowPositioned())
329 return;
330
331 const RenderBox* childBox = toRenderBox(child);
332 GridCoordinate coordinate = m_gridItemCoordinate.take(childBox);
333
334 for (GridSpan::iterator row = coordinate.rows.begin(); row != coordinate.row s.end(); ++row) {
335 for (GridSpan::iterator column = coordinate.columns.begin(); column != c oordinate.columns.end(); ++column) {
336 GridCell& cell = m_grid[row.toInt()][column.toInt()];
337 cell.remove(cell.find(childBox));
338 }
339 }
340
341 m_gridItemsIndexesMap.remove(childBox);
342 } 263 }
343 264
344 void RenderGrid::styleDidChange(StyleDifference diff, const RenderStyle* oldStyl e) 265 void RenderGrid::styleDidChange(StyleDifference diff, const RenderStyle* oldStyl e)
345 { 266 {
346 RenderBlock::styleDidChange(diff, oldStyle); 267 RenderBlock::styleDidChange(diff, oldStyle);
347 if (!oldStyle) 268 if (!oldStyle)
348 return; 269 return;
349 270
350 // FIXME: The following checks could be narrowed down if we kept track of wh ich type of grid items we have: 271 // FIXME: The following checks could be narrowed down if we kept track of wh ich type of grid items we have:
351 // - explicit grid size changes impact negative explicitely positioned and a uto-placed grid items. 272 // - explicit grid size changes impact negative explicitely positioned and a uto-placed grid items.
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 else 876 else
956 specifiedMajorAxisAutoGridItems.append(child); 877 specifiedMajorAxisAutoGridItems.append(child);
957 continue; 878 continue;
958 } 879 }
959 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPosition s)); 880 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPosition s));
960 } 881 }
961 882
962 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style() )); 883 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style() ));
963 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s tyle())); 884 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s tyle()));
964 885
965 // FIXME: Implement properly "stack" value in auto-placement algorithm.
966 if (style()->isGridAutoFlowAlgorithmStack()) {
967 // If we did collect some grid items, they won't be placed thus never la id out.
968 ASSERT(!autoMajorAxisAutoGridItems.size());
969 ASSERT(!specifiedMajorAxisAutoGridItems.size());
970 return;
971 }
972
973 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); 886 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems);
974 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); 887 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems);
975 888
976 m_grid.shrinkToFit(); 889 m_grid.shrinkToFit();
977 } 890 }
978 891
979 void RenderGrid::populateExplicitGridAndOrderIterator() 892 void RenderGrid::populateExplicitGridAndOrderIterator()
980 { 893 {
981 OrderIteratorPopulator populator(m_orderIterator); 894 OrderIteratorPopulator populator(m_orderIterator);
982 895
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 if (isOutOfFlowPositioned()) 1628 if (isOutOfFlowPositioned())
1716 return "RenderGrid (positioned)"; 1629 return "RenderGrid (positioned)";
1717 if (isAnonymous()) 1630 if (isAnonymous())
1718 return "RenderGrid (generated)"; 1631 return "RenderGrid (generated)";
1719 if (isRelPositioned()) 1632 if (isRelPositioned())
1720 return "RenderGrid (relative positioned)"; 1633 return "RenderGrid (relative positioned)";
1721 return "RenderGrid"; 1634 return "RenderGrid";
1722 } 1635 }
1723 1636
1724 } // namespace blink 1637 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | Source/core/rendering/style/GridResolvedPosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698