| 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 "core/style/GridPositionsResolver.h" | 8 #include "core/style/GridPositionsResolver.h" |
| 9 #include "core/style/GridTrackSize.h" | 9 #include "core/style/GridTrackSize.h" |
| 10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 GridTrackSizingAlgorithm(const LayoutGrid* layoutGrid, Grid& grid) | 77 GridTrackSizingAlgorithm(const LayoutGrid* layoutGrid, Grid& grid) |
| 78 : m_grid(grid), | 78 : m_grid(grid), |
| 79 m_layoutGrid(layoutGrid), | 79 m_layoutGrid(layoutGrid), |
| 80 m_sizingState(ColumnSizingFirstIteration) {} | 80 m_sizingState(ColumnSizingFirstIteration) {} |
| 81 | 81 |
| 82 // setup() must be run before calling run() as it configures the behaviour of | 82 // setup() must be run before calling run() as it configures the behaviour of |
| 83 // the algorithm. | 83 // the algorithm. |
| 84 void setup(GridTrackSizingDirection, | 84 void setup(GridTrackSizingDirection, |
| 85 size_t numTracks, | 85 size_t numTracks, |
| 86 SizingOperation, | 86 SizingOperation, |
| 87 LayoutUnit availableSpace, | 87 Optional<LayoutUnit> availableSpace, |
| 88 LayoutUnit freeSpace); | 88 Optional<LayoutUnit> freeSpace); |
| 89 void run(); | 89 void run(); |
| 90 void reset(); | 90 void reset(); |
| 91 | 91 |
| 92 // Required by LayoutGrid. Try to minimize the exposed surface. | 92 // Required by LayoutGrid. Try to minimize the exposed surface. |
| 93 const Grid& grid() const { return m_grid; } | 93 const Grid& grid() const { return m_grid; } |
| 94 GridTrackSize gridTrackSize(GridTrackSizingDirection, | 94 GridTrackSize gridTrackSize(GridTrackSizingDirection, |
| 95 size_t translatedIndex, | 95 size_t translatedIndex, |
| 96 SizingOperation) const; | 96 SizingOperation) const; |
| 97 LayoutUnit minContentSize() const { return m_minContentSize; }; | 97 LayoutUnit minContentSize() const { return m_minContentSize; }; |
| 98 LayoutUnit maxContentSize() const { return m_maxContentSize; }; | 98 LayoutUnit maxContentSize() const { return m_maxContentSize; }; |
| 99 | 99 |
| 100 Vector<GridTrack>& tracks(GridTrackSizingDirection); | 100 Vector<GridTrack>& tracks(GridTrackSizingDirection); |
| 101 const Vector<GridTrack>& tracks(GridTrackSizingDirection) const; | 101 const Vector<GridTrack>& tracks(GridTrackSizingDirection) const; |
| 102 | 102 |
| 103 LayoutUnit& freeSpace(GridTrackSizingDirection); | 103 Optional<LayoutUnit> freeSpace(GridTrackSizingDirection); |
| 104 void setFreeSpace(GridTrackSizingDirection, Optional<LayoutUnit>); |
| 104 | 105 |
| 105 #if DCHECK_IS_ON() | 106 #if DCHECK_IS_ON() |
| 106 bool tracksAreWiderThanMinTrackBreadth() const; | 107 bool tracksAreWiderThanMinTrackBreadth() const; |
| 107 bool isTrackSizingOperation() const { | 108 bool isTrackSizingOperation() const { |
| 108 return m_sizingOperation == TrackSizing; | 109 return m_sizingOperation == TrackSizing; |
| 109 }; | 110 }; |
| 110 #endif | 111 #endif |
| 111 | 112 |
| 112 private: | 113 private: |
| 113 GridTrackSize gridTrackSize(GridTrackSizingDirection, | 114 GridTrackSize gridTrackSize(GridTrackSizingDirection, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 Vector<LayoutUnit>& increments, | 158 Vector<LayoutUnit>& increments, |
| 158 LayoutUnit& totalGrowth) const; | 159 LayoutUnit& totalGrowth) const; |
| 159 double findFrUnitSize(const GridSpan& tracksSpan, | 160 double findFrUnitSize(const GridSpan& tracksSpan, |
| 160 LayoutUnit leftOverSpace) const; | 161 LayoutUnit leftOverSpace) const; |
| 161 | 162 |
| 162 // Track sizing algorithm steps. Note that the "Maximize Tracks" step is done | 163 // Track sizing algorithm steps. Note that the "Maximize Tracks" step is done |
| 163 // entirely inside the strategies, that's why we don't need an additional | 164 // entirely inside the strategies, that's why we don't need an additional |
| 164 // method at thise level. | 165 // method at thise level. |
| 165 void initializeTrackSizes(); | 166 void initializeTrackSizes(); |
| 166 void resolveIntrinsicTrackSizes(); | 167 void resolveIntrinsicTrackSizes(); |
| 167 void stretchFlexibleTracks(LayoutUnit freeSpace); | 168 void stretchFlexibleTracks(Optional<LayoutUnit> freeSpace); |
| 168 | 169 |
| 169 // State machine. | 170 // State machine. |
| 170 void advanceNextState(); | 171 void advanceNextState(); |
| 171 bool isValidTransition() const; | 172 bool isValidTransition() const; |
| 172 | 173 |
| 173 // Data. | 174 // Data. |
| 174 bool m_needsSetup{true}; | 175 bool m_needsSetup{true}; |
| 175 LayoutUnit m_availableSpace; | 176 Optional<LayoutUnit> m_availableSpace; |
| 176 | 177 |
| 177 LayoutUnit m_freeSpaceColumns; | 178 Optional<LayoutUnit> m_freeSpaceColumns; |
| 178 LayoutUnit m_freeSpaceRows; | 179 Optional<LayoutUnit> m_freeSpaceRows; |
| 179 | 180 |
| 180 // We need to keep both alive in order to properly size grids with orthogonal | 181 // We need to keep both alive in order to properly size grids with orthogonal |
| 181 // writing modes. | 182 // writing modes. |
| 182 Vector<GridTrack> m_columns; | 183 Vector<GridTrack> m_columns; |
| 183 Vector<GridTrack> m_rows; | 184 Vector<GridTrack> m_rows; |
| 184 Vector<size_t> m_contentSizedTracksIndex; | 185 Vector<size_t> m_contentSizedTracksIndex; |
| 185 Vector<size_t> m_flexibleSizedTracksIndex; | 186 Vector<size_t> m_flexibleSizedTracksIndex; |
| 186 | 187 |
| 187 GridTrackSizingDirection m_direction; | 188 GridTrackSizingDirection m_direction; |
| 188 SizingOperation m_sizingOperation; | 189 SizingOperation m_sizingOperation; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 225 |
| 225 class GridTrackSizingAlgorithmStrategy { | 226 class GridTrackSizingAlgorithmStrategy { |
| 226 WTF_MAKE_NONCOPYABLE(GridTrackSizingAlgorithmStrategy); | 227 WTF_MAKE_NONCOPYABLE(GridTrackSizingAlgorithmStrategy); |
| 227 USING_FAST_MALLOC(GridTrackSizingAlgorithmStrategy); | 228 USING_FAST_MALLOC(GridTrackSizingAlgorithmStrategy); |
| 228 | 229 |
| 229 public: | 230 public: |
| 230 LayoutUnit minContentForChild(LayoutBox&) const; | 231 LayoutUnit minContentForChild(LayoutBox&) const; |
| 231 LayoutUnit maxContentForChild(LayoutBox&) const; | 232 LayoutUnit maxContentForChild(LayoutBox&) const; |
| 232 LayoutUnit minSizeForChild(LayoutBox&) const; | 233 LayoutUnit minSizeForChild(LayoutBox&) const; |
| 233 | 234 |
| 234 virtual void maximizeTracks(Vector<GridTrack>&, LayoutUnit& freeSpace) = 0; | 235 virtual void maximizeTracks(Vector<GridTrack>&, |
| 235 virtual double findUsedFlexFraction(Vector<size_t>& flexibleSizedTracksIndex, | 236 Optional<LayoutUnit>& freeSpace) = 0; |
| 236 GridTrackSizingDirection, | 237 virtual double findUsedFlexFraction( |
| 237 LayoutUnit initialFreeSpace) const = 0; | 238 Vector<size_t>& flexibleSizedTracksIndex, |
| 239 GridTrackSizingDirection, |
| 240 Optional<LayoutUnit> initialFreeSpace) const = 0; |
| 238 virtual bool recomputeUsedFlexFractionIfNeeded( | 241 virtual bool recomputeUsedFlexFractionIfNeeded( |
| 239 Vector<size_t>& flexibleSizedTracksIndex, | 242 Vector<size_t>& flexibleSizedTracksIndex, |
| 240 double& flexFraction, | 243 double& flexFraction, |
| 241 Vector<LayoutUnit>& increments, | 244 Vector<LayoutUnit>& increments, |
| 242 LayoutUnit& totalGrowth) const = 0; | 245 LayoutUnit& totalGrowth) const = 0; |
| 243 | 246 |
| 244 protected: | 247 protected: |
| 245 GridTrackSizingAlgorithmStrategy(GridTrackSizingAlgorithm& algorithm) | 248 GridTrackSizingAlgorithmStrategy(GridTrackSizingAlgorithm& algorithm) |
| 246 : m_algorithm(algorithm) {} | 249 : m_algorithm(algorithm) {} |
| 247 | 250 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 266 LayoutUnit leftOverSpace) const; | 269 LayoutUnit leftOverSpace) const; |
| 267 void distributeSpaceToTracks(Vector<GridTrack*>& tracks, | 270 void distributeSpaceToTracks(Vector<GridTrack*>& tracks, |
| 268 LayoutUnit& availableLogicalSpace) const; | 271 LayoutUnit& availableLogicalSpace) const; |
| 269 const LayoutGrid* layoutGrid() const { return m_algorithm.m_layoutGrid; } | 272 const LayoutGrid* layoutGrid() const { return m_algorithm.m_layoutGrid; } |
| 270 | 273 |
| 271 GridTrackSizingAlgorithm& m_algorithm; | 274 GridTrackSizingAlgorithm& m_algorithm; |
| 272 }; | 275 }; |
| 273 } | 276 } |
| 274 | 277 |
| 275 #endif // GridTrackSizingAlgorithm_h | 278 #endif // GridTrackSizingAlgorithm_h |
| OLD | NEW |