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

Unified Diff: tools/dom/templates/html/impl/impl_Element.darttemplate

Issue 18060010: Added offset document measurement to Element. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/html/element_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
}
« no previous file with comments | « tests/html/element_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698