OLD | NEW |
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. | 187 // Performance optimization: hold onto these Vectors until the end of Layout
to avoid repeated malloc / free. |
188 Vector<LayoutUnit> distributeTrackVector; | 188 Vector<LayoutUnit> distributeTrackVector; |
189 Vector<GridTrack*> filteredTracks; | 189 Vector<GridTrack*> filteredTracks; |
190 WillBeHeapVector<GridItemWithSpan> itemsSortedByIncreasingSpan; | 190 WillBeHeapVector<GridItemWithSpan> itemsSortedByIncreasingSpan; |
191 Vector<size_t> growAboveMaxBreadthTrackIndexes; | 191 Vector<size_t> growAboveMaxBreadthTrackIndexes; |
192 }; | 192 }; |
193 | 193 |
194 RenderGrid::RenderGrid(Element* element) | 194 RenderGrid::RenderGrid(Element* element) |
195 : RenderBlock(element) | 195 : RenderBlock(element) |
196 , m_gridIsDirty(true) | 196 , m_gridIsDirty(true) |
| 197 , m_hasAutoPlacedItems(false) |
197 , m_orderIterator(this) | 198 , m_orderIterator(this) |
198 { | 199 { |
199 ASSERT(!childrenInline()); | 200 ASSERT(!childrenInline()); |
200 } | 201 } |
201 | 202 |
202 RenderGrid::~RenderGrid() | 203 RenderGrid::~RenderGrid() |
203 { | 204 { |
204 } | 205 } |
205 | 206 |
206 void RenderGrid::addChild(RenderObject* newChild, RenderObject* beforeChild) | 207 void RenderGrid::addChild(RenderObject* newChild, RenderObject* beforeChild) |
(...skipping 19 matching lines...) Expand all Loading... |
226 | 227 |
227 // Positioned items shouldn't take up space or otherwise participate in the
layout of the grid. | 228 // Positioned items shouldn't take up space or otherwise participate in the
layout of the grid. |
228 if (newChild->isOutOfFlowPositioned()) | 229 if (newChild->isOutOfFlowPositioned()) |
229 return; | 230 return; |
230 | 231 |
231 // If the new child has been inserted inside an existent anonymous block, we
can simply ignore it as the anonymous | 232 // If the new child has been inserted inside an existent anonymous block, we
can simply ignore it as the anonymous |
232 // block is an already known grid item. | 233 // block is an already known grid item. |
233 if (newChild->parent() != this) | 234 if (newChild->parent() != this) |
234 return; | 235 return; |
235 | 236 |
236 // FIXME: Implement properly "stack" value in auto-placement algorithm. | 237 if (hasAutoPlacedItems()) { |
237 if (!style()->isGridAutoFlowAlgorithmStack()) { | 238 // The grid needs to be recomputed as it contains auto-placed items that
might change their position. |
238 // The grid needs to be recomputed as it might contain auto-placed items
that will change their position. | |
239 dirtyGrid(); | 239 dirtyGrid(); |
240 return; | 240 return; |
241 } | 241 } |
242 | 242 |
243 RenderBox* newChildBox = toRenderBox(newChild); | 243 RenderBox* newChildBox = toRenderBox(newChild); |
244 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositionsFr
omStyle(*style(), *newChildBox, ForRows); | 244 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositionsFr
omStyle(*style(), *newChildBox, ForRows); |
245 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosition
sFromStyle(*style(), *newChildBox, ForColumns); | 245 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosition
sFromStyle(*style(), *newChildBox, ForColumns); |
246 if (!rowPositions || !columnPositions) { | 246 if (!rowPositions || !columnPositions) { |
247 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. | 247 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. |
248 dirtyGrid(); | 248 dirtyGrid(); |
(...skipping 27 matching lines...) Expand all Loading... |
276 | 276 |
277 void RenderGrid::removeChild(RenderObject* child) | 277 void RenderGrid::removeChild(RenderObject* child) |
278 { | 278 { |
279 RenderBlock::removeChild(child); | 279 RenderBlock::removeChild(child); |
280 | 280 |
281 if (gridIsDirty()) | 281 if (gridIsDirty()) |
282 return; | 282 return; |
283 | 283 |
284 ASSERT(child->isBox()); | 284 ASSERT(child->isBox()); |
285 | 285 |
286 // FIXME: Implement properly "stack" value in auto-placement algorithm. | 286 if (hasAutoPlacedItems()) { |
287 if (!style()->isGridAutoFlowAlgorithmStack()) { | 287 // The grid needs to be recomputed as it contains auto-placed items that
will change their position. |
288 // The grid needs to be recomputed as it might contain auto-placed items
that will change their position. | |
289 dirtyGrid(); | 288 dirtyGrid(); |
290 return; | 289 return; |
291 } | 290 } |
292 | 291 |
293 if (child->isOutOfFlowPositioned()) | 292 if (child->isOutOfFlowPositioned()) |
294 return; | 293 return; |
295 | 294 |
296 const RenderBox* childBox = toRenderBox(child); | 295 const RenderBox* childBox = toRenderBox(child); |
297 GridCoordinate coordinate = m_gridItemCoordinate.take(childBox); | 296 GridCoordinate coordinate = m_gridItemCoordinate.take(childBox); |
298 | 297 |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 Vector<RenderBox*> specifiedMajorAxisAutoGridItems; | 909 Vector<RenderBox*> specifiedMajorAxisAutoGridItems; |
911 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { | 910 for (RenderBox* child = m_orderIterator.first(); child; child = m_orderItera
tor.next()) { |
912 if (child->isOutOfFlowPositioned()) | 911 if (child->isOutOfFlowPositioned()) |
913 continue; | 912 continue; |
914 | 913 |
915 // FIXME: We never re-resolve positions if the grid is grown during auto
-placement which may lead auto / <integer> | 914 // FIXME: We never re-resolve positions if the grid is grown during auto
-placement which may lead auto / <integer> |
916 // positions to not match the author's intent. The specification is uncl
ear on what should be done in this case. | 915 // positions to not match the author's intent. The specification is uncl
ear on what should be done in this case. |
917 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositio
nsFromStyle(*style(), *child, ForRows); | 916 OwnPtr<GridSpan> rowPositions = GridResolvedPosition::resolveGridPositio
nsFromStyle(*style(), *child, ForRows); |
918 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosi
tionsFromStyle(*style(), *child, ForColumns); | 917 OwnPtr<GridSpan> columnPositions = GridResolvedPosition::resolveGridPosi
tionsFromStyle(*style(), *child, ForColumns); |
919 if (!rowPositions || !columnPositions) { | 918 if (!rowPositions || !columnPositions) { |
| 919 setHasAutoPlacedItems(); |
920 GridSpan* majorAxisPositions = (autoPlacementMajorAxisDirection() ==
ForColumns) ? columnPositions.get() : rowPositions.get(); | 920 GridSpan* majorAxisPositions = (autoPlacementMajorAxisDirection() ==
ForColumns) ? columnPositions.get() : rowPositions.get(); |
921 if (!majorAxisPositions) | 921 if (!majorAxisPositions) |
922 autoMajorAxisAutoGridItems.append(child); | 922 autoMajorAxisAutoGridItems.append(child); |
923 else | 923 else |
924 specifiedMajorAxisAutoGridItems.append(child); | 924 specifiedMajorAxisAutoGridItems.append(child); |
925 continue; | 925 continue; |
926 } | 926 } |
927 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPosition
s)); | 927 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPosition
s)); |
928 } | 928 } |
929 | 929 |
930 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); | 930 ASSERT(gridRowCount() >= GridResolvedPosition::explicitGridRowCount(*style()
)); |
931 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); | 931 ASSERT(gridColumnCount() >= GridResolvedPosition::explicitGridColumnCount(*s
tyle())); |
932 | 932 |
933 // FIXME: Implement properly "stack" value in auto-placement algorithm. | |
934 if (style()->isGridAutoFlowAlgorithmStack()) { | |
935 // If we did collect some grid items, they won't be placed thus never la
id out. | |
936 ASSERT(!autoMajorAxisAutoGridItems.size()); | |
937 ASSERT(!specifiedMajorAxisAutoGridItems.size()); | |
938 return; | |
939 } | |
940 | |
941 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); | 933 placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems); |
942 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); | 934 placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems); |
943 | 935 |
944 m_grid.shrinkToFit(); | 936 m_grid.shrinkToFit(); |
945 } | 937 } |
946 | 938 |
947 void RenderGrid::populateExplicitGridAndOrderIterator() | 939 void RenderGrid::populateExplicitGridAndOrderIterator() |
948 { | 940 { |
949 OrderIteratorPopulator populator(m_orderIterator); | 941 OrderIteratorPopulator populator(m_orderIterator); |
950 | 942 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const | 1078 GridTrackSizingDirection RenderGrid::autoPlacementMinorAxisDirection() const |
1087 { | 1079 { |
1088 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; | 1080 return style()->isGridAutoFlowDirectionColumn() ? ForRows : ForColumns; |
1089 } | 1081 } |
1090 | 1082 |
1091 void RenderGrid::dirtyGrid() | 1083 void RenderGrid::dirtyGrid() |
1092 { | 1084 { |
1093 m_grid.resize(0); | 1085 m_grid.resize(0); |
1094 m_gridItemCoordinate.clear(); | 1086 m_gridItemCoordinate.clear(); |
1095 m_gridIsDirty = true; | 1087 m_gridIsDirty = true; |
| 1088 m_hasAutoPlacedItems = false; |
1096 m_gridItemsOverflowingGridArea.resize(0); | 1089 m_gridItemsOverflowingGridArea.resize(0); |
1097 m_gridItemsIndexesMap.clear(); | 1090 m_gridItemsIndexesMap.clear(); |
1098 } | 1091 } |
1099 | 1092 |
1100 void RenderGrid::layoutGridItems() | 1093 void RenderGrid::layoutGridItems() |
1101 { | 1094 { |
1102 placeItemsOnGrid(); | 1095 placeItemsOnGrid(); |
1103 | 1096 |
1104 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); | 1097 LayoutUnit availableSpaceForColumns = availableLogicalWidth(); |
1105 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); | 1098 LayoutUnit availableSpaceForRows = availableLogicalHeight(IncludeMarginBorde
rPadding); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 if (isOutOfFlowPositioned()) | 1671 if (isOutOfFlowPositioned()) |
1679 return "RenderGrid (positioned)"; | 1672 return "RenderGrid (positioned)"; |
1680 if (isAnonymous()) | 1673 if (isAnonymous()) |
1681 return "RenderGrid (generated)"; | 1674 return "RenderGrid (generated)"; |
1682 if (isRelPositioned()) | 1675 if (isRelPositioned()) |
1683 return "RenderGrid (relative positioned)"; | 1676 return "RenderGrid (relative positioned)"; |
1684 return "RenderGrid"; | 1677 return "RenderGrid"; |
1685 } | 1678 } |
1686 | 1679 |
1687 } // namespace blink | 1680 } // namespace blink |
OLD | NEW |