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

Side by Side Diff: tools/dom/src/Dimension.dart

Issue 15507007: Provide cross-browser Rects for box model dimensions for Elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
OLDNEW
(Empty)
1 /** Class representing a distance measurement in CSS. */
2 class Dimension {
3 num _value;
4 String _unit;
5
6 /** Set this CSS Dimension to a percentage `value`. */
7 Dimension.percent(this._value) : _unit = '%';
8
9 /** Set this CSS Dimension to a pixel `value`. */
10 Dimension.px(this._value) : _unit = 'px';
11
12 /** Set this CSS Dimension to a pica `value`. */
13 Dimension.pc(this._value) : _unit = 'pc';
14
15 /** Set this CSS Dimension to a point `value`. */
16 Dimension.pt(this._value) : _unit = 'pt';
17
18 /** Set this CSS Dimension to an inch `value`. */
19 Dimension.inch(this._value) : _unit = 'in';
20
21 /** Set this CSS Dimension to a centimeter `value`. */
22 Dimension.cm(this._value) : _unit = 'cm';
23
24 /** Set this CSS Dimension to a millimeter `value`. */
25 Dimension.mm(this._value) : _unit = 'mm';
26
27 /**
28 * Set this CSS Dimension to the specified number of ems.
29 *
30 * 1em is equal to the current font size. (So 2ems is equal to double the font
31 * size). This is useful for producing website layouts that scale nicely with
32 * the user's desired font size.
33 */
34 Dimension.em(this._value) : _unit = 'em';
35
36 /**
37 * Set this CSS Dimension to the specified number of x-heights.
38 *
39 * One ex is equal to the the x-height of a font's baseline to its mean line,
40 * generally the height of the letter "x" in the font, which is usually about
41 * half the font-size.
42 */
43 Dimension.ex(this._value) : _unit = 'ex';
44
45 /** Construct a Dimension object from the valid CSS string `cssValue`. */
46 Dimension.css(String cssValue) {
blois 2013/05/22 01:18:07 Some edge cases for cssValue: 0 50.5% auto inherit
Emily Fortuna 2013/07/10 21:40:16 I can change this so this constructor is now priva
47 if (cssValue == '') cssValue = '0px';
48 if (cssValue.endsWith('%')) {
49 _unit = '%';
50 _value = int.parse(cssValue.substring(0, cssValue.length-1));
51 } else {
52 _value = int.parse(cssValue.substring(0, cssValue.length - 2));
53 _unit = cssValue.substring(cssValue.length - 2);
54 }
55 }
56
57 /** Print out the CSS String representation of this value. */
58 String toString() {
59 return '${_value}${_unit}';
60 }
61
62 /** Return a unitless, numerical value of this CSS value. */
63 num get value => this._value;
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698