]> source.dussan.org Git - gwtquery.git/commitdiff
delegate calculation of offsets to the native methods present in the GWT core library
authorManolo Carrasco <manolo@apache.org>
Thu, 13 May 2010 10:14:52 +0000 (10:14 +0000)
committerManolo Carrasco <manolo@apache.org>
Thu, 13 May 2010 10:14:52 +0000 (10:14 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java

index 373ca2d7896195f0ee5b7a9dc87c3be7e6c36630..fa339dbd86c7ab68486487bbeda143596866eeaa 100644 (file)
@@ -1424,32 +1424,11 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
 \r
   /**\r
    * Get the current offset of the first matched element, in pixels, relative to\r
-   * the document. The returned object contains two Float properties, top and\r
-   * left. Browsers usually round these values to the nearest integer pixel for\r
-   * actual positioning. The method works only with visible elements.\r
+   * the document. The returned object contains two integer properties, top and\r
+   * left. The method works only with visible elements.\r
    */\r
   public Offset offset() {\r
-    if (length() == 0) {\r
-      return new Offset(0, 0);\r
-    }\r
-    int boxtop = getClientBoundingRectTop(get(0));\r
-    int boxleft = getClientBoundingRectLeft(get(0));\r
-    Element docElem = document.getDocumentElement();\r
-    Element body = document.getBody();\r
-    int clientTop = docElem.getPropertyInt("clientTop");\r
-    if (clientTop == 0) {\r
-      clientTop = body.getPropertyInt("clientTop");\r
-    }\r
-    int clientLeft = docElem.getPropertyInt("clientLeft");\r
-    if (clientLeft == 0) {\r
-      clientLeft = body.getPropertyInt("clientLeft");\r
-    }\r
-    int wleft = Window.getScrollLeft();\r
-    int wtop = Window.getScrollTop();\r
-    int top = boxtop + (wtop == 0 ? body.getScrollTop() : wtop) - clientTop;\r
-    int left = boxleft + (wleft == 0 ? body.getScrollLeft() : wleft)\r
-        - clientLeft;\r
-    return new Offset(top, left);\r
+    return new Offset(get(0).getAbsoluteTop(), get(0).getAbsoluteLeft());\r
   }\r
 \r
   /**\r
@@ -1539,22 +1518,7 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
    * and padding. This method only works with visible elements.\r
    */\r
   public Offset position() {\r
-\r
-    if (size() > 0) {\r
-      GQuery offsetParent = offsetParent();\r
-      Offset offset = offset();\r
-      Element e = offsetParent.get(0);\r
-\r
-      Offset parentOffset = BodyElement.is(e) || "html".equals(e.getTagName())\r
-          ? new Offset(0, 0) : offsetParent.offset();\r
-      offset.top -= num(this, "marginTop");\r
-      offset.left -= num(this, "marginLeft");\r
-      parentOffset.top += num(offsetParent, "borderTopWidth");\r
-      parentOffset.left += num(offsetParent, "borderLeftWidth");\r
-      return new Offset(offset.top - parentOffset.top,\r
-          offset.left - parentOffset.left);\r
-    }\r
-    return null;\r
+    return new Offset(get(0).getOffsetTop(), get(0).getAbsoluteLeft());\r
   }\r
 \r
   /**\r
@@ -2504,14 +2468,6 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     return styleImpl.getPropertyName(key);\r
   }\r
 \r
-  private native int getClientBoundingRectLeft(Element element) /*-{\r
-    return element.getClientBoundingRect().left;\r
-  }-*/;\r
-\r
-  private native int getClientBoundingRectTop(Element element) /*-{\r
-    return element.getClientBoundingRect().top;\r
-  }-*/;\r
-\r
   private native Document getContentDocument(Node n) /*-{\r
     return n.contentDocument || n.contentWindow.document;\r
   }-*/;\r