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

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

Issue 2654533003: [css-grid] Move the track sizing algorithm to its own class (Closed)
Patch Set: Created 3 years, 11 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
(Empty)
1 #ifndef Grid_h
Manuel Rego 2017/01/30 11:00:45 I guess you miss the license header here. And in t
svillar 2017/01/30 11:28:28 Acknowledged.
2 #define Grid_h
3
4 #include "core/layout/OrderIterator.h"
5 #include "core/style/GridArea.h"
6 #include "core/style/GridPositionsResolver.h"
7 #include "wtf/Assertions.h"
8 #include "wtf/ListHashSet.h"
9 #include "wtf/Vector.h"
10
11 namespace blink {
12
13 typedef Vector<LayoutBox*, 1> GridCell;
jfernandez 2017/01/30 08:48:48 Can those LayoutBox pointer be null ? Perhaps we c
svillar 2017/01/30 09:35:45 Right, but I guess we can do it in a follow up cha
Manuel Rego 2017/01/30 11:00:45 Then add a TODO so we don't forget about it. :-)
14 typedef Vector<Vector<GridCell>> GridAsMatrix;
15 typedef ListHashSet<size_t> OrderedTrackIndexSet;
16
17 class LayoutGrid;
18
19 // TODO(svillar): move into this class once GridIterator is added.
jfernandez 2017/01/30 08:48:48 I don't understand this comment.
svillar 2017/01/30 09:35:45 That's a legacy comment, I'll change it.
20 class Grid final {
Manuel Rego 2017/01/30 11:00:45 Please add a brief comment explaining what's the p
21 public:
22 Grid(const LayoutGrid*);
jfernandez 2017/01/30 08:48:48 Could we use reference here ?
svillar 2017/01/30 09:35:45 I tried but it looks like we cannot because in com
23
24 size_t numTracks(GridTrackSizingDirection) const;
25
26 void ensureGridSize(size_t maximumRowSize, size_t maximumColumnSize);
27 void insert(LayoutBox&, const GridArea&);
28
29 // Note that out of flow children are not grid items.
30 bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
31
32 bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
33 void setHasAnyOrthogonalGridItem(bool);
Manuel Rego 2017/01/30 11:00:45 This method could be implemented here, like the pr
svillar 2017/01/30 11:28:28 Nop because it'd break the rule of not having impl
34
35 GridArea gridItemArea(const LayoutBox& item) const;
jfernandez 2017/01/30 08:48:48 We don't need the "item" arg name.
svillar 2017/01/30 09:35:45 Acknowledged.
36 void setGridItemArea(const LayoutBox& item, GridArea);
jfernandez 2017/01/30 08:48:48 Ditto
37
38 GridSpan gridItemSpan(const LayoutBox&, GridTrackSizingDirection) const;
39
40 size_t gridItemPaintOrder(const LayoutBox& item) const;
41 void setGridItemPaintOrder(const LayoutBox& item, size_t order);
42
43 const GridCell& cell(size_t row, size_t column) const {
44 return m_grid[row][column];
45 }
46
47 int smallestTrackStart(GridTrackSizingDirection) const;
48 void setSmallestTracksStart(int rowStart, int columnStart);
49
50 size_t autoRepeatTracks(GridTrackSizingDirection) const;
51 void setAutoRepeatTracks(size_t autoRepeatRows, size_t autoRepeatColumns);
52
53 typedef ListHashSet<size_t> OrderedTrackIndexSet;
54 void setAutoRepeatEmptyColumns(std::unique_ptr<OrderedTrackIndexSet>);
55 void setAutoRepeatEmptyRows(std::unique_ptr<OrderedTrackIndexSet>);
56
57 size_t autoRepeatEmptyTracksCount(GridTrackSizingDirection) const;
58 bool hasAutoRepeatEmptyTracks(GridTrackSizingDirection) const;
59 bool isEmptyAutoRepeatTrack(GridTrackSizingDirection, size_t) const;
60
61 OrderedTrackIndexSet* autoRepeatEmptyTracks(GridTrackSizingDirection) const;
62
63 OrderIterator& orderIterator() { return m_orderIterator; }
64
65 void setNeedsItemsPlacement(bool);
66 bool needsItemsPlacement() const { return m_needsItemsPlacement; };
67
68 #if DCHECK_IS_ON()
69 bool hasAnyGridItemPaintOrder() const;
70 #endif
71
72 private:
73 friend class GridIterator;
74
75 OrderIterator m_orderIterator;
76
77 int m_smallestColumnStart{0};
78 int m_smallestRowStart{0};
79
80 size_t m_autoRepeatColumns{0};
81 size_t m_autoRepeatRows{0};
82
83 bool m_hasAnyOrthogonalGridItem{false};
84 bool m_needsItemsPlacement{true};
85
86 GridAsMatrix m_grid;
87
88 HashMap<const LayoutBox*, GridArea> m_gridItemArea;
89 HashMap<const LayoutBox*, size_t> m_gridItemsIndexesMap;
jfernandez 2017/01/30 08:48:48 Ditton about LayoutBox pointers.
svillar 2017/01/30 09:35:45 Same comment here, perhaps for a followup change.
Manuel Rego 2017/01/30 11:00:45 I think for the HashMap we need pointers, but mayb
svillar 2017/01/30 11:28:28 Indeed, we cannot have references in the HashMap
90
91 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns{nullptr};
92 std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows{nullptr};
93 };
94
95 class GridIterator {
96 WTF_MAKE_NONCOPYABLE(GridIterator);
97
98 public:
99 // |direction| is the direction that is fixed to |fixedTrackIndex| so e.g
100 // GridIterator(m_grid, ForColumns, 1) will walk over the rows of the 2nd
101 // column.
102 GridIterator(const Grid&,
103 GridTrackSizingDirection,
104 size_t fixedTrackIndex,
105 size_t varyingTrackIndex = 0);
106
107 LayoutBox* nextGridItem();
108
109 bool checkEmptyCells(size_t rowSpan, size_t columnSpan) const;
110
111 std::unique_ptr<GridArea> nextEmptyGridArea(size_t fixedTrackSpan,
112 size_t varyingTrackSpan);
113
114 private:
115 const GridAsMatrix& m_grid;
116 GridTrackSizingDirection m_direction;
117 size_t m_rowIndex;
118 size_t m_columnIndex;
119 size_t m_childIndex;
120 };
121
122 } // namespace blink
123
124 #endif // Grid_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698