Chromium Code Reviews| Index: tools/dom/src/Dimension.dart |
| diff --git a/tools/dom/src/Dimension.dart b/tools/dom/src/Dimension.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fab8d8990e246aa0bf44189ae765224669f1c967 |
| --- /dev/null |
| +++ b/tools/dom/src/Dimension.dart |
| @@ -0,0 +1,67 @@ |
| +/** 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.
|
| +@Experimental() |
| +class Dimension { |
| + num _value; |
| + String _unit; |
| + |
| + /** Set this CSS Dimension to a percentage `value`. */ |
| + Dimension.percent(this._value) : _unit = '%'; |
| + |
| + /** Set this CSS Dimension to a pixel `value`. */ |
| + Dimension.px(this._value) : _unit = 'px'; |
| + |
| + /** Set this CSS Dimension to a pica `value`. */ |
| + Dimension.pc(this._value) : _unit = 'pc'; |
| + |
| + /** Set this CSS Dimension to a point `value`. */ |
| + Dimension.pt(this._value) : _unit = 'pt'; |
| + |
| + /** Set this CSS Dimension to an inch `value`. */ |
| + Dimension.inch(this._value) : _unit = 'in'; |
| + |
| + /** Set this CSS Dimension to a centimeter `value`. */ |
| + Dimension.cm(this._value) : _unit = 'cm'; |
| + |
| + /** Set this CSS Dimension to a millimeter `value`. */ |
| + Dimension.mm(this._value) : _unit = 'mm'; |
| + |
| + /** |
| + * Set this CSS Dimension to the specified number of ems. |
| + * |
| + * 1em is equal to the current font size. (So 2ems is equal to double the font |
| + * size). This is useful for producing website layouts that scale nicely with |
| + * the user's desired font size. |
| + */ |
| + Dimension.em(this._value) : _unit = 'em'; |
| + |
| + /** |
| + * Set this CSS Dimension to the specified number of x-heights. |
| + * |
| + * One ex is equal to the the x-height of a font's baseline to its mean line, |
| + * generally the height of the letter "x" in the font, which is usually about |
| + * half the font-size. |
| + */ |
| + Dimension.ex(this._value) : _unit = 'ex'; |
| + |
| + /** |
| + * Construct a Dimension object from the CSS string `cssValue`, in pixels. |
| + * This constructor is only called on output from getComputedValue, which we |
| + * know to be pixels. |
| + */ |
| + 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
|
| + if (pixels.contains('.')) { |
| + _value = double.parse(pixels.substring(0, pixels.length - 2)); |
| + } else { |
| + _value = int.parse(pixels.substring(0, pixels.length - 2)); |
| + } |
| + _unit = 'px'; |
| + } |
| + |
| + /** Print out the CSS String representation of this value. */ |
| + String toString() { |
| + return '${_value}${_unit}'; |
| + } |
| + |
| + /** Return a unitless, numerical value of this CSS value. */ |
| + num get value => this._value; |
|
Jennifer Messerly
2013/07/16 22:03:16
remove this.?
|
| +} |