Chromium Code Reviews| Index: tools/dom/templates/html/impl/impl_Element.darttemplate |
| diff --git a/tools/dom/templates/html/impl/impl_Element.darttemplate b/tools/dom/templates/html/impl/impl_Element.darttemplate |
| index c64cb74a36a7824b10bceac952d751b49e1a746a..29533d85e51edf400246ddabfac96794c71a764f 100644 |
| --- a/tools/dom/templates/html/impl/impl_Element.darttemplate |
| +++ b/tools/dom/templates/html/impl/impl_Element.darttemplate |
| @@ -1090,6 +1090,46 @@ $endif |
| */ |
| @Experimental() |
| CssRect get marginEdge => new _MarginCssRect(this); |
| + |
| + /** |
| + * Provides the coordinates of the element relative to the top of the |
| + * document. |
| + * |
| + * This method is the Dart equivalent to jQuery's |
| + * [offset](http://api.jquery.com/offset/) method. |
| + */ |
| + Point get documentOffset => offsetTo(document.documentElement); |
|
blois
2013/07/27 00:00:56
What's the difference between rolling the offsets
|
| + |
| + /** |
| + * Provides the offset of this element's [borderEdge] relative to the |
| + * specified [parent]. |
| + * |
| + * This is the Dart equivalent of jQuery's |
| + * [position](http://api.jquery.com/position/) method. Unlike jQuery's |
| + * position, however, [parent] can be any parent element of `this`, |
| + * rather than only `this`'s immediate [offsetParent]. If the specified |
| + * element is _not_ an offset parent or transitive offset parent to this |
| + * element, an [ArgumentError] is thrown. |
| + */ |
| + Point offsetTo(Element parent) { |
| + return Element._offsetToHelper(this, parent); |
|
blois
2013/07/27 00:00:56
Why not just:
return new Point(documentOffset.x -
|
| + } |
| + |
| + static Point _offsetToHelper(Element current, Element parent) { |
| + // We're hopping from _offsetParent_ to offsetParent (not just parent), so |
| + // offsetParent, "tops out" at BODY. But people could conceivably pass in |
| + // the document.documentElement and I want it to return an absolute offset, |
| + // so we have the special case checking for HTML. |
| + bool foundAsParent = identical(current, parent) || parent.tagName == 'HTML'; |
| + if (current == null || identical(current, parent)) { |
| + if (foundAsParent) return new Point(0, 0); |
| + throw new ArgumentError("Specified element is not a transitive offset " |
| + "parent of this element."); |
| + } |
| + Element parentOffset = current.offsetParent; |
| + Point p = Element._offsetToHelper(parentOffset, parent); |
| + return new Point(p.x + current.offsetLeft, p.y + current.offsetTop); |
| + } |
| $!MEMBERS |
| } |