OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef GridCoordinate_h | 31 #ifndef GridCoordinate_h |
32 #define GridCoordinate_h | 32 #define GridCoordinate_h |
33 | 33 |
34 #include "core/rendering/style/GridPosition.h" | 34 #include "core/rendering/style/GridResolvedPosition.h" |
35 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
36 #include "wtf/PassOwnPtr.h" | 36 #include "wtf/PassOwnPtr.h" |
37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 // A span in a single direction (either rows or columns). Note that |initialPosi
tionIndex| | 41 // A span in a single direction (either rows or columns). Note that |resolvedIni
tialPosition| |
42 // and |finalPositionIndex| are grid areas' indexes, NOT grid lines'. Iterating
over the | 42 // and |resolvedFinalPosition| are grid areas' indexes, NOT grid lines'. Iterati
ng over the |
43 // span should include both |initialPositionIndex| and |finalPositionIndex| to b
e correct. | 43 // span should include both |resolvedInitialPosition| and |resolvedFinalPosition
| to be correct. |
44 struct GridSpan { | 44 struct GridSpan { |
45 static PassOwnPtr<GridSpan> create(size_t initialPosition, size_t finalPosit
ion) | 45 static PassOwnPtr<GridSpan> create(const GridResolvedPosition& resolvedIniti
alPosition, const GridResolvedPosition& resolvedFinalPosition) |
46 { | 46 { |
47 return adoptPtr(new GridSpan(initialPosition, finalPosition)); | 47 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosit
ion)); |
48 } | 48 } |
49 | 49 |
50 static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(size_t resolvedOpp
ositePosition, const GridPosition& position, GridPositionSide side) | 50 static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(const GridResolved
Position& resolvedOppositePosition, const GridPosition& position, GridPositionSi
de side) |
51 { | 51 { |
52 // 'span 1' is contained inside a single grid track regardless of the di
rection. | 52 // 'span 1' is contained inside a single grid track regardless of the di
rection. |
53 // That's why the CSS span value is one more than the offset we apply. | 53 // That's why the CSS span value is one more than the offset we apply. |
54 size_t positionOffset = position.spanPosition() - 1; | 54 size_t positionOffset = position.spanPosition() - 1; |
55 if (side == ColumnStartSide || side == RowStartSide) { | 55 if (side == ColumnStartSide || side == RowStartSide) { |
56 size_t initialResolvedPosition = std::max<int>(0, resolvedOppositePo
sition - positionOffset); | 56 GridResolvedPosition initialResolvedPosition = GridResolvedPosition(
std::max<int>(0, resolvedOppositePosition.toInt() - positionOffset)); |
57 return GridSpan::create(initialResolvedPosition, resolvedOppositePos
ition); | 57 return GridSpan::create(initialResolvedPosition, resolvedOppositePos
ition); |
58 } | 58 } |
59 | 59 |
60 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on + positionOffset); | 60 return GridSpan::create(resolvedOppositePosition, GridResolvedPosition(r
esolvedOppositePosition.toInt() + positionOffset)); |
61 } | 61 } |
62 | 62 |
63 static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(size_t resolv
edOppositePosition, const GridPosition& position, GridPositionSide side, const V
ector<size_t>& gridLines) | 63 static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(const GridRes
olvedPosition& resolvedOppositePosition, const GridPosition& position, GridPosit
ionSide side, const Vector<size_t>& gridLines) |
64 { | 64 { |
65 if (side == RowStartSide || side == ColumnStartSide) | 65 if (side == RowStartSide || side == ColumnStartSide) |
66 return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); | 66 return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePos
ition, position, gridLines); |
67 | 67 |
68 return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition,
position, gridLines); | 68 return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition,
position, gridLines); |
69 } | 69 } |
70 | 70 |
71 static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(size_t
resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& g
ridLines) | 71 static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(const
GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, co
nst Vector<size_t>& gridLines) |
72 { | 72 { |
73 // The grid line inequality needs to be strict (which doesn't match the
after / end case) because |resolvedOppositePosition| | 73 // The grid line inequality needs to be strict (which doesn't match the
after / end case) because |resolvedOppositePosition| |
74 // is already converted to an index in our grid representation (ie one w
as removed from the grid line to account for the side). | 74 // is already converted to an index in our grid representation (ie one w
as removed from the grid line to account for the side). |
75 size_t firstLineBeforeOppositePositionIndex = 0; | 75 size_t firstLineBeforeOppositePositionIndex = 0; |
76 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin
es.begin(), gridLines.end(), resolvedOppositePosition); | 76 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin
es.begin(), gridLines.end(), resolvedOppositePosition.toInt()); |
77 if (firstLineBeforeOppositePosition != gridLines.end()) { | 77 if (firstLineBeforeOppositePosition != gridLines.end()) { |
78 if (*firstLineBeforeOppositePosition > resolvedOppositePosition && f
irstLineBeforeOppositePosition != gridLines.begin()) | 78 if (*firstLineBeforeOppositePosition > resolvedOppositePosition.toIn
t() && firstLineBeforeOppositePosition != gridLines.begin()) |
79 --firstLineBeforeOppositePosition; | 79 --firstLineBeforeOppositePosition; |
80 | 80 |
81 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi
on - gridLines.begin(); | 81 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi
on - gridLines.begin(); |
82 } | 82 } |
83 | 83 |
84 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI
ndex - position.spanPosition() + 1); | 84 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI
ndex - position.spanPosition() + 1); |
85 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; | 85 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; |
86 if (resolvedGridLinePosition > resolvedOppositePosition) | 86 if (resolvedGridLinePosition > resolvedOppositePosition.toInt()) |
87 resolvedGridLinePosition = resolvedOppositePosition; | 87 resolvedGridLinePosition = resolvedOppositePosition.toInt(); |
88 return GridSpan::create(resolvedGridLinePosition, resolvedOppositePositi
on); | 88 return GridSpan::create(GridResolvedPosition(resolvedGridLinePosition),
resolvedOppositePosition); |
89 } | 89 } |
90 | 90 |
91 static PassOwnPtr<GridSpan> createWithFinalNamedSpanAgainstOpposite(size_t r
esolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gri
dLines) | 91 static PassOwnPtr<GridSpan> createWithFinalNamedSpanAgainstOpposite(const Gr
idResolvedPosition& resolvedOppositePosition, const GridPosition& position, cons
t Vector<size_t>& gridLines) |
92 { | 92 { |
93 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; | 93 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1; |
94 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine
s.begin(), gridLines.end(), resolvedOppositePosition); | 94 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine
s.begin(), gridLines.end(), resolvedOppositePosition.toInt()); |
95 if (firstLineAfterOppositePosition != gridLines.end()) | 95 if (firstLineAfterOppositePosition != gridLines.end()) |
96 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition
- gridLines.begin(); | 96 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition
- gridLines.begin(); |
97 | 97 |
98 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo
sitePositionIndex + position.spanPosition() - 1); | 98 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo
sitePositionIndex + position.spanPosition() - 1); |
99 size_t resolvedGridLinePosition = GridPosition::adjustGridPositionForAft
erEndSide(gridLines[gridLineIndex]); | 99 size_t resolvedGridLinePositionInteger = GridResolvedPosition::adjustGri
dPositionForAfterEndSide(gridLines[gridLineIndex]); |
100 if (resolvedGridLinePosition < resolvedOppositePosition) | 100 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(res
olvedGridLinePositionInteger); |
101 resolvedGridLinePosition = resolvedOppositePosition; | 101 if (resolvedGridLinePosition < resolvedOppositePosition.toInt()) |
| 102 resolvedGridLinePosition = resolvedOppositePosition.toInt(); |
102 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePositi
on); | 103 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePositi
on); |
103 } | 104 } |
104 | 105 |
105 GridSpan(size_t initialPosition, size_t finalPosition) | 106 GridSpan(const GridResolvedPosition& resolvedInitialPosition, const GridReso
lvedPosition& resolvedFinalPosition) |
106 : initialPositionIndex(initialPosition) | 107 : resolvedInitialPosition(resolvedInitialPosition) |
107 , finalPositionIndex(finalPosition) | 108 , resolvedFinalPosition(resolvedFinalPosition) |
108 { | 109 { |
109 ASSERT(initialPositionIndex <= finalPositionIndex); | 110 ASSERT(resolvedInitialPosition <= resolvedFinalPosition); |
110 } | 111 } |
111 | 112 |
112 bool operator==(const GridSpan& o) const | 113 bool operator==(const GridSpan& o) const |
113 { | 114 { |
114 return initialPositionIndex == o.initialPositionIndex && finalPositionIn
dex == o.finalPositionIndex; | 115 return resolvedInitialPosition == o.resolvedInitialPosition && resolvedF
inalPosition == o.resolvedFinalPosition; |
115 } | 116 } |
116 | 117 |
117 size_t initialPositionIndex; | 118 GridResolvedPosition resolvedInitialPosition; |
118 size_t finalPositionIndex; | 119 GridResolvedPosition resolvedFinalPosition; |
119 }; | 120 }; |
120 | 121 |
121 // This represents a grid area that spans in both rows' and columns' direction. | 122 // This represents a grid area that spans in both rows' and columns' direction. |
122 struct GridCoordinate { | 123 struct GridCoordinate { |
123 // HashMap requires a default constuctor. | 124 // HashMap requires a default constuctor. |
124 GridCoordinate() | 125 GridCoordinate() |
125 : columns(0, 0) | 126 : columns(0, 0) |
126 , rows(0, 0) | 127 , rows(0, 0) |
127 { | 128 { |
128 } | 129 } |
(...skipping 16 matching lines...) Expand all Loading... |
145 | 146 |
146 GridSpan columns; | 147 GridSpan columns; |
147 GridSpan rows; | 148 GridSpan rows; |
148 }; | 149 }; |
149 | 150 |
150 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; | 151 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; |
151 | 152 |
152 } // namespace WebCore | 153 } // namespace WebCore |
153 | 154 |
154 #endif // GridCoordinate_h | 155 #endif // GridCoordinate_h |
OLD | NEW |