OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 GridResolvedPosition_h | 5 #ifndef GridResolvedPosition_h |
6 #define GridResolvedPosition_h | 6 #define GridResolvedPosition_h |
7 | 7 |
8 #include "core/style/GridPosition.h" | 8 #include "core/style/GridPosition.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 struct GridSpan; | 13 struct GridSpan; |
14 class LayoutBox; | 14 class LayoutBox; |
15 class ComputedStyle; | 15 class ComputedStyle; |
16 | 16 |
17 enum GridPositionSide { | |
18 ColumnStartSide, | |
19 ColumnEndSide, | |
20 RowStartSide, | |
21 RowEndSide | |
22 }; | |
23 | |
24 enum GridTrackSizingDirection { | 17 enum GridTrackSizingDirection { |
25 ForColumns, | 18 ForColumns, |
26 ForRows | 19 ForRows |
27 }; | 20 }; |
28 | 21 |
| 22 class GridUnresolvedSpan { |
| 23 public: |
| 24 GridUnresolvedSpan(GridPosition initialPosition, GridPositionSide initialPos
itionSide, GridPosition finalPosition, GridPositionSide finalPositionSide) |
| 25 : m_initialPosition(initialPosition) |
| 26 , m_finalPosition(finalPosition) |
| 27 , m_initialPositionSide(initialPositionSide) |
| 28 , m_finalPositionSide(finalPositionSide) |
| 29 { |
| 30 } |
| 31 |
| 32 const GridPosition& initialPosition() const { return m_initialPosition; } |
| 33 const GridPosition& finalPosition() const { return m_finalPosition; } |
| 34 GridPositionSide initialPositionSide() const { return m_initialPositionSide;
} |
| 35 GridPositionSide finalPositionSide() const { return m_finalPositionSide; } |
| 36 |
| 37 bool requiresAutoPlacement() const; |
| 38 GridUnresolvedSpan& adjustGridPositionsFromStyle(const ComputedStyle& gridCo
ntainerStyle); |
| 39 |
| 40 private: |
| 41 GridPosition m_initialPosition; |
| 42 GridPosition m_finalPosition; |
| 43 GridPositionSide m_initialPositionSide; |
| 44 GridPositionSide m_finalPositionSide; |
| 45 }; |
| 46 |
29 // This class represents an index into one of the dimensions of the grid array. | 47 // This class represents an index into one of the dimensions of the grid array. |
30 // Wraps a size_t integer just for the purpose of knowing what we manipulate in
the grid code. | 48 // Wraps a size_t integer just for the purpose of knowing what we manipulate in
the grid code. |
31 class GridResolvedPosition { | 49 class GridResolvedPosition { |
32 DISALLOW_NEW(); | 50 DISALLOW_NEW(); |
33 public: | 51 public: |
34 static GridResolvedPosition adjustGridPositionForAfterEndSide(size_t resolve
dPosition) | |
35 { | |
36 return resolvedPosition ? GridResolvedPosition(resolvedPosition - 1) : G
ridResolvedPosition(0); | |
37 } | |
38 | |
39 static GridResolvedPosition adjustGridPositionForSide(size_t resolvedPositio
n, GridPositionSide side) | |
40 { | |
41 // An item finishing on the N-th line belongs to the N-1-th cell. | |
42 if (side == ColumnEndSide || side == RowEndSide) | |
43 return adjustGridPositionForAfterEndSide(resolvedPosition); | |
44 | |
45 return GridResolvedPosition(resolvedPosition); | |
46 } | |
47 | |
48 static bool isValidNamedLineOrArea(const String& lineName, const ComputedSty
le&, GridPositionSide); | |
49 static GridPositionSide initialPositionSide(GridTrackSizingDirection); | |
50 static GridPositionSide finalPositionSide(GridTrackSizingDirection); | |
51 static void initialAndFinalPositionsFromStyle(const ComputedStyle&, const La
youtBox&, GridTrackSizingDirection, GridPosition &initialPosition, GridPosition
&finalPosition); | |
52 static GridSpan resolveGridPositionsFromAutoPlacementPosition(const Computed
Style&, const LayoutBox&, GridTrackSizingDirection, const GridResolvedPosition&)
; | |
53 static PassOwnPtr<GridSpan> resolveGridPositionsFromStyle(const ComputedStyl
e&, const LayoutBox&, GridTrackSizingDirection); | |
54 static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const Comp
utedStyle&, const GridPosition&, GridPositionSide); | |
55 static GridResolvedPosition resolveGridPositionFromStyle(const ComputedStyle
&, const GridPosition&, GridPositionSide); | |
56 static PassOwnPtr<GridSpan> resolveGridPositionAgainstOppositePosition(const
ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition, const Gri
dPosition&, GridPositionSide); | |
57 static PassOwnPtr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosit
ion(const ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition,
const GridPosition&, GridPositionSide); | |
58 | |
59 GridResolvedPosition(size_t position) | 52 GridResolvedPosition(size_t position) |
60 : m_integerPosition(position) | 53 : m_integerPosition(position) |
61 { | 54 { |
62 } | 55 } |
63 | 56 |
64 GridResolvedPosition(const GridPosition& position, GridPositionSide side) | |
65 { | |
66 ASSERT(position.integerPosition()); | |
67 size_t integerPosition = position.integerPosition() - 1; | |
68 | |
69 m_integerPosition = adjustGridPositionForSide(integerPosition, side).toI
nt(); | |
70 } | |
71 | |
72 GridResolvedPosition& operator*() | 57 GridResolvedPosition& operator*() |
73 { | 58 { |
74 return *this; | 59 return *this; |
75 } | 60 } |
76 | 61 |
77 GridResolvedPosition& operator++() | 62 GridResolvedPosition& operator++() |
78 { | 63 { |
79 m_integerPosition++; | 64 m_integerPosition++; |
80 return *this; | 65 return *this; |
81 } | 66 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 size_t toInt() const | 98 size_t toInt() const |
114 { | 99 { |
115 return m_integerPosition; | 100 return m_integerPosition; |
116 } | 101 } |
117 | 102 |
118 GridResolvedPosition next() const | 103 GridResolvedPosition next() const |
119 { | 104 { |
120 return GridResolvedPosition(m_integerPosition + 1); | 105 return GridResolvedPosition(m_integerPosition + 1); |
121 } | 106 } |
122 | 107 |
| 108 static bool isValidNamedLineOrArea(const String& lineName, const ComputedSty
le&, GridPositionSide); |
| 109 static GridSpan resolveGridPositionsFromAutoPlacementPosition(const Computed
Style&, const LayoutBox&, GridTrackSizingDirection, const GridResolvedPosition&)
; |
| 110 static GridUnresolvedSpan unresolvedSpanFromStyle(const ComputedStyle&, cons
t LayoutBox&, GridTrackSizingDirection); |
| 111 static GridSpan resolveGridPositionsFromStyle(const GridUnresolvedSpan&, con
st ComputedStyle&); |
123 static size_t explicitGridColumnCount(const ComputedStyle&); | 112 static size_t explicitGridColumnCount(const ComputedStyle&); |
124 static size_t explicitGridRowCount(const ComputedStyle&); | 113 static size_t explicitGridRowCount(const ComputedStyle&); |
125 | 114 |
126 private: | 115 private: |
127 | |
128 static size_t explicitGridSizeForSide(const ComputedStyle&, GridPositionSide
); | |
129 | |
130 size_t m_integerPosition; | 116 size_t m_integerPosition; |
131 }; | 117 }; |
132 | 118 |
133 } // namespace blink | 119 } // namespace blink |
134 | 120 |
135 #endif // GridResolvedPosition_h | 121 #endif // GridResolvedPosition_h |
OLD | NEW |