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

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

Issue 198703004: [CSS Grid Layout] Fix issues adding new items to grid (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@enable-css-grid-layout
Patch Set: Update growGrid() to grow several positions at a time Created 6 years, 9 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/rendering/RenderGrid.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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 RenderBlock::addChild(newChild, beforeChild); 184 RenderBlock::addChild(newChild, beforeChild);
185 185
186 if (gridIsDirty()) 186 if (gridIsDirty())
187 return; 187 return;
188 188
189 if (!newChild->isBox()) { 189 if (!newChild->isBox()) {
190 dirtyGrid(); 190 dirtyGrid();
191 return; 191 return;
192 } 192 }
193 193
194 if (style()->gridAutoFlow() != AutoFlowNone) {
195 // The grid needs to be recomputed as it might contain auto-placed items that will change their position.
196 dirtyGrid();
197 return;
198 }
199
194 RenderBox* newChildBox = toRenderBox(newChild); 200 RenderBox* newChildBox = toRenderBox(newChild);
195 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F orRows); 201 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F orRows);
196 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox , ForColumns); 202 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox , ForColumns);
197 if (!rowPositions || !columnPositions) { 203 if (!rowPositions || !columnPositions) {
198 // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully. 204 // The new child requires the auto-placement algorithm to run so we need to recompute the grid fully.
199 dirtyGrid(); 205 dirtyGrid();
200 } else { 206 return;
201 if (gridRowCount() <= rowPositions->finalPositionIndex || gridColumnCoun t() <= columnPositions->finalPositionIndex) {
202 // FIXME: We could just insert the new child provided we had a primi tive to arbitrarily grow the grid.
203 dirtyGrid();
204 } else {
205 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *colum nPositions));
206 }
207 } 207 }
208
209 // Grow grid if required.
Julien - ping for review 2014/03/21 18:27:19 Maybe we could turn that into a better comment: /
210 if (gridRowCount() <= rowPositions->finalPositionIndex)
211 growGrid(ForRows, rowPositions->finalPositionIndex - gridRowCount() + 1) ;
212 if (gridColumnCount() <= columnPositions->finalPositionIndex)
213 growGrid(ForColumns, columnPositions->finalPositionIndex - gridColumnCou nt() + 1);
214
215 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *columnPositio ns));
208 } 216 }
209 217
210 void RenderGrid::removeChild(RenderObject* child) 218 void RenderGrid::removeChild(RenderObject* child)
211 { 219 {
212 RenderBlock::removeChild(child); 220 RenderBlock::removeChild(child);
213 221
214 if (gridIsDirty()) 222 if (gridIsDirty())
215 return; 223 return;
216 224
217 ASSERT(child->isBox()); 225 ASSERT(child->isBox());
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 for (size_t i = 0; i < tracks.size(); ++i) { 710 for (size_t i = 0; i < tracks.size(); ++i) {
703 const GridTrackSize& trackSize = gridTrackSize(direction, i); 711 const GridTrackSize& trackSize = gridTrackSize(direction, i);
704 const GridLength& minTrackBreadth = trackSize.minTrackBreadth(); 712 const GridLength& minTrackBreadth = trackSize.minTrackBreadth();
705 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].m_usedBreadth) 713 if (computeUsedBreadthOfMinLength(direction, minTrackBreadth) > tracks[i ].m_usedBreadth)
706 return false; 714 return false;
707 } 715 }
708 return true; 716 return true;
709 } 717 }
710 #endif 718 #endif
711 719
712 void RenderGrid::growGrid(GridTrackSizingDirection direction) 720 void RenderGrid::growGrid(GridTrackSizingDirection direction, size_t positions)
Julien - ping for review 2014/03/21 18:27:19 How about we pass in the _maximum_ position we wan
713 { 721 {
722 ASSERT(positions >= 1);
723
714 if (direction == ForColumns) { 724 if (direction == ForColumns) {
715 const size_t oldColumnSize = m_grid[0].size(); 725 const size_t oldColumnSize = m_grid[0].size();
716 for (size_t row = 0; row < m_grid.size(); ++row) 726 for (size_t row = 0; row < m_grid.size(); ++row)
717 m_grid[row].grow(oldColumnSize + 1); 727 m_grid[row].grow(oldColumnSize + positions);
718 } else { 728 } else {
719 const size_t oldRowSize = m_grid.size(); 729 const size_t oldRowSize = m_grid.size();
720 m_grid.grow(oldRowSize + 1); 730 m_grid.grow(oldRowSize + positions);
721 m_grid[oldRowSize].grow(m_grid[0].size()); 731 for (size_t row = oldRowSize; row < m_grid.size(); ++row)
732 m_grid[row].grow(m_grid[0].size());
722 } 733 }
723 } 734 }
724 735
725 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor dinate) 736 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor dinate)
726 { 737 {
727 for (size_t row = coordinate.rows.initialPositionIndex; row <= coordinate.ro ws.finalPositionIndex; ++row) { 738 for (size_t row = coordinate.rows.initialPositionIndex; row <= coordinate.ro ws.finalPositionIndex; ++row) {
728 for (size_t column = coordinate.columns.initialPositionIndex; column <= coordinate.columns.finalPositionIndex; ++column) 739 for (size_t column = coordinate.columns.initialPositionIndex; column <= coordinate.columns.finalPositionIndex; ++column)
729 m_grid[row][column].append(child); 740 m_grid[row][column].append(child);
730 } 741 }
731 742
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems) 828 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au toGridItems)
818 { 829 {
819 for (size_t i = 0; i < autoGridItems.size(); ++i) { 830 for (size_t i = 0; i < autoGridItems.size(); ++i) {
820 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection()); 831 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto GridItems[i], autoPlacementMajorAxisDirection());
821 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex); 832 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx isPositions->initialPositionIndex);
822 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) { 833 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea()) {
823 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi tionIndex, emptyGridArea->columns.initialPositionIndex); 834 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi tionIndex, emptyGridArea->columns.initialPositionIndex);
824 continue; 835 continue;
825 } 836 }
826 837
827 growGrid(autoPlacementMinorAxisDirection()); 838 growGrid(autoPlacementMinorAxisDirection(), 1);
828 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); 839 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea();
829 ASSERT(emptyGridArea); 840 ASSERT(emptyGridArea);
830 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); 841 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex);
831 } 842 }
832 } 843 }
833 844
834 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems) 845 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri dItems)
835 { 846 {
836 for (size_t i = 0; i < autoGridItems.size(); ++i) 847 for (size_t i = 0; i < autoGridItems.size(); ++i)
837 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); 848 placeAutoMajorAxisItemOnGrid(autoGridItems[i]);
(...skipping 18 matching lines...) Expand all
856 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a()) { 867 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre a()) {
857 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex); 868 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition Index, emptyGridArea->columns.initialPositionIndex);
858 return; 869 return;
859 } 870 }
860 } 871 }
861 } 872 }
862 873
863 // We didn't find an empty grid area so we need to create an extra major axi s line and insert our gridItem in it. 874 // We didn't find an empty grid area so we need to create an extra major axi s line and insert our gridItem in it.
864 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? m_grid[0].size() : minorAxisIndex; 875 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? m_grid[0].size() : minorAxisIndex;
865 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? minorAxisIndex : m_grid.size(); 876 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ? minorAxisIndex : m_grid.size();
866 growGrid(autoPlacementMajorAxisDirection()); 877 growGrid(autoPlacementMajorAxisDirection(), 1);
867 insertItemIntoGrid(gridItem, rowIndex, columnIndex); 878 insertItemIntoGrid(gridItem, rowIndex, columnIndex);
868 } 879 }
869 880
870 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const 881 GridTrackSizingDirection RenderGrid::autoPlacementMajorAxisDirection() const
871 { 882 {
872 GridAutoFlow flow = style()->gridAutoFlow(); 883 GridAutoFlow flow = style()->gridAutoFlow();
873 ASSERT(flow != AutoFlowNone); 884 ASSERT(flow != AutoFlowNone);
874 return (flow == AutoFlowColumn) ? ForColumns : ForRows; 885 return (flow == AutoFlowColumn) ? ForColumns : ForRows;
875 } 886 }
876 887
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 if (isOutOfFlowPositioned()) 1393 if (isOutOfFlowPositioned())
1383 return "RenderGrid (positioned)"; 1394 return "RenderGrid (positioned)";
1384 if (isAnonymous()) 1395 if (isAnonymous())
1385 return "RenderGrid (generated)"; 1396 return "RenderGrid (generated)";
1386 if (isRelPositioned()) 1397 if (isRelPositioned())
1387 return "RenderGrid (relative positioned)"; 1398 return "RenderGrid (relative positioned)";
1388 return "RenderGrid"; 1399 return "RenderGrid";
1389 } 1400 }
1390 1401
1391 } // namespace WebCore 1402 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderGrid.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698