]> source.dussan.org Git - gwtquery.git/commitdiff
fixed an issue in PropertiesAnimation with the width and height. Added tests for...
authorManolo Carrasco <manolo@apache.org>
Wed, 16 Jun 2010 15:28:18 +0000 (15:28 +0000)
committerManolo Carrasco <manolo@apache.org>
Wed, 16 Jun 2010 15:28:18 +0000 (15:28 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java

index 941fd14e9e32ecd4187e10994f933cb97b287796..394e27ebc7082660efb73f2bcabdcf552d85ad65 100644 (file)
@@ -275,10 +275,10 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
     GQuery g = $(elem);\r
     String val = g.css(prop, true);\r
     if ("height".equalsIgnoreCase(prop)) {\r
-      return g.clientHeight();\r
+      return elem.getClientHeight() - cur(elem, "paddingTop") - cur(elem, "paddingBottom");\r
     }\r
     if ("width".equalsIgnoreCase(prop)) {\r
-      return g.clientWidth();\r
+      return elem.getClientWidth() - cur(elem, "paddingLeft") - cur(elem, "paddingRight");\r
     }\r
     if ("absolute".equalsIgnoreCase(g.css("position", true))) {\r
       if ("left".equalsIgnoreCase(prop)) {\r
index c1d240b6c8938fb32ee6d50c9d5a56f82e741d61..e53f77caa844d9df2c3cbc40ee978136b671a578 100644 (file)
@@ -617,4 +617,18 @@ public class GQueryCoreTest extends GWTTestCase {
     assertEquals("block", sectC.css("display"));
   }
   
+  public void testWidthHeight() {
+    $(e)
+    .html(
+        "<div style='border: 1px solid red; padding: 10px; width: 100px; height: 100px'>Content 1</div>");
+    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"));
+  }
 }
index 94e2bd115310a27e6fc76e7ce8babd73b93a912f..b77455293570127f5174aa9f337124f352bb7430 100644 (file)
@@ -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("<p id='idtest'>Content 1</p></p>");
+    
+    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);