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

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, 5 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. */
Jennifer Messerly 2013/07/16 22:03:16 fyi, I think the spec terminology is "length". ei
Emily Fortuna 2013/07/18 22:45:02 Done.
2 @Experimental()
3 class Dimension {
4 num _value;
5 String _unit;
6
7 /** Set this CSS Dimension to a percentage `value`. */
8 Dimension.percent(this._value) : _unit = '%';
9
10 /** Set this CSS Dimension to a pixel `value`. */
11 Dimension.px(this._value) : _unit = 'px';
12
13 /** Set this CSS Dimension to a pica `value`. */
14 Dimension.pc(this._value) : _unit = 'pc';
15
16 /** Set this CSS Dimension to a point `value`. */
17 Dimension.pt(this._value) : _unit = 'pt';
18
19 /** Set this CSS Dimension to an inch `value`. */
20 Dimension.inch(this._value) : _unit = 'in';
21
22 /** Set this CSS Dimension to a centimeter `value`. */
23 Dimension.cm(this._value) : _unit = 'cm';
24
25 /** Set this CSS Dimension to a millimeter `value`. */
26 Dimension.mm(this._value) : _unit = 'mm';
27
28 /**
29 * Set this CSS Dimension to the specified number of ems.
30 *
31 * 1em is equal to the current font size. (So 2ems is equal to double the font
32 * size). This is useful for producing website layouts that scale nicely with
33 * the user's desired font size.
34 */
35 Dimension.em(this._value) : _unit = 'em';
36
37 /**
38 * Set this CSS Dimension to the specified number of x-heights.
39 *
40 * One ex is equal to the the x-height of a font's baseline to its mean line,
41 * generally the height of the letter "x" in the font, which is usually about
42 * half the font-size.
43 */
44 Dimension.ex(this._value) : _unit = 'ex';
45
46 /**
47 * Construct a Dimension object from the CSS string `cssValue`, in pixels.
48 * This constructor is only called on output from getComputedValue, which we
49 * know to be pixels.
50 */
51 Dimension._(String pixels = '0px') {
Jennifer Messerly 2013/07/16 22:03:16 make this public? It seems really useful, even if
Emily Fortuna 2013/07/18 22:45:02 Updated! It originally was, but I had made it priv
52 if (pixels.contains('.')) {
53 _value = double.parse(pixels.substring(0, pixels.length - 2));
54 } else {
55 _value = int.parse(pixels.substring(0, pixels.length - 2));
56 }
57 _unit = 'px';
58 }
59
60 /** Print out the CSS String representation of this value. */
61 String toString() {
62 return '${_value}${_unit}';
63 }
64
65 /** Return a unitless, numerical value of this CSS value. */
66 num get value => this._value;
Jennifer Messerly 2013/07/16 22:03:16 remove this.?
67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698