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

Side by Side Diff: third_party/WebKit/Source/core/style/GridCoordinate.h

Issue 1477203002: [css-grid] Simplify GridResolvedPosition interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/style/GridResolvedPosition.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 static GridSpan definiteGridSpan(const GridResolvedPosition& resolvedInitial Position, const GridResolvedPosition& resolvedFinalPosition) 53 static GridSpan definiteGridSpan(const GridResolvedPosition& resolvedInitial Position, const GridResolvedPosition& resolvedFinalPosition)
54 { 54 {
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); 55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite );
56 } 56 }
57 57
58 static GridSpan indefiniteGridSpan() 58 static GridSpan indefiniteGridSpan()
59 { 59 {
60 return GridSpan(0, 1, Indefinite); 60 return GridSpan(0, 1, Indefinite);
61 } 61 }
62 62
63 static GridSpan definiteGridSpanWithSpanAgainstOpposite(const GridResolvedPo sition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side)
64 {
65 size_t positionOffset = position.spanPosition();
66 if (side == ColumnStartSide || side == RowStartSide) {
67 if (resolvedOppositePosition == 0)
68 return GridSpan::definiteGridSpan(resolvedOppositePosition, reso lvedOppositePosition.next());
69
70 GridResolvedPosition initialResolvedPosition = GridResolvedPosition( std::max<int>(0, resolvedOppositePosition.toInt() - positionOffset));
71 return GridSpan::definiteGridSpan(initialResolvedPosition, resolvedO ppositePosition);
72 }
73
74 return GridSpan::definiteGridSpan(resolvedOppositePosition, GridResolved Position(resolvedOppositePosition.toInt() + positionOffset));
75 }
76
77 static GridSpan definiteGridSpanWithNamedSpanAgainstOpposite(const GridResol vedPosition& resolvedOppositePosition, const GridPosition& position, GridPositio nSide side, const Vector<size_t>& gridLines)
78 {
79 if (side == RowStartSide || side == ColumnStartSide)
80 return definiteGridSpanWithInitialNamedSpanAgainstOpposite(resolvedO ppositePosition, position, gridLines);
81
82 return definiteGridSpanWithFinalNamedSpanAgainstOpposite(resolvedOpposit ePosition, position, gridLines);
83 }
84
85 static GridSpan definiteGridSpanWithInitialNamedSpanAgainstOpposite(const Gr idResolvedPosition& resolvedOppositePosition, const GridPosition& position, cons t Vector<size_t>& gridLines)
86 {
87 if (resolvedOppositePosition == 0)
88 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolved OppositePosition.next());
89
90 size_t firstLineBeforeOppositePositionIndex = 0;
91 const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLin es.begin(), gridLines.end(), resolvedOppositePosition.toInt());
92 if (firstLineBeforeOppositePosition != gridLines.end())
93 firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePositi on - gridLines.begin();
94 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionI ndex - position.spanPosition());
95 GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(gri dLines[gridLineIndex]);
96 if (resolvedGridLinePosition >= resolvedOppositePosition)
97 resolvedGridLinePosition = resolvedOppositePosition.prev();
98 return GridSpan::definiteGridSpan(resolvedGridLinePosition, resolvedOppo sitePosition);
99 }
100
101 static GridSpan definiteGridSpanWithFinalNamedSpanAgainstOpposite(const Grid ResolvedPosition& resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines)
102 {
103 size_t firstLineAfterOppositePositionIndex = gridLines.size() - 1;
104 const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLine s.begin(), gridLines.end(), resolvedOppositePosition.toInt());
105 if (firstLineAfterOppositePosition != gridLines.end())
106 firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition - gridLines.begin();
107 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppo sitePositionIndex + position.spanPosition() - 1);
108 GridResolvedPosition resolvedGridLinePosition = gridLines[gridLineIndex] ;
109 if (resolvedGridLinePosition <= resolvedOppositePosition)
110 resolvedGridLinePosition = resolvedOppositePosition.next();
111
112 return GridSpan::definiteGridSpan(resolvedOppositePosition, resolvedGrid LinePosition);
113 }
114
115 bool operator==(const GridSpan& o) const 63 bool operator==(const GridSpan& o) const
116 { 64 {
117 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; 65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition;
118 } 66 }
119 67
120 size_t integerSpan() const 68 size_t integerSpan() const
121 { 69 {
122 ASSERT(isDefinite()); 70 ASSERT(isDefinite());
123 return m_resolvedFinalPosition.toInt() - m_resolvedInitialPosition.toInt (); 71 return m_resolvedFinalPosition.toInt() - m_resolvedInitialPosition.toInt ();
124 } 72 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bool operator==(const GridCoordinate& o) const 139 bool operator==(const GridCoordinate& o) const
192 { 140 {
193 return columns == o.columns && rows == o.rows; 141 return columns == o.columns && rows == o.rows;
194 } 142 }
195 143
196 bool operator!=(const GridCoordinate& o) const 144 bool operator!=(const GridCoordinate& o) const
197 { 145 {
198 return !(*this == o); 146 return !(*this == o);
199 } 147 }
200 148
201 GridResolvedPosition positionForSide(GridPositionSide side) const
202 {
203 switch (side) {
204 case ColumnStartSide:
205 return columns.resolvedInitialPosition();
206 case ColumnEndSide:
207 return columns.resolvedFinalPosition();
208 case RowStartSide:
209 return rows.resolvedInitialPosition();
210 case RowEndSide:
211 return rows.resolvedFinalPosition();
212 }
213 ASSERT_NOT_REACHED();
214 return 0;
215 }
216
217 GridSpan columns; 149 GridSpan columns;
218 GridSpan rows; 150 GridSpan rows;
219 }; 151 };
220 152
221 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; 153 typedef HashMap<String, GridCoordinate> NamedGridAreaMap;
222 154
223 } // namespace blink 155 } // namespace blink
224 156
225 #endif // GridCoordinate_h 157 #endif // GridCoordinate_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/style/GridResolvedPosition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698