Revision: 9803
Author: [email protected]
Date: Thu Mar 3 08:28:01 2011
Log: Fix for issue where Image(Element element) does not initialize the
initial ClippedState.
http://gwt-code-reviews.appspot.com/1370804/
Issue: 5998
Author: david.nouls
Review by: jlabanca
http://code.google.com/p/google-web-toolkit/source/detail?r=9803
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/Image.java
/trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Image.java Tue Mar 1
06:29:34 2011
+++ /trunk/user/src/com/google/gwt/user/client/ui/Image.java Thu Mar 3
08:28:01 2011
@@ -409,7 +409,6 @@
assert Document.get().getBody().isOrHasChild(element);
Image image = new Image(element);
- image.changeState(new UnclippedState(element));
// Mark it attached and remember it for cleanup.
image.onAttach();
@@ -481,6 +480,7 @@
protected Image(Element element) {
ImageElement.as(element);
setElement(element);
+ changeState(new UnclippedState(element));
}
public HandlerRegistration addClickHandler(ClickHandler handler) {
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java Fri Oct
8 06:15:38 2010
+++ /trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java Thu Mar
3 08:28:01 2011
@@ -18,6 +18,7 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.event.dom.client.LoadEvent;
@@ -50,6 +51,25 @@
}
}
+ private static class TestImage extends Image {
+ public TestImage(Element element) {
+ super(element);
+ }
+
+ public static TestImage wrap(Element element) {
+ // Assert that the element is attached.
+ assert Document.get().getBody().isOrHasChild(element);
+
+ TestImage image = new TestImage(element);
+
+ // Mark it attached and remember it for cleanup.
+ image.onAttach();
+ RootPanel.detachOnWindowClose(image);
+
+ return image;
+ }
+ }
+
private abstract static class TestLoadHandler implements LoadHandler {
private boolean finished = false;
@@ -555,6 +575,23 @@
image.setVisibleRect(16, 0, 16, 16);
image.setVisibleRect(16, 8, 8, 8);
}
+
+ /**
+ * Tests that it is possible to make a subclass of Image that can be
wrapped.
+ */
+ public void testWrapOfSubclass() {
+ String uid = Document.get().createUniqueId();
+ DivElement div = Document.get().createDivElement();
+ div.setInnerHTML("<img id='" + uid + "' src='counting-forward.png'>");
+ Document.get().getBody().appendChild(div);
+
+ final TestImage image =
TestImage.wrap(Document.get().getElementById(uid));
+ assertNotNull(image);
+
+ // Cleanup.
+ Document.get().getBody().appendChild(div);
+ RootPanel.detachNow(image);
+ }
/**
* Tests that wrapping an existing DOM element works if you call
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors