From 35210485d54ee77ba847fcb5102bf97c66e6d116 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 16 Jun 2010 15:28:18 +0000 Subject: [PATCH] fixed an issue in PropertiesAnimation with the width and height. Added tests for width and height calculations. Added tests for ClipAnimation effect --- .../com/google/gwt/query/client/GQuery.java | 4 +- .../gwt/query/client/GQueryCoreTest.java | 14 ++++++ .../gwt/query/client/GQueryEffectsTest.java | 45 ++++++++++++++++++- 3 files changed, 60 insertions(+), 3 deletions(-) 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 941fd14e..394e27eb 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 @@ -275,10 +275,10 @@ public class GQuery implements Lazy { GQuery g = $(elem); String val = g.css(prop, true); if ("height".equalsIgnoreCase(prop)) { - return g.clientHeight(); + return elem.getClientHeight() - cur(elem, "paddingTop") - cur(elem, "paddingBottom"); } if ("width".equalsIgnoreCase(prop)) { - return g.clientWidth(); + return elem.getClientWidth() - cur(elem, "paddingLeft") - cur(elem, "paddingRight"); } if ("absolute".equalsIgnoreCase(g.css("position", true))) { if ("left".equalsIgnoreCase(prop)) { diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index c1d240b6..e53f77ca 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -617,4 +617,18 @@ public class GQueryCoreTest extends GWTTestCase { assertEquals("block", sectC.css("display")); } + public void testWidthHeight() { + $(e) + .html( + "
Content 1
"); + GQuery g = $("div", e); + assertEquals(120, g.width()); + assertEquals(122, g.height()); + assertEquals(120, g.clientWidth()); + assertEquals(120, g.clientHeight()); + assertEquals(100, (int)GQuery.cur(g.get(0), "width")); + assertEquals(100, (int)GQuery.cur(g.get(0), "height")); + assertEquals("100px", g.css("width")); + assertEquals("100px", g.css("height")); + } } diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java index 94e2bd11..b7745529 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java @@ -22,6 +22,7 @@ import com.google.gwt.dom.client.Element; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.GQuery.Offset; import com.google.gwt.query.client.plugins.Effects; +import com.google.gwt.query.client.plugins.ClipAnimation.Action; import com.google.gwt.query.client.plugins.PropertiesAnimation.Easing; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HTML; @@ -153,10 +154,52 @@ public class GQueryEffectsTest extends GWTTestCase { timer3.schedule(duration); } }; - // Starts the first timer timer4.schedule(duration/2); } + + public void testClipAnimation() { + $(e).html("

Content 1

"); + + final GQuery g = $("#idtest"); + final int duration = 800; + + // Clip effect paces a relative div in the position of the original element + // So check that there is not any div. + GQuery back = $("div", e); + assertEquals(0, back.size()); + + g.as(Effects.Effects).clipDisappear(duration); + + // Check that the back div has been created + back = $("div", e); + assertEquals(1, back.size()); + + // Configure the max duration for this test + delayTestFinish(duration * 2); + + // each timer calls the next one + final Timer timer1 = new Timer() { + public void run() { + // Check that the back div has been removed + GQuery back = $("div", e); + assertEquals(0, back.size()); + // Check that the attribute clip has been removed + assertEquals("", g.css("clip")); + finishTest(); + } + }; + final Timer timer2 = new Timer() { + public void run() { + // Check that the attribute clip has been set + assertTrue(g.css("clip").matches("rect\\(\\d+px[, ]+\\d+px[, ]+\\d+px[, ]+\\d+px\\)")); + timer1.schedule(duration/2 + 1); + } + }; + + // Start the first timer + timer2.schedule(duration/2); + } private void assertPosition(GQuery g, Offset min, Offset max) { int a = Math.min(min.top, max.top); -- 2.39.5