From: Manolo Carrasco Date: Thu, 15 Mar 2012 12:22:43 +0000 (+0000) Subject: fix width/height when the window is not the main X-Git-Tag: release-1.3.2~103 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f1e61076b2cdc9b7a79cb339d647429968674ce8;p=gwtquery.git fix width/height when the window is not the main --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 9680fdd9..0bfa6baf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -213,10 +213,12 @@ public class GQuery implements Lazy { * Wrap a GQuery around an existing element, event, node or nodelist. */ public static GQuery $(JavaScriptObject e) { - return JsUtils.isElement(e) ? GQuery.$(e.cast()) : + return + JsUtils.isWindow(e) ? GQuery.$(e.cast()) : + JsUtils.isElement(e) ? GQuery.$(e.cast()) : JsUtils.isEvent(e) ? GQuery.$(e.cast()) : JsUtils.isNodeList(e) ? GQuery.$(e.>cast()) : - $(); + $(); } /** @@ -477,12 +479,6 @@ public class GQuery implements Lazy { } } - private static native void emptyDocument(Document d) /*-{ - d.open(); - d.write(""); - d.close(); - }-*/; - /** * Perform an ajax request to the server using GET. */ @@ -527,13 +523,6 @@ public class GQuery implements Lazy { return attributeImpl; } - private native static Document getContentDocument(Node n) /*-{ - var d = n.contentDocument || n.document || n.contentWindow.document; - if (!d.body) - @com.google.gwt.query.client.GQuery::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d); - return d; - }-*/; - /** * Perform an ajax request to the server using POST and * parsing the json response. @@ -1425,7 +1414,7 @@ public class GQuery implements Lazy { JsNodeArray result = JsNodeArray.create(); for (Element e : elements) { if (JsUtils.isWindow(e) || "iframe".equalsIgnoreCase(e.getTagName())) { - result.addNode(getContentDocument(e)); + result.addNode(styleImpl.getContentDocument(e)); } else { NodeList children = e.getChildNodes(); for (int i = 0, l = children.getLength(); i < l; i++) { @@ -2023,7 +2012,7 @@ public class GQuery implements Lazy { public GQuery empty() { for (Element e : elements) { if (e.getNodeType() == Element.DOCUMENT_NODE) { - emptyDocument(e. cast()); + styleImpl.emptyDocument(e. cast()); } else { Node c = e.getFirstChild(); while (c != null) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index a2aaf788..3e6f58bb 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -17,12 +17,12 @@ package com.google.gwt.query.client.impl; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.Node; import com.google.gwt.query.client.GQuery; import com.google.gwt.query.client.js.JsNamedArray; import com.google.gwt.query.client.js.JsRegexp; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.user.client.DOM; -import com.google.gwt.user.client.Window; /** * A helper class to get computed CSS styles for elements. @@ -40,12 +40,12 @@ public class DocumentStyleImpl { * - Otherwise it returns the real computed value. */ public double cur(Element elem, String prop, boolean force) { - if (elem.equals(GQuery.window)) { + if (JsUtils.isWindow(elem)) { if ("width".equals(prop)) { - return Window.getClientWidth(); + return getContentDocument(elem).getClientWidth(); } if ("height".equals(prop)) { - return Window.getClientHeight(); + return getContentDocument(elem).getClientHeight(); } elem = GQuery.body; } @@ -199,4 +199,16 @@ public class DocumentStyleImpl { return ret; } + public native Document getContentDocument(Node n) /*-{ + var d = n.contentDocument || n.document || n.contentWindow.document; + if (!d.body) + this.@com.google.gwt.query.client.impl.DocumentStyleImpl::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d); + return d; + }-*/; + + public native void emptyDocument(Document d) /*-{ + d.open(); + d.write(""); + d.close(); + }-*/; }