OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef GridTrackSizingAlgorithm_h | 5 #ifndef GridTrackSizingAlgorithm_h |
6 #define GridTrackSizingAlgorithm_h | 6 #define GridTrackSizingAlgorithm_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
10 #include "core/style/GridPositionsResolver.h" | 10 #include "core/style/GridPositionsResolver.h" |
11 #include "core/style/GridTrackSize.h" | 11 #include "core/style/GridTrackSize.h" |
12 #include "platform/LayoutUnit.h" | 12 #include "platform/LayoutUnit.h" |
13 #include "platform/wtf/HashSet.h" | 13 #include "platform/wtf/HashSet.h" |
14 #include "platform/wtf/Optional.h" | 14 #include "platform/wtf/Optional.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 static const int kInfinity = -1; | 18 static const int kInfinity = -1; |
19 | 19 |
20 class Grid; | 20 class Grid; |
21 class GridTrackSizingAlgorithmStrategy; | 21 class GridTrackSizingAlgorithmStrategy; |
22 class LayoutGrid; | 22 class LayoutGrid; |
23 | 23 |
24 enum SizingOperation { kTrackSizing, kIntrinsicSizeComputation }; | |
25 | |
26 enum TrackSizeComputationPhase { | 24 enum TrackSizeComputationPhase { |
27 kResolveIntrinsicMinimums, | 25 kResolveIntrinsicMinimums, |
28 kResolveContentBasedMinimums, | 26 kResolveContentBasedMinimums, |
29 kResolveMaxContentMinimums, | 27 kResolveMaxContentMinimums, |
30 kResolveIntrinsicMaximums, | 28 kResolveIntrinsicMaximums, |
31 kResolveMaxContentMaximums, | 29 kResolveMaxContentMaximums, |
32 kMaximizeTracks, | 30 kMaximizeTracks, |
33 }; | 31 }; |
34 | 32 |
35 class GridTrack { | 33 class GridTrack { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 public: | 77 public: |
80 GridTrackSizingAlgorithm(const LayoutGrid* layout_grid, Grid& grid) | 78 GridTrackSizingAlgorithm(const LayoutGrid* layout_grid, Grid& grid) |
81 : grid_(grid), | 79 : grid_(grid), |
82 layout_grid_(layout_grid), | 80 layout_grid_(layout_grid), |
83 sizing_state_(kColumnSizingFirstIteration) {} | 81 sizing_state_(kColumnSizingFirstIteration) {} |
84 | 82 |
85 // setup() must be run before calling run() as it configures the behaviour of | 83 // setup() must be run before calling run() as it configures the behaviour of |
86 // the algorithm. | 84 // the algorithm. |
87 void Setup(GridTrackSizingDirection, | 85 void Setup(GridTrackSizingDirection, |
88 size_t num_tracks, | 86 size_t num_tracks, |
89 SizingOperation, | |
90 Optional<LayoutUnit> available_space, | 87 Optional<LayoutUnit> available_space, |
91 Optional<LayoutUnit> free_space); | 88 Optional<LayoutUnit> free_space); |
92 void Run(); | 89 void Run(); |
93 void Reset(); | 90 void Reset(); |
94 | 91 |
95 // Required by LayoutGrid. Try to minimize the exposed surface. | 92 // Required by LayoutGrid. Try to minimize the exposed surface. |
96 const Grid& GetGrid() const { return grid_; } | 93 const Grid& GetGrid() const { return grid_; } |
97 GridTrackSize GetGridTrackSize(GridTrackSizingDirection, | 94 GridTrackSize GetGridTrackSize(GridTrackSizingDirection, |
98 size_t translated_index) const; | 95 size_t translated_index) const; |
99 LayoutUnit MinContentSize() const { return min_content_size_; }; | 96 LayoutUnit MinContentSize() const { return min_content_size_; }; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 Optional<LayoutUnit> free_space_rows_; | 180 Optional<LayoutUnit> free_space_rows_; |
184 | 181 |
185 // We need to keep both alive in order to properly size grids with orthogonal | 182 // We need to keep both alive in order to properly size grids with orthogonal |
186 // writing modes. | 183 // writing modes. |
187 Vector<GridTrack> columns_; | 184 Vector<GridTrack> columns_; |
188 Vector<GridTrack> rows_; | 185 Vector<GridTrack> rows_; |
189 Vector<size_t> content_sized_tracks_index_; | 186 Vector<size_t> content_sized_tracks_index_; |
190 Vector<size_t> flexible_sized_tracks_index_; | 187 Vector<size_t> flexible_sized_tracks_index_; |
191 | 188 |
192 GridTrackSizingDirection direction_; | 189 GridTrackSizingDirection direction_; |
193 SizingOperation sizing_operation_; | |
194 | 190 |
195 Grid& grid_; | 191 Grid& grid_; |
196 | 192 |
197 const LayoutGrid* layout_grid_; | 193 const LayoutGrid* layout_grid_; |
198 std::unique_ptr<GridTrackSizingAlgorithmStrategy> strategy_; | 194 std::unique_ptr<GridTrackSizingAlgorithmStrategy> strategy_; |
199 | 195 |
200 // The track sizing algorithm is used for both layout and intrinsic size | 196 // The track sizing algorithm is used for both layout and intrinsic size |
201 // computation. We're normally just interested in intrinsic inline sizes | 197 // computation. We're normally just interested in intrinsic inline sizes |
202 // (a.k.a widths in most of the cases) for the computeIntrinsicLogicalWidths() | 198 // (a.k.a widths in most of the cases) for the computeIntrinsicLogicalWidths() |
203 // computations. That's why we don't need to keep around different values for | 199 // computations. That's why we don't need to keep around different values for |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 virtual void LayoutGridItemForMinSizeComputation( | 255 virtual void LayoutGridItemForMinSizeComputation( |
260 LayoutBox&, | 256 LayoutBox&, |
261 bool override_size_has_changed) const = 0; | 257 bool override_size_has_changed) const = 0; |
262 | 258 |
263 LayoutUnit LogicalHeightForChild(LayoutBox&) const; | 259 LayoutUnit LogicalHeightForChild(LayoutBox&) const; |
264 | 260 |
265 bool UpdateOverrideContainingBlockContentSizeForChild( | 261 bool UpdateOverrideContainingBlockContentSizeForChild( |
266 LayoutBox&, | 262 LayoutBox&, |
267 GridTrackSizingDirection) const; | 263 GridTrackSizingDirection) const; |
268 LayoutUnit ComputeTrackBasedSize() const; | 264 LayoutUnit ComputeTrackBasedSize() const; |
| 265 Optional<LayoutUnit> ExtentForBaselineAlignment(LayoutBox&) const; |
| 266 |
269 GridTrackSizingDirection Direction() const { return algorithm_.direction_; } | 267 GridTrackSizingDirection Direction() const { return algorithm_.direction_; } |
270 double FindFrUnitSize(const GridSpan& tracks_span, | 268 double FindFrUnitSize(const GridSpan& tracks_span, |
271 LayoutUnit left_over_space) const; | 269 LayoutUnit left_over_space) const; |
272 void DistributeSpaceToTracks(Vector<GridTrack*>& tracks, | 270 void DistributeSpaceToTracks(Vector<GridTrack*>& tracks, |
273 LayoutUnit& available_logical_space) const; | 271 LayoutUnit& available_logical_space) const; |
274 const LayoutGrid* GetLayoutGrid() const { return algorithm_.layout_grid_; } | 272 const LayoutGrid* GetLayoutGrid() const { return algorithm_.layout_grid_; } |
275 Optional<LayoutUnit> AvailableSpace() const { | 273 Optional<LayoutUnit> AvailableSpace() const { |
276 return algorithm_.AvailableSpace(); | 274 return algorithm_.AvailableSpace(); |
277 } | 275 } |
278 | 276 |
(...skipping 18 matching lines...) Expand all Loading... |
297 static GridTrackSizingDirection FlowAwareDirectionForChild( | 295 static GridTrackSizingDirection FlowAwareDirectionForChild( |
298 const LayoutGrid*, | 296 const LayoutGrid*, |
299 const LayoutBox& child, | 297 const LayoutBox& child, |
300 GridTrackSizingDirection); | 298 GridTrackSizingDirection); |
301 | 299 |
302 GridTrackSizingAlgorithm& algorithm_; | 300 GridTrackSizingAlgorithm& algorithm_; |
303 }; | 301 }; |
304 } | 302 } |
305 | 303 |
306 #endif // GridTrackSizingAlgorithm_h | 304 #endif // GridTrackSizingAlgorithm_h |
OLD | NEW |