OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of layout; | 5 part of layout; |
6 | 6 |
7 // This file has classes representing the grid tracks and grid template | 7 // This file has classes representing the grid tracks and grid template |
8 | 8 |
9 /** | 9 /** |
10 * The data structure representing the grid-rows or grid-columns | 10 * The data structure representing the grid-rows or grid-columns |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 : _rects = new Map<int, _GridTemplateRect>(), | 111 : _rects = new Map<int, _GridTemplateRect>(), |
112 _numRows = rows.length { | 112 _numRows = rows.length { |
113 _buildRects(rows); | 113 _buildRects(rows); |
114 } | 114 } |
115 | 115 |
116 /** Scans the template strings and computes bounds for each one. */ | 116 /** Scans the template strings and computes bounds for each one. */ |
117 void _buildRects(List<String> templateRows) { | 117 void _buildRects(List<String> templateRows) { |
118 for (int r = 0; r < templateRows.length; r++) { | 118 for (int r = 0; r < templateRows.length; r++) { |
119 String row = templateRows[r]; | 119 String row = templateRows[r]; |
120 for (int c = 0; c < row.length; c++) { | 120 for (int c = 0; c < row.length; c++) { |
121 int cell = row.charCodeAt(c); | 121 int cell = row.codeUnitAt(c); |
122 final rect = _rects[cell]; | 122 final rect = _rects[cell]; |
123 if (rect != null) { | 123 if (rect != null) { |
124 rect.add(r + 1, c + 1); | 124 rect.add(r + 1, c + 1); |
125 } else { | 125 } else { |
126 _rects[cell] = new _GridTemplateRect(cell, r + 1, c + 1); | 126 _rects[cell] = new _GridTemplateRect(cell, r + 1, c + 1); |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Finally, check that each rectangle is valid (i.e. all spaces filled) | 131 // Finally, check that each rectangle is valid (i.e. all spaces filled) |
132 for (final rect in _rects.values) { | 132 for (final rect in _rects.values) { |
133 rect.checkValid(); | 133 rect.checkValid(); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 /** | 137 /** |
138 * Looks up the given cell in the template, and returns the rect. | 138 * Looks up the given cell in the template, and returns the rect. |
139 */ | 139 */ |
140 _GridTemplateRect lookupCell(String cell) { | 140 _GridTemplateRect lookupCell(String cell) { |
141 if (cell.length != 1) { | 141 if (cell.length != 1) { |
142 throw new UnsupportedError( | 142 throw new UnsupportedError( |
143 'grid-cell "$cell" must be a one character string'); | 143 'grid-cell "$cell" must be a one character string'); |
144 } | 144 } |
145 final rect = _rects[cell.charCodeAt(0)]; | 145 final rect = _rects[cell.codeUnitAt(0)]; |
146 if (rect == null) { | 146 if (rect == null) { |
147 throw new UnsupportedError( | 147 throw new UnsupportedError( |
148 'grid-cell "$cell" not found in parent\'s grid-template'); | 148 'grid-cell "$cell" not found in parent\'s grid-template'); |
149 } | 149 } |
150 return rect; | 150 return rect; |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 /** Used by GridTemplate to track a single cell's bounds. */ | 154 /** Used by GridTemplate to track a single cell's bounds. */ |
155 class _GridTemplateRect { | 155 class _GridTemplateRect { |
(...skipping 24 matching lines...) Expand all Loading... |
180 /** | 180 /** |
181 * Used to return a row/column and span during parsing of grid-row and | 181 * Used to return a row/column and span during parsing of grid-row and |
182 * grid-column during parsing. | 182 * grid-column during parsing. |
183 */ | 183 */ |
184 class _GridLocation { | 184 class _GridLocation { |
185 final int start, length; | 185 final int start, length; |
186 _GridLocation(this.start, this.length) {} | 186 _GridLocation(this.start, this.length) {} |
187 | 187 |
188 int get end => start + length; | 188 int get end => start + length; |
189 } | 189 } |
OLD | NEW |