From: Manolo Carrasco Date: Sun, 18 Mar 2012 09:26:11 +0000 (+0000) Subject: Fix computing of width and height in inline elements so as gquery behaves the same... X-Git-Tag: release-1.3.2~98 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=34b7307e843e93ca06e25fa1175055fad77b2b64;p=gwtquery.git Fix computing of width and height in inline elements so as gquery behaves the same than jquery --- 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 3e6f58bb..ac836e8d 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 @@ -115,7 +115,17 @@ public class DocumentStyleImpl { return JsUtils.camelize(name); } + // inline elements do not have width nor height unless we set it to inline-block + private void fixInlineElement(Element e) { + if (e.getClientHeight() == 0 && e.getClientWidth() == 0 && "inline".equals(curCSS(e, "display", true))) { + setStyleProperty(e, "display", "inline-block"); + setStyleProperty(e, "width", "auto"); + setStyleProperty(e, "height", "auto"); + } + } + public int getHeight(Element e) { + fixInlineElement(e); return (int) (e.getClientHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, "paddingBottom", true))); } @@ -125,6 +135,7 @@ public class DocumentStyleImpl { } public int getWidth(Element e) { + fixInlineElement(e); return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, "paddingRight", true))); } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java index 370e3a1a..20eed559 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java @@ -1085,6 +1085,14 @@ public class GQueryCoreTestGwt extends GWTTestCase { assertEquals(142, g.outerWidth(true)); } + + public void testWidthHeightInlineElement() { + $(e).html( + "Content 1"); + GQuery g = $("span", e); + assertTrue(g.width() > 0); + assertTrue(g.height() > 0); + } public void testWrapMethod() { String content = "

Test Paragraph.

";