Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef Grid_h | |
| 6 #define Grid_h | |
| 7 | |
| 8 #include "core/layout/OrderIterator.h" | |
| 9 #include "core/style/GridArea.h" | |
| 10 #include "core/style/GridPositionsResolver.h" | |
| 11 #include "wtf/Assertions.h" | |
| 12 #include "wtf/ListHashSet.h" | |
| 13 #include "wtf/Vector.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 // TODO(svillar): Perhaps we should use references here. | |
| 18 typedef Vector<LayoutBox*, 1> GridCell; | |
| 19 typedef Vector<Vector<GridCell>> GridAsMatrix; | |
| 20 typedef ListHashSet<size_t> OrderedTrackIndexSet; | |
| 21 | |
| 22 class LayoutGrid; | |
| 23 class GridIterator; | |
| 24 | |
| 25 // The Grid class represent a generic storage for grid items. It's currently | |
| 26 // implemented as a matrix (vector of vectors) but it can be eventually replaced | |
| 27 // by a more memory efficient representation later. This class is used by the | |
|
Manuel Rego
2017/01/31 09:37:09
Nit: I'm not sure if the "eventually ... later" se
svillar
2017/01/31 10:03:12
Acknowledged.
| |
| 28 // LayoutGrid object to place the grid items on a grid like structure, so that | |
| 29 // they could be accessed by rows/columns instead of just traversing the DOM or | |
| 30 // Layout trees. | |
| 31 class Grid final { | |
| 32 public: | |
| 33 Grid(const LayoutGrid*); | |
| 34 | |
| 35 size_t numTracks(GridTrackSizingDirection) const; | |
| 36 | |
| 37 void ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize); | |
| 38 void insert(LayoutBox&, const GridArea&); | |
| 39 | |
| 40 // Note that out of flow children are not grid items. | |
| 41 bool hasGridItems() const { return !m_gridItemArea.isEmpty(); } | |
| 42 | |
| 43 bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; } | |
| 44 void setHasAnyOrthogonalGridItem(bool); | |
| 45 | |
| 46 GridArea gridItemArea(const LayoutBox&) const; | |
| 47 void setGridItemArea(const LayoutBox&, GridArea); | |
| 48 | |
| 49 GridSpan gridItemSpan(const LayoutBox&, GridTrackSizingDirection) const; | |
| 50 | |
| 51 size_t gridItemPaintOrder(const LayoutBox& item) const; | |
|
Manuel Rego
2017/01/31 09:37:09
Nit: "item" is not needed here.
svillar
2017/01/31 10:03:12
Acknowledged.
| |
| 52 void setGridItemPaintOrder(const LayoutBox& item, size_t order); | |
| 53 | |
| 54 const GridCell& cell(size_t row, size_t column) const; | |
| 55 | |
| 56 int smallestTrackStart(GridTrackSizingDirection) const; | |
| 57 void setSmallestTracksStart(int rowStart, int columnStart); | |
| 58 | |
| 59 size_t autoRepeatTracks(GridTrackSizingDirection) const; | |
| 60 void setAutoRepeatTracks(size_t autoRepeatRows, size_t autoRepeatColumns); | |
| 61 | |
| 62 typedef ListHashSet<size_t> OrderedTrackIndexSet; | |
| 63 void setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet>); | |
| 64 void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>); | |
| 65 | |
| 66 size_t autoRepeatEmptyTracksCount(GridTrackSizingDirection) const; | |
| 67 bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const; | |
| 68 bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, size_t) const; | |
| 69 | |
| 70 OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const; | |
| 71 | |
| 72 OrderIterator& orderIterator() { return m_orderIterator; } | |
| 73 | |
| 74 void setNeedsItemsPlacement(bool); | |
| 75 bool needsItemsPlacement() const { return m_needsItemsPlacement; }; | |
| 76 | |
| 77 #if DCHECK_IS_ON() | |
| 78 bool hasAnyGridItemPaintOrder() const; | |
| 79 #endif | |
| 80 | |
| 81 private: | |
| 82 friend class GridIterator; | |
| 83 | |
| 84 OrderIterator m_orderIterator; | |
| 85 | |
| 86 int m_smallestColumnStart{0}; | |
| 87 int m_smallestRowStart{0}; | |
| 88 | |
| 89 size_t m_autoRepeatColumns{0}; | |
| 90 size_t m_autoRepeatRows{0}; | |
| 91 | |
| 92 bool m_hasAnyOrthogonalGridItem{false}; | |
| 93 bool m_needsItemsPlacement{true}; | |
| 94 | |
| 95 GridAsMatrix m_grid; | |
| 96 | |
| 97 HashMap<const LayoutBox*, GridArea> m_gridItemArea; | |
| 98 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap; | |
| 99 | |
| 100 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns{nullptr}; | |
| 101 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows{nullptr}; | |
| 102 }; | |
| 103 | |
| 104 // TODO(svillar): ideally the Grid class should be the one returning an iterator | |
| 105 // for its contents. | |
| 106 class GridIterator final { | |
| 107 WTF_MAKE_NONCOPYABLE(GridIterator); | |
| 108 | |
| 109 public: | |
| 110 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g | |
| 111 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd | |
| 112 // column. | |
| 113 GridIterator(const Grid&, | |
| 114 GridTrackSizingDirection, | |
| 115 size_t fixedTrackIndex, | |
| 116 size_t varyingTrackIndex = 0); | |
| 117 | |
| 118 LayoutBox* nextGridItem(); | |
| 119 | |
| 120 bool checkEmptyCells(size_t rowSpan, size_t columnSpan) const; | |
| 121 | |
| 122 std::unique_ptr<GridArea> nextEmptyGridArea(size_t fixedTrackSpan, | |
| 123 size_t varyingTrackSpan); | |
| 124 | |
| 125 private: | |
| 126 const GridAsMatrix& m_grid; | |
| 127 GridTrackSizingDirection m_direction; | |
| 128 size_t m_rowIndex; | |
| 129 size_t m_columnIndex; | |
| 130 size_t m_childIndex; | |
| 131 }; | |
| 132 | |
| 133 } // namespace blink | |
| 134 | |
| 135 #endif // Grid_h | |
| OLD | NEW |