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

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

Issue 19786005: Reapply Box Model convenience classes (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
« no previous file with comments | « tools/dom/src/CssRectangle.dart ('k') | tools/dom/src/Rectangle.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 part of html;
2
3 /**
4 * Class representing a
5 * [length measurement](https://developer.mozilla.org/en-US/docs/Web/CSS/length)
6 * in CSS.
7 */
8 @Experimental()
9 class Dimension {
10 num _value;
11 String _unit;
12
13 /** Set this CSS Dimension to a percentage `value`. */
14 Dimension.percent(this._value) : _unit = '%';
15
16 /** Set this CSS Dimension to a pixel `value`. */
17 Dimension.px(this._value) : _unit = 'px';
18
19 /** Set this CSS Dimension to a pica `value`. */
20 Dimension.pc(this._value) : _unit = 'pc';
21
22 /** Set this CSS Dimension to a point `value`. */
23 Dimension.pt(this._value) : _unit = 'pt';
24
25 /** Set this CSS Dimension to an inch `value`. */
26 Dimension.inch(this._value) : _unit = 'in';
27
28 /** Set this CSS Dimension to a centimeter `value`. */
29 Dimension.cm(this._value) : _unit = 'cm';
30
31 /** Set this CSS Dimension to a millimeter `value`. */
32 Dimension.mm(this._value) : _unit = 'mm';
33
34 /**
35 * Set this CSS Dimension to the specified number of ems.
36 *
37 * 1em is equal to the current font size. (So 2ems is equal to double the font
38 * size). This is useful for producing website layouts that scale nicely with
39 * the user's desired font size.
40 */
41 Dimension.em(this._value) : _unit = 'em';
42
43 /**
44 * Set this CSS Dimension to the specified number of x-heights.
45 *
46 * One ex is equal to the the x-height of a font's baseline to its mean line,
47 * generally the height of the letter "x" in the font, which is usually about
48 * half the font-size.
49 */
50 Dimension.ex(this._value) : _unit = 'ex';
51
52 /**
53 * Construct a Dimension object from the valid, simple CSS string `cssValue`
54 * that represents a distance measurement.
55 *
56 * This constructor is intended as a convenience method for working with
57 * simplistic CSS length measurements. Non-numeric values such as `auto` or
58 * `inherit` or invalid CSS will cause this constructor to throw a
59 * FormatError.
60 */
61 Dimension.css(String cssValue) {
62 if (cssValue == '') cssValue = '0px';
63 if (cssValue.endsWith('%')) {
64 _unit = '%';
65 } else {
66 _unit = cssValue.substring(cssValue.length - 2);
67 }
68 if (cssValue.contains('.')) {
69 _value = double.parse(cssValue.substring(0,
70 cssValue.length - _unit.length));
71 } else {
72 _value = int.parse(cssValue.substring(0, cssValue.length - _unit.length));
73 }
74 }
75
76 /** Print out the CSS String representation of this value. */
77 String toString() {
78 return '${_value}${_unit}';
79 }
80
81 /** Return a unitless, numerical value of this CSS value. */
82 num get value => this._value;
83 }
OLDNEW
« no previous file with comments | « tools/dom/src/CssRectangle.dart ('k') | tools/dom/src/Rectangle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698