OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** Representations of CSS styles. */ | 5 /** Representations of CSS styles. */ |
6 | 6 |
7 part of csslib.parser; | 7 part of csslib.parser; |
8 | 8 |
9 // TODO(terry): Prune down this file we do need some of the code in this file | 9 // TODO(terry): Prune down this file we do need some of the code in this file |
10 // for darker, lighter, how to represent a Font, etc but alot of | 10 // for darker, lighter, how to represent a Font, etc but alot of |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return new Hsla(args[0], args[1], args[2], | 284 return new Hsla(args[0], args[1], args[2], |
285 args[3]).toHexArgbString(); | 285 args[3]).toHexArgbString(); |
286 default: | 286 default: |
287 // Type not defined UnsupportedOperationException should have thrown. | 287 // Type not defined UnsupportedOperationException should have thrown. |
288 assert(true); | 288 assert(true); |
289 break; | 289 break; |
290 } | 290 } |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 /** | 294 static int hexToInt(String hex) => int.parse(hex, radix: 16); |
295 * [hex] hexadecimal string to convert to scalar. | |
296 * returns hexadecimal number as an integer. | |
297 * throws BadNumberFormatException if [hex] isn't a valid hexadecimal number. | |
298 */ | |
299 // TODO(terry): Should be part of Dart standard library see bug | |
300 // <http://code.google.com/p/dart/issues/detail?id=2624> | |
301 static int hexToInt(String hex) { | |
302 int val = 0; | |
303 | |
304 int len = hex.length; | |
305 for (int i = 0; i < len; i++) { | |
306 int hexDigit = hex.codeUnitAt(i); | |
307 if (hexDigit >= 48 && hexDigit <= 57) { | |
308 val += (hexDigit - 48) * (1 << (4 * (len - 1 - i))); | |
309 } else if (hexDigit >= 65 && hexDigit <= 70) { | |
310 // A..F | |
311 val += (hexDigit - 55) * (1 << (4 * (len - 1 - i))); | |
312 } else if (hexDigit >= 97 && hexDigit <= 102) { | |
313 // a..f | |
314 val += (hexDigit - 87) * (1 << (4 * (len - 1 - i))); | |
315 } else { | |
316 throw throw new FormatException("Bad hexadecimal value"); | |
317 } | |
318 } | |
319 | |
320 return val; | |
321 } | |
322 | 295 |
323 static String convertToHexString(int r, int g, int b, [num a]) { | 296 static String convertToHexString(int r, int g, int b, [num a]) { |
324 String rHex = Color._numAs2DigitHex(Color._clamp(r, 0, 255)); | 297 String rHex = Color._numAs2DigitHex(Color._clamp(r, 0, 255)); |
325 String gHex = Color._numAs2DigitHex(Color._clamp(g, 0, 255)); | 298 String gHex = Color._numAs2DigitHex(Color._clamp(g, 0, 255)); |
326 String bHex = Color._numAs2DigitHex(Color._clamp(b, 0, 255)); | 299 String bHex = Color._numAs2DigitHex(Color._clamp(b, 0, 255)); |
327 String aHex = (a != null) ? | 300 String aHex = (a != null) ? |
328 Color._numAs2DigitHex((Color._clamp(a, 0, 1) * 255).round()) : ""; | 301 Color._numAs2DigitHex((Color._clamp(a, 0, 1) * 255).round()) : ""; |
329 | 302 |
330 // TODO(terry) 15.toRadixString(16) return 'F' on Dartium not f as in JS. | 303 // TODO(terry) 15.toRadixString(16) return 'F' on Dartium not f as in JS. |
331 // bug: <http://code.google.com/p/dart/issues/detail?id=2670> | 304 // bug: <http://code.google.com/p/dart/issues/detail?id=2670> |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 num get width => (left != null ? left : 0) + (right != null ? right : 0); | 1214 num get width => (left != null ? left : 0) + (right != null ? right : 0); |
1242 | 1215 |
1243 /** | 1216 /** |
1244 * The total size of the vertical edges. Equal to [top] + [bottom], where | 1217 * The total size of the vertical edges. Equal to [top] + [bottom], where |
1245 * null is interpreted as 0px. | 1218 * null is interpreted as 0px. |
1246 */ | 1219 */ |
1247 num get height => (top != null ? top : 0) + (bottom != null ? bottom : 0); | 1220 num get height => (top != null ? top : 0) + (bottom != null ? bottom : 0); |
1248 } | 1221 } |
1249 | 1222 |
1250 _mergeVal(x, y) => y != null ? y : x; | 1223 _mergeVal(x, y) => y != null ? y : x; |
OLD | NEW |