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

Side by Side Diff: samples/ui_lib/layout/ViewLayout.dart

Issue 10409003: Eliminate switches that are not on const ints or strings (as required in spec 0.09). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
« lib/json/json.dart ('K') | « samples/ui_lib/layout/GridLayout.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** The interface that the layout algorithms use to talk to the view. */ 5 /** The interface that the layout algorithms use to talk to the view. */
6 interface Positionable { 6 interface Positionable {
7 ViewLayout get layout(); 7 ViewLayout get layout();
8 8
9 /** Gets our custom CSS properties, as provided by the CSS preprocessor. */ 9 /** Gets our custom CSS properties, as provided by the CSS preprocessor. */
10 Map<String, String> get customStyle(); 10 Map<String, String> get customStyle();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (!hasCustomLayout(view)) { 172 if (!hasCustomLayout(view)) {
173 for (final child in view.childViews) { 173 for (final child in view.childViews) {
174 child.doLayout(); 174 child.doLayout();
175 } 175 }
176 } 176 }
177 } 177 }
178 } 178 }
179 179
180 int measureContent(ViewLayout parent, Dimension dimension, 180 int measureContent(ViewLayout parent, Dimension dimension,
181 [ContentSizeMode mode = null]) { 181 [ContentSizeMode mode = null]) {
182 switch (dimension) { 182 if (dimension == Dimension.WIDTH) {
183 case Dimension.WIDTH: 183 return measureWidth(parent, mode);
184 return measureWidth(parent, mode); 184 } else if (dimension == Dimension.HEIGHT) {
185 case Dimension.HEIGHT: 185 return measureHeight(parent, mode);
186 return measureHeight(parent, mode);
187 } 186 }
188 } 187 }
189 188
190 int measureWidth(ViewLayout parent, ContentSizeMode mode) { 189 int measureWidth(ViewLayout parent, ContentSizeMode mode) {
191 final style = layoutParams.style.value; 190 final style = layoutParams.style.value;
192 switch (mode) { 191 if (mode == ContentSizeMode.MIN) {
193 case ContentSizeMode.MIN: 192 return _styleToPixels(
194 return _styleToPixels( 193 style.minWidth, currentWidth, parent.currentWidth);
195 style.minWidth, currentWidth, parent.currentWidth); 194 } else if (mode == ContentSizeMode.MAX) {
196 195 return _styleToPixels(
197 case ContentSizeMode.MAX: 196 style.maxWidth, currentWidth, parent.currentWidth);
198 return _styleToPixels(
199 style.maxWidth, currentWidth, parent.currentWidth);
200 } 197 }
201 } 198 }
202 199
203 int measureHeight(ViewLayout parent, ContentSizeMode mode) { 200 int measureHeight(ViewLayout parent, ContentSizeMode mode) {
204 final style = layoutParams.style.value; 201 final style = layoutParams.style.value;
205 switch (mode) { 202 if (mode == ContentSizeMode.MIN) {
206 case ContentSizeMode.MIN: 203 return _styleToPixels(
207 return _styleToPixels( 204 style.minHeight, currentHeight, parent.currentHeight);
208 style.minHeight, currentHeight, parent.currentHeight); 205 } else if (mode == ContentSizeMode.MAX) {
209 206 return _styleToPixels(
210 case ContentSizeMode.MAX: 207 style.maxHeight, currentHeight, parent.currentHeight);
211 return _styleToPixels(
212 style.maxHeight, currentHeight, parent.currentHeight);
213 } 208 }
214 } 209 }
215 210
216 static int _toPixels(String style) { 211 static int _toPixels(String style) {
217 if (style.endsWith('px')) { 212 if (style.endsWith('px')) {
218 return Math.parseInt(style.substring(0, style.length - 2)); 213 return Math.parseInt(style.substring(0, style.length - 2));
219 } else { 214 } else {
220 // TODO(jmesserly): other size units 215 // TODO(jmesserly): other size units
221 throw new UnsupportedOperationException( 216 throw new UnsupportedOperationException(
222 'Unknown min/max content size format: "$style"'); 217 'Unknown min/max content size format: "$style"');
223 } 218 }
224 } 219 }
225 220
226 static int _styleToPixels(String style, num size, num parentSize) { 221 static int _styleToPixels(String style, num size, num parentSize) {
227 if (style == 'none') { 222 if (style == 'none') {
228 // For an unset max-content size, use the actual size 223 // For an unset max-content size, use the actual size
229 return size; 224 return size;
230 } 225 }
231 if (style.endsWith('%')) { 226 if (style.endsWith('%')) {
232 num percent = Math.parseDouble(style.substring(0, style.length - 1)); 227 num percent = Math.parseDouble(style.substring(0, style.length - 1));
233 return ((percent / 100) * parentSize).toInt(); 228 return ((percent / 100) * parentSize).toInt();
234 } 229 }
235 return _toPixels(style); 230 return _toPixels(style);
236 } 231 }
237 } 232 }
OLDNEW
« lib/json/json.dart ('K') | « samples/ui_lib/layout/GridLayout.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698