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

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
« tests/html/element_test.dart ('K') | « 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..45523a03665bd2c2429beaa6a2e97e778c55dc8f 100644
--- a/tools/dom/templates/html/impl/impl_Element.darttemplate
+++ b/tools/dom/templates/html/impl/impl_Element.darttemplate
@@ -1090,6 +1090,43 @@ $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 docOffset => offsetTo(document.documentElement);
Jennifer Messerly 2013/07/24 23:26:23 personally, I would call this "documentOffset". Th
Emily Fortuna 2013/07/25 00:20:07 Done.
+
+ /**
+ * 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.
Jennifer Messerly 2013/07/24 23:26:23 could use code links for [ArgumentError] and [offs
Emily Fortuna 2013/07/25 00:20:07 Done.
+ */
+ Point offsetTo(Element parent) {
+ return _offsetToHelper(this,
+ parent, parent == this || parent.tagName == 'HTML');
Jennifer Messerly 2013/07/24 23:26:23 can we remove this extra arg? suggestion below.
Jennifer Messerly 2013/07/24 23:26:23 use "identical(parent, this)"? one thing to watch
+ }
+
+ Point _offsetToHelper(Element current, Element parent, bool foundAsParent) {
Jennifer Messerly 2013/07/24 23:26:23 can this be static?
Emily Fortuna 2013/07/25 00:20:07 Done.
+ if (current == null || current == parent) {
Jennifer Messerly 2013/07/24 23:26:23 can we remove "foundAsParent"? it seems to duplica
Emily Fortuna 2013/07/25 00:20:07 HTML discussed offline and added comment. and refa
+ return foundAsParent? new Point(0, 0) : throw new ArgumentError(
Jennifer Messerly 2013/07/24 23:26:23 this might be cleaner as: if (foundAsParent) retu
Emily Fortuna 2013/07/25 00:20:07 Done.
+ "Specified element is not a transitive offset parent of this "
+ "element.");
+ }
+ Element parentOffset = current.offsetParent;
+ Point p = _offsetToHelper(
+ parentOffset, parent, foundAsParent || parentOffset == parent);
+ return new Point(p.x + current.offsetLeft, p.y + current.offsetTop);
+ }
$!MEMBERS
}
« tests/html/element_test.dart ('K') | « tests/html/element_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698