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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutGrid.h

Issue 2654533003: [css-grid] Move the track sizing algorithm to its own class (Closed)
Patch Set: Win build fix Created 3 years, 10 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef LayoutGrid_h 26 #ifndef LayoutGrid_h
27 #define LayoutGrid_h 27 #define LayoutGrid_h
28 28
29 #include "core/layout/Grid.h"
30 #include "core/layout/GridTrackSizingAlgorithm.h"
29 #include "core/layout/LayoutBlock.h" 31 #include "core/layout/LayoutBlock.h"
30 #include "core/layout/OrderIterator.h" 32 #include "core/layout/OrderIterator.h"
31 #include "core/style/GridPositionsResolver.h" 33 #include "core/style/GridPositionsResolver.h"
32 #include <memory> 34 #include <memory>
33 35
34 namespace blink { 36 namespace blink {
35 37
36 struct ContentAlignmentData; 38 struct ContentAlignmentData;
37 struct GridArea; 39 struct GridArea;
38 struct GridSpan; 40 struct GridSpan;
39 class GridTrack;
40 41
41 enum TrackSizeComputationPhase {
42 ResolveIntrinsicMinimums,
43 ResolveContentBasedMinimums,
44 ResolveMaxContentMinimums,
45 ResolveIntrinsicMaximums,
46 ResolveMaxContentMaximums,
47 MaximizeTracks,
48 };
49 enum GridAxisPosition { GridAxisStart, GridAxisEnd, GridAxisCenter }; 42 enum GridAxisPosition { GridAxisStart, GridAxisEnd, GridAxisCenter };
50 43
51 class LayoutGrid final : public LayoutBlock { 44 class LayoutGrid final : public LayoutBlock {
52 public: 45 public:
53 explicit LayoutGrid(Element*); 46 explicit LayoutGrid(Element*);
54 ~LayoutGrid() override; 47 ~LayoutGrid() override;
55 48
56 static LayoutGrid* createAnonymous(Document*); 49 static LayoutGrid* createAnonymous(Document*);
57 const char* name() const override { return "LayoutGrid"; } 50 const char* name() const override { return "LayoutGrid"; }
58 51
59 void layoutBlock(bool relayoutChildren) override; 52 void layoutBlock(bool relayoutChildren) override;
60 53
61 void dirtyGrid(); 54 void dirtyGrid();
62 55
63 Vector<LayoutUnit> trackSizesForComputedStyle(GridTrackSizingDirection) const; 56 Vector<LayoutUnit> trackSizesForComputedStyle(GridTrackSizingDirection) const;
64 57
65 const Vector<LayoutUnit>& columnPositions() const { 58 const Vector<LayoutUnit>& columnPositions() const {
66 DCHECK(!m_grid.needsItemsPlacement()); 59 DCHECK(!m_grid.needsItemsPlacement());
67 return m_columnPositions; 60 return m_columnPositions;
68 } 61 }
69 62
70 const Vector<LayoutUnit>& rowPositions() const { 63 const Vector<LayoutUnit>& rowPositions() const {
71 DCHECK(!m_grid.needsItemsPlacement()); 64 DCHECK(!m_grid.needsItemsPlacement());
72 return m_rowPositions; 65 return m_rowPositions;
73 } 66 }
74 67
75 typedef Vector<LayoutBox*, 1> GridCell;
76 const GridCell& gridCell(int row, int column) const { 68 const GridCell& gridCell(int row, int column) const {
77 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); 69 SECURITY_DCHECK(!m_grid.needsItemsPlacement());
78 return m_grid.cell(row, column); 70 return m_grid.cell(row, column);
79 } 71 }
80 72
81 const Vector<LayoutBox*>& itemsOverflowingGridArea() const { 73 const Vector<LayoutBox*>& itemsOverflowingGridArea() const {
82 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); 74 SECURITY_DCHECK(!m_grid.needsItemsPlacement());
83 return m_gridItemsOverflowingGridArea; 75 return m_gridItemsOverflowingGridArea;
84 } 76 }
85 77
86 int paintIndexForGridItem(const LayoutBox* layoutBox) const { 78 int paintIndexForGridItem(const LayoutBox* layoutBox) const {
87 SECURITY_DCHECK(!m_grid.needsItemsPlacement()); 79 SECURITY_DCHECK(!m_grid.needsItemsPlacement());
88 return m_grid.gridItemPaintOrder(*layoutBox); 80 return m_grid.gridItemPaintOrder(*layoutBox);
89 } 81 }
90 82
91 size_t autoRepeatCountForDirection(GridTrackSizingDirection direction) const { 83 size_t autoRepeatCountForDirection(GridTrackSizingDirection direction) const {
92 return m_grid.autoRepeatTracks(direction); 84 return m_grid.autoRepeatTracks(direction);
93 } 85 }
94 86
95 LayoutUnit translateRTLCoordinate(LayoutUnit) const; 87 LayoutUnit translateRTLCoordinate(LayoutUnit) const;
96 88
89 // TODO(svillar): We need these for the GridTrackSizingAlgorithm. Let's figure
90 // it out how to remove this dependency.
91 LayoutUnit guttersSize(const Grid&,
92 GridTrackSizingDirection,
93 size_t startLine,
94 size_t span,
95 SizingOperation) const;
96 bool cachedHasDefiniteLogicalHeight() const;
97 bool isOrthogonalChild(const LayoutBox&) const;
98
97 private: 99 private:
98 bool isOfType(LayoutObjectType type) const override { 100 bool isOfType(LayoutObjectType type) const override {
99 return type == LayoutObjectLayoutGrid || LayoutBlock::isOfType(type); 101 return type == LayoutObjectLayoutGrid || LayoutBlock::isOfType(type);
100 } 102 }
101 void computeIntrinsicLogicalWidths( 103 void computeIntrinsicLogicalWidths(
102 LayoutUnit& minLogicalWidth, 104 LayoutUnit& minLogicalWidth,
103 LayoutUnit& maxLogicalWidth) const override; 105 LayoutUnit& maxLogicalWidth) const override;
104 106
105 LayoutUnit computeIntrinsicLogicalContentHeightUsing( 107 LayoutUnit computeIntrinsicLogicalContentHeightUsing(
106 const Length& logicalHeightLength, 108 const Length& logicalHeightLength,
107 LayoutUnit intrinsicContentHeight, 109 LayoutUnit intrinsicContentHeight,
108 LayoutUnit borderAndPadding) const override; 110 LayoutUnit borderAndPadding) const override;
109 111
110 void addChild(LayoutObject* newChild, 112 void addChild(LayoutObject* newChild,
111 LayoutObject* beforeChild = nullptr) override; 113 LayoutObject* beforeChild = nullptr) override;
112 void removeChild(LayoutObject*) override; 114 void removeChild(LayoutObject*) override;
113 115
114 void styleDidChange(StyleDifference, const ComputedStyle*) override; 116 void styleDidChange(StyleDifference, const ComputedStyle*) override;
115 117
116 bool explicitGridDidResize(const ComputedStyle&) const; 118 bool explicitGridDidResize(const ComputedStyle&) const;
117 bool namedGridLinesDefinitionDidChange(const ComputedStyle&) const; 119 bool namedGridLinesDefinitionDidChange(const ComputedStyle&) const;
118 120
119 class Grid;
120 class GridIterator;
121 struct GridSizingData;
122 enum SizingOperation { TrackSizing, IntrinsicSizeComputation };
123 void computeUsedBreadthOfGridTracks(
124 GridTrackSizingDirection,
125 GridSizingData&,
126 LayoutUnit& baseSizesWithoutMaximization,
127 LayoutUnit& growthLimitsWithoutMaximization) const;
128 void computeFlexSizedTracksGrowth(
129 GridTrackSizingDirection,
130 Vector<GridTrack>&,
131 const Vector<size_t>& flexibleSizedTracksIndex,
132 double flexFraction,
133 Vector<LayoutUnit>& increments,
134 LayoutUnit& totalGrowth,
135 const GridSizingData&) const;
136 LayoutUnit computeUsedBreadthOfMinLength(const GridTrackSize&,
137 LayoutUnit maxBreadth) const;
138 LayoutUnit computeUsedBreadthOfMaxLength(const GridTrackSize&,
139 LayoutUnit usedBreadth,
140 LayoutUnit maxBreadth) const;
141 void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection,
142 GridSizingData&) const;
143
144 size_t computeAutoRepeatTracksCount(GridTrackSizingDirection, 121 size_t computeAutoRepeatTracksCount(GridTrackSizingDirection,
145 SizingOperation) const; 122 SizingOperation) const;
146 123
147 typedef ListHashSet<size_t> OrderedTrackIndexSet;
148 std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat( 124 std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat(
149 Grid&, 125 Grid&,
150 GridTrackSizingDirection) const; 126 GridTrackSizingDirection) const;
151 127
152 void placeItemsOnGrid(Grid&, SizingOperation) const; 128 void placeItemsOnGrid(Grid&, SizingOperation) const;
153 void populateExplicitGridAndOrderIterator(Grid&) const; 129 void populateExplicitGridAndOrderIterator(Grid&) const;
154 std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( 130 std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(
155 const Grid&, 131 const Grid&,
156 const LayoutBox&, 132 const LayoutBox&,
157 GridTrackSizingDirection, 133 GridTrackSizingDirection,
158 const GridSpan& specifiedPositions) const; 134 const GridSpan& specifiedPositions) const;
159 void placeSpecifiedMajorAxisItemsOnGrid(Grid&, 135 void placeSpecifiedMajorAxisItemsOnGrid(Grid&,
160 const Vector<LayoutBox*>&) const; 136 const Vector<LayoutBox*>&) const;
161 void placeAutoMajorAxisItemsOnGrid(Grid&, const Vector<LayoutBox*>&) const; 137 void placeAutoMajorAxisItemsOnGrid(Grid&, const Vector<LayoutBox*>&) const;
162 void placeAutoMajorAxisItemOnGrid( 138 void placeAutoMajorAxisItemOnGrid(
163 Grid&, 139 Grid&,
164 LayoutBox&, 140 LayoutBox&,
165 std::pair<size_t, size_t>& autoPlacementCursor) const; 141 std::pair<size_t, size_t>& autoPlacementCursor) const;
166 GridTrackSizingDirection autoPlacementMajorAxisDirection() const; 142 GridTrackSizingDirection autoPlacementMajorAxisDirection() const;
167 GridTrackSizingDirection autoPlacementMinorAxisDirection() const; 143 GridTrackSizingDirection autoPlacementMinorAxisDirection() const;
168 144
169 void computeTrackSizesForIndefiniteSize(GridTrackSizingDirection, 145 void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&,
170 GridSizingData&, 146 GridTrackSizingDirection,
147 Grid&,
171 LayoutUnit& minIntrinsicSize, 148 LayoutUnit& minIntrinsicSize,
172 LayoutUnit& maxIntrinsicSize) const; 149 LayoutUnit& maxIntrinsicSize) const;
173 LayoutUnit computeTrackBasedLogicalHeight(const GridSizingData&) const; 150 LayoutUnit computeTrackBasedLogicalHeight() const;
174 void computeTrackSizesForDefiniteSize(GridTrackSizingDirection, 151 void computeTrackSizesForDefiniteSize(GridTrackSizingDirection,
175 GridSizingData&, 152 LayoutUnit freeSpace);
176 LayoutUnit freeSpace) const;
177 153
178 void repeatTracksSizingIfNeeded(GridSizingData&, 154 void repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns,
179 LayoutUnit availableSpaceForColumns,
180 LayoutUnit availableSpaceForRows); 155 LayoutUnit availableSpaceForRows);
181 156
182 void layoutGridItems(GridSizingData&); 157 void layoutGridItems();
183 void prepareChildForPositionedLayout(LayoutBox&); 158 void prepareChildForPositionedLayout(LayoutBox&);
184 void layoutPositionedObjects( 159 void layoutPositionedObjects(
185 bool relayoutChildren, 160 bool relayoutChildren,
186 PositionedLayoutBehavior = DefaultLayout) override; 161 PositionedLayoutBehavior = DefaultLayout) override;
187 void offsetAndBreadthForPositionedChild(const LayoutBox&, 162 void offsetAndBreadthForPositionedChild(const LayoutBox&,
188 GridTrackSizingDirection, 163 GridTrackSizingDirection,
189 LayoutUnit& offset, 164 LayoutUnit& offset,
190 LayoutUnit& breadth); 165 LayoutUnit& breadth);
191 void populateGridPositionsForDirection(GridSizingData&, 166 void populateGridPositionsForDirection(GridTrackSizingDirection);
192 GridTrackSizingDirection);
193 167
194 typedef struct GridItemsSpanGroupRange GridItemsSpanGroupRange;
195 LayoutUnit currentItemSizeForTrackSizeComputationPhase(
196 TrackSizeComputationPhase,
197 LayoutBox&,
198 GridTrackSizingDirection,
199 GridSizingData&) const;
200 void resolveContentBasedTrackSizingFunctionsForNonSpanningItems(
201 GridTrackSizingDirection,
202 const GridSpan&,
203 LayoutBox& gridItem,
204 GridTrack&,
205 GridSizingData&) const;
206 template <TrackSizeComputationPhase>
207 void resolveContentBasedTrackSizingFunctionsForItems(
208 GridTrackSizingDirection,
209 GridSizingData&,
210 const GridItemsSpanGroupRange&) const;
211 template <TrackSizeComputationPhase>
212 void distributeSpaceToTracks(Vector<GridTrack*>&,
213 Vector<GridTrack*>* growBeyondGrowthLimitsTracks,
214 GridSizingData&,
215 LayoutUnit& availableLogicalSpace) const;
216
217 typedef HashSet<size_t,
218 DefaultHash<size_t>::Hash,
219 WTF::UnsignedWithZeroKeyHashTraits<size_t>>
220 TrackIndexSet;
221 double computeFlexFactorUnitSize(
222 const Vector<GridTrack>&,
223 GridTrackSizingDirection,
224 double flexFactorSum,
225 LayoutUnit& leftOverSpace,
226 const Vector<size_t, 8>& flexibleTracksIndexes,
227 const GridSizingData&,
228 std::unique_ptr<TrackIndexSet> tracksToTreatAsInflexible = nullptr) const;
229 double findFlexFactorUnitSize(const Vector<GridTrack>&,
230 const GridSpan&,
231 GridTrackSizingDirection,
232 LayoutUnit leftOverSpace,
233 const GridSizingData&) const;
234
235 const GridTrackSize& rawGridTrackSize(GridTrackSizingDirection,
236 size_t,
237 const GridSizingData&) const;
238 GridTrackSize gridTrackSize(GridTrackSizingDirection,
239 size_t,
240 const GridSizingData&) const;
241
242 bool updateOverrideContainingBlockContentSizeForChild(
243 LayoutBox&,
244 GridTrackSizingDirection,
245 GridSizingData&) const;
246 LayoutUnit logicalHeightForChild(LayoutBox&, GridSizingData&) const;
247 LayoutUnit minSizeForChild(LayoutBox&,
248 GridTrackSizingDirection,
249 GridSizingData&) const;
250 LayoutUnit minContentForChild(LayoutBox&,
251 GridTrackSizingDirection,
252 GridSizingData&) const;
253 LayoutUnit maxContentForChild(LayoutBox&,
254 GridTrackSizingDirection,
255 GridSizingData&) const;
256 GridAxisPosition columnAxisPositionForChild(const LayoutBox&) const; 168 GridAxisPosition columnAxisPositionForChild(const LayoutBox&) const;
257 GridAxisPosition rowAxisPositionForChild(const LayoutBox&) const; 169 GridAxisPosition rowAxisPositionForChild(const LayoutBox&) const;
258 LayoutUnit rowAxisOffsetForChild(const LayoutBox&, GridSizingData&) const; 170 LayoutUnit rowAxisOffsetForChild(const LayoutBox&) const;
259 LayoutUnit columnAxisOffsetForChild(const LayoutBox&, GridSizingData&) const; 171 LayoutUnit columnAxisOffsetForChild(const LayoutBox&) const;
260 ContentAlignmentData computeContentPositionAndDistributionOffset( 172 ContentAlignmentData computeContentPositionAndDistributionOffset(
261 GridTrackSizingDirection, 173 GridTrackSizingDirection,
262 const LayoutUnit& availableFreeSpace, 174 const LayoutUnit& availableFreeSpace,
263 unsigned numberOfGridTracks) const; 175 unsigned numberOfGridTracks) const;
264 LayoutPoint gridAreaLogicalPosition(const GridArea&) const; 176 LayoutPoint gridAreaLogicalPosition(const GridArea&) const;
265 LayoutPoint findChildLogicalPosition(const LayoutBox&, GridSizingData&) const; 177 LayoutPoint findChildLogicalPosition(const LayoutBox&) const;
266 GridArea cachedGridArea(const LayoutBox&) const;
267 GridSpan cachedGridSpan(const LayoutBox&, GridTrackSizingDirection) const;
268 178
269 LayoutUnit gridAreaBreadthForChild(const LayoutBox& child,
270 GridTrackSizingDirection,
271 const GridSizingData&) const;
272 LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets( 179 LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(
273 const LayoutBox&, 180 const LayoutBox&,
274 GridTrackSizingDirection, 181 GridTrackSizingDirection) const;
275 const GridSizingData&) const;
276 LayoutUnit assumedRowsSizeForOrthogonalChild(const LayoutBox&,
277 const GridSizingData&) const;
278 182
279 void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection, 183 void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection);
280 GridSizingData&);
281 184
282 void paintChildren(const PaintInfo&, const LayoutPoint&) const override; 185 void paintChildren(const PaintInfo&, const LayoutPoint&) const override;
283 186
284 LayoutUnit marginLogicalHeightForChild(const LayoutBox&) const; 187 LayoutUnit marginLogicalHeightForChild(const LayoutBox&) const;
285 LayoutUnit computeMarginLogicalSizeForChild(MarginDirection, 188 LayoutUnit computeMarginLogicalSizeForChild(MarginDirection,
286 const LayoutBox&) const; 189 const LayoutBox&) const;
287 LayoutUnit availableAlignmentSpaceForChildBeforeStretching( 190 LayoutUnit availableAlignmentSpaceForChildBeforeStretching(
288 LayoutUnit gridAreaBreadthForChild, 191 LayoutUnit gridAreaBreadthForChild,
289 const LayoutBox&) const; 192 const LayoutBox&) const;
290 StyleSelfAlignmentData justifySelfForChild(const LayoutBox&) const; 193 StyleSelfAlignmentData justifySelfForChild(const LayoutBox&) const;
(...skipping 22 matching lines...) Expand all
313 216
314 int baselinePosition( 217 int baselinePosition(
315 FontBaseline, 218 FontBaseline,
316 bool firstLine, 219 bool firstLine,
317 LineDirectionMode, 220 LineDirectionMode,
318 LinePositionMode = PositionOnContainingLine) const override; 221 LinePositionMode = PositionOnContainingLine) const override;
319 int firstLineBoxBaseline() const override; 222 int firstLineBoxBaseline() const override;
320 int inlineBlockBaseline(LineDirectionMode) const override; 223 int inlineBlockBaseline(LineDirectionMode) const override;
321 bool isInlineBaselineAlignedChild(const LayoutBox* child) const; 224 bool isInlineBaselineAlignedChild(const LayoutBox* child) const;
322 225
323 #if DCHECK_IS_ON()
324 bool tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection,
325 GridSizingData&) const;
326 #endif
327
328 LayoutUnit gridGapForDirection(GridTrackSizingDirection, 226 LayoutUnit gridGapForDirection(GridTrackSizingDirection,
329 SizingOperation) const; 227 SizingOperation) const;
330 LayoutUnit guttersSize(const Grid&,
331 GridTrackSizingDirection,
332 size_t startLine,
333 size_t span,
334 SizingOperation) const;
335 228
336 size_t gridItemSpan(const LayoutBox&, GridTrackSizingDirection); 229 size_t gridItemSpan(const LayoutBox&, GridTrackSizingDirection);
337 bool spanningItemCrossesFlexibleSizedTracks(const GridSpan&,
338 GridTrackSizingDirection,
339 const GridSizingData&) const;
340 230
341 bool isOrthogonalChild(const LayoutBox&) const;
342 GridTrackSizingDirection flowAwareDirectionForChild( 231 GridTrackSizingDirection flowAwareDirectionForChild(
343 const LayoutBox&, 232 const LayoutBox&,
344 GridTrackSizingDirection) const; 233 GridTrackSizingDirection) const;
345 234
346 bool cachedHasDefiniteLogicalHeight() const;
347
348 size_t numTracks(GridTrackSizingDirection, const Grid&) const; 235 size_t numTracks(GridTrackSizingDirection, const Grid&) const;
349 236
350 // TODO(svillar): move into this class once GridIterator is added.
351 typedef Vector<Vector<GridCell>> GridAsMatrix;
352 class Grid final {
353 public:
354 Grid(const LayoutGrid* grid) : m_orderIterator(grid) {}
355
356 size_t numTracks(GridTrackSizingDirection) const;
357
358 void ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize);
359 void insert(LayoutBox&, const GridArea&);
360
361 // Note that out of flow children are not grid items.
362 bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
363
364 // TODO(svillar): move this to SizingData once it's passed to
365 // placeItemsOnGrid.
366 bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
367 void setHasAnyOrthogonalGridItem(bool);
368
369 GridArea gridItemArea(const LayoutBox& item) const;
370 void setGridItemArea(const LayoutBox& item, GridArea);
371
372 GridSpan gridItemSpan(const LayoutBox&, GridTrackSizingDirection) const;
373
374 size_t gridItemPaintOrder(const LayoutBox& item) const;
375 void setGridItemPaintOrder(const LayoutBox& item, size_t order);
376
377 const GridCell& cell(size_t row, size_t column) const {
378 return m_grid[row][column];
379 }
380
381 int smallestTrackStart(GridTrackSizingDirection) const;
382 void setSmallestTracksStart(int rowStart, int columnStart);
383
384 size_t autoRepeatTracks(GridTrackSizingDirection) const;
385 void setAutoRepeatTracks(size_t autoRepeatRows, size_t autoRepeatColumns);
386
387 void setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet>);
388 void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>);
389
390 size_t autoRepeatEmptyTracksCount(GridTrackSizingDirection) const;
391 bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const;
392 bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, size_t) const;
393
394 OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const;
395
396 OrderIterator& orderIterator() { return m_orderIterator; }
397
398 void setNeedsItemsPlacement(bool);
399 bool needsItemsPlacement() const { return m_needsItemsPlacement; };
400
401 #if DCHECK_IS_ON()
402 bool hasAnyGridItemPaintOrder() const;
403 #endif
404
405 private:
406 friend class GridIterator;
407
408 OrderIterator m_orderIterator;
409
410 int m_smallestColumnStart{0};
411 int m_smallestRowStart{0};
412
413 size_t m_autoRepeatColumns{0};
414 size_t m_autoRepeatRows{0};
415
416 bool m_hasAnyOrthogonalGridItem{false};
417 bool m_needsItemsPlacement{true};
418
419 GridAsMatrix m_grid;
420
421 HashMap<const LayoutBox*, GridArea> m_gridItemArea;
422 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap;
423
424 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns{nullptr};
425 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows{nullptr};
426 };
427 Grid m_grid; 237 Grid m_grid;
238 GridTrackSizingAlgorithm m_trackSizingAlgorithm;
428 239
429 Vector<LayoutUnit> m_rowPositions; 240 Vector<LayoutUnit> m_rowPositions;
430 Vector<LayoutUnit> m_columnPositions; 241 Vector<LayoutUnit> m_columnPositions;
431 LayoutUnit m_offsetBetweenColumns; 242 LayoutUnit m_offsetBetweenColumns;
432 LayoutUnit m_offsetBetweenRows; 243 LayoutUnit m_offsetBetweenRows;
433 Vector<LayoutBox*> m_gridItemsOverflowingGridArea; 244 Vector<LayoutBox*> m_gridItemsOverflowingGridArea;
434 245
435 LayoutUnit m_minContentHeight{-1}; 246 LayoutUnit m_minContentHeight{-1};
436 LayoutUnit m_maxContentHeight{-1}; 247 LayoutUnit m_maxContentHeight{-1};
437 248
438 Optional<bool> m_hasDefiniteLogicalHeight; 249 Optional<bool> m_hasDefiniteLogicalHeight;
439 }; 250 };
440 251
441 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); 252 DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid());
442 253
443 } // namespace blink 254 } // namespace blink
444 255
445 #endif // LayoutGrid_h 256 #endif // LayoutGrid_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698