| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * Utilities for [Element]s. | 6 * Utilities for [Element]s. |
| 7 */ | 7 */ |
| 8 class DomUtils { | 8 class DomUtils { |
| 9 | |
| 10 /** | |
| 11 * Returns an element's absolute bottom coordinate in the document's coordinat
e system. | |
| 12 */ | |
| 13 static int getAbsoluteBottom(Element elem) => getAbsoluteTop(elem) + elem.offs
etHeight; | |
| 14 | |
| 15 /** | |
| 16 * Returns an element's absolute left coordinate in the document's coordinate
system. | |
| 17 */ | |
| 18 static int getAbsoluteLeft(Element elem) { | |
| 19 int left = 0; | |
| 20 Element curr = elem; | |
| 21 while (curr.offsetParent != null) { | |
| 22 left -= curr.scrollLeft; | |
| 23 curr = curr.parent; | |
| 24 } | |
| 25 while (elem != null) { | |
| 26 left += elem.offsetLeft; | |
| 27 elem = elem.offsetParent; | |
| 28 } | |
| 29 return left; | |
| 30 } | |
| 31 | |
| 32 /** | |
| 33 * Returns an element's absolute right coordinate in the document's coordinate
system. | |
| 34 */ | |
| 35 static int getAbsoluteRight(Element elem) => getAbsoluteLeft(elem) + elem.offs
etWidth; | |
| 36 | |
| 37 /** | |
| 38 * Returns an element's absolute top coordinate in the document's coordinate s
ystem. | |
| 39 */ | |
| 40 static int getAbsoluteTop(Element elem) { | |
| 41 int top = 0; | |
| 42 Element curr = elem; | |
| 43 while (curr.offsetParent != null) { | |
| 44 top -= curr.scrollTop; | |
| 45 curr = curr.parent; | |
| 46 } | |
| 47 while (elem != null) { | |
| 48 top += elem.offsetTop; | |
| 49 elem = elem.offsetParent; | |
| 50 } | |
| 51 return top; | |
| 52 } | |
| 53 | |
| 54 /** | 9 /** |
| 55 * Removes a property on the given element's style. | 10 * Removes a property on the given element's style. |
| 56 */ | 11 */ |
| 57 static void removeStyleProperty(Element elem, String name) { | 12 static void removeStyleProperty(Element elem, String name) { |
| 58 elem.style.removeProperty(name); | 13 elem.style.removeProperty(name); |
| 59 } | 14 } |
| 60 | 15 |
| 61 /** | 16 /** |
| 62 * Sets a property on the given element's style. | 17 * Sets a property on the given element's style. |
| 63 */ | 18 */ |
| 64 static void setStyleProperty(Element elem, String name, String value) { | 19 static void setStyleProperty(Element elem, String name, String value) { |
| 65 elem.style.setProperty(name, value); | 20 elem.style.setProperty(name, value); |
| 66 } | 21 } |
| 67 | 22 |
| 68 /** | 23 /** |
| 69 * Sets an integer property (with optional unit) on the given element's style. | 24 * Sets an integer property (with optional unit) on the given element's style. |
| 70 */ | 25 */ |
| 71 static void setStylePropertyInt(Element elem, String name, int value, [String
unit = ""]) { | 26 static void setStylePropertyInt(Element elem, String name, int value, [String
unit = ""]) { |
| 72 setStyleProperty(elem, name, value.toString() + unit); | 27 setStyleProperty(elem, name, value.toString() + unit); |
| 73 } | 28 } |
| 74 } | 29 } |
| OLD | NEW |