Revision: 9785
Author: p...@google.com
Date: Tue Mar  1 05:24:17 2011
Log: Fix bug for IE frames where onload events don't fire.

Issue: http://code.google.com/p/google-webtoolkit/issues/detail?id=1720

Review at http://gwt-code-reviews.appspot.com/1353801

Review by: jlaba...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9785

Added:
 /trunk/user/test/com/google/gwt/dom/public-test/iframetest.html
Modified:
 /trunk/user/src/com/google/gwt/user/client/impl/DOMImplOpera.java
 /trunk/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java
 /trunk/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java
 /trunk/user/src/com/google/gwt/user/client/ui/Frame.java
 /trunk/user/src/com/google/gwt/user/client/ui/Image.java
 /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImpl.java
 /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImplIE6.java
 /trunk/user/test/com/google/gwt/dom/DOMSuite.java
 /trunk/user/test/com/google/gwt/dom/client/FrameTests.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/dom/public-test/iframetest.html Tue Mar 1 05:24:17 2011
@@ -0,0 +1,10 @@
+<html>
+<body>
+IFRAME TEST
+</body>
+</html>
+<html>
+<body>
+IFRAME TEST
+</body>
+</html>
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/DOMImplOpera.java Fri Nov 20 16:10:50 2009 +++ /trunk/user/src/com/google/gwt/user/client/impl/DOMImplOpera.java Tue Mar 1 05:24:17 2011
@@ -59,7 +59,7 @@
     elem.onscroll      = (bits & 0x04000) ?
@com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
     elem.onload        = (bits & 0x08000) ?
- @com.google.gwt.user.client.impl.DOMImplStandard::dispatchUnhandledEvent : null; + @com.google.gwt.user.client.impl.DOMImplStandard::dispatchOnLoadEvent : null;
     elem.onerror       = (bits & 0x10000) ?
@com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
     elem.onmousewheel  = (bits & 0x20000) ?
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java Tue Nov 23 11:35:12 2010 +++ /trunk/user/src/com/google/gwt/user/client/impl/DOMImplStandard.java Tue Mar 1 05:24:17 2011
@@ -39,7 +39,7 @@
   private static JavaScriptObject dispatchEvent;

   @SuppressWarnings("unused")
-  private static JavaScriptObject dispatchUnhandledEvent;
+  private static JavaScriptObject dispatchOnLoadEvent;

   @Override
   public Element eventGetFromElement(Event evt) {
@@ -167,8 +167,8 @@
       return true;
     });

- @com.google.gwt.user.client.impl.DOMImplStandard::dispatchUnhandledEvent = $entry(function(evt) {
-      this.__gwtLastUnhandledEvent = evt.type;
+ @com.google.gwt.user.client.impl.DOMImplStandard::dispatchOnLoadEvent = $entry(function(evt) {
+      this.__gwtLastOnLoadEvent = evt.type;
@com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent.call(this, evt);
     });

@@ -248,7 +248,7 @@
     if (chMask & 0x04000) elem.onscroll      = (bits & 0x04000) ?
@com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
     if (chMask & 0x08000) elem.onload        = (bits & 0x08000) ?
- @com.google.gwt.user.client.impl.DOMImplStandard::dispatchUnhandledEvent : null; + @com.google.gwt.user.client.impl.DOMImplStandard::dispatchOnLoadEvent : null;
     if (chMask & 0x10000) elem.onerror       = (bits & 0x10000) ?
@com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
     if (chMask & 0x20000) elem.onmousewheel  = (bits & 0x20000) ?
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java Wed Jan 19 06:51:52 2011 +++ /trunk/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java Tue Mar 1 05:24:17 2011
@@ -31,7 +31,7 @@
   private static JavaScriptObject callDispatchDblClickEvent;

   @SuppressWarnings("unused")
-  private static JavaScriptObject callDispatchUnhandledEvent;
+  private static JavaScriptObject callDispatchOnLoadEvent;

   /**
* Let every GWT app on the page preview the current event. If any app cancels
@@ -154,8 +154,8 @@
       }
     });

-    var dispatchUnhandledEvent = $entry(function() {
-      this.__gwtLastUnhandledEvent = $wnd.event.type;
+    var dispatchOnLoadEvent = $entry(function() {
+      this.__gwtLastOnLoadEvent = $wnd.event.type;
       dispatchEvent.call(this);
     });

@@ -173,9 +173,9 @@
@com.google.gwt.user.client.impl.DOMImplTrident::callDispatchDblClickEvent = new Function('w', 'return function() { w.__gwt_dispatchDblClickEvent_' + moduleName + '.call(this)}')($wnd);

- $wnd['__gwt_dispatchUnhandledEvent_' + moduleName] = dispatchUnhandledEvent; - @com.google.gwt.user.client.impl.DOMImplTrident::callDispatchUnhandledEvent = new Function('w', - 'return function() { w.__gwt_dispatchUnhandledEvent_' + moduleName + '.call(this)}')($wnd);
+    $wnd['__gwt_dispatchOnLoadEvent_' + moduleName] = dispatchOnLoadEvent;
+ @com.google.gwt.user.client.impl.DOMImplTrident::callDispatchOnLoadEvent = new Function('w', + 'return function() { w.__gwt_dispatchOnLoadEvent_' + moduleName + '.call(w.event.srcElement)}')($wnd);

// We need to create these delegate functions to fix up the 'this' context.
     // Normally, 'this' is the firing element, but this is only true for
@@ -268,8 +268,13 @@
@com.google.gwt.user.client.impl.DOMImplTrident::callDispatchEvent : null;
     if (chMask & 0x04000) elem.onscroll      = (bits & 0x04000) ?
@com.google.gwt.user.client.impl.DOMImplTrident::callDispatchEvent : null;
-    if (chMask & 0x08000) elem.onload        = (bits & 0x08000) ?
- @com.google.gwt.user.client.impl.DOMImplTrident::callDispatchUnhandledEvent : null;
+    if (chMask & 0x08000) {
+      if (bits & 0x08000) {
+ elem.attachEvent('onload', @com.google.gwt.user.client.impl.DOMImplTrident::callDispatchOnLoadEvent);
+      } else {
+ elem.detachEvent('onload', @com.google.gwt.user.client.impl.DOMImplTrident::callDispatchOnLoadEvent);
+      }
+    }
     if (chMask & 0x10000) elem.onerror       = (bits & 0x10000) ?
@com.google.gwt.user.client.impl.DOMImplTrident::callDispatchEvent : null;
     if (chMask & 0x20000) elem.onmousewheel  = (bits & 0x20000) ?
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Frame.java Tue Jul 8 12:08:40 2008 +++ /trunk/user/src/com/google/gwt/user/client/ui/Frame.java Tue Mar 1 05:24:17 2011
@@ -15,10 +15,16 @@
  */
 package com.google.gwt.user.client.ui;

+import com.google.gwt.user.client.Event;
+
 import com.google.gwt.dom.client.Document;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.FrameElement;
 import com.google.gwt.dom.client.IFrameElement;
+import com.google.gwt.event.dom.client.HasLoadHandlers;
+import com.google.gwt.event.dom.client.LoadEvent;
+import com.google.gwt.event.dom.client.LoadHandler;
+import com.google.gwt.event.shared.HandlerRegistration;

 /**
* A widget that wraps an IFRAME element, which can contain an arbitrary web
@@ -37,7 +43,7 @@
  * <h3>Example</h3> {@example com.google.gwt.examples.FrameExample}
  * </p>
  */
-public class Frame extends Widget {
+public class Frame extends Widget implements HasLoadHandlers {

   static final String DEFAULT_STYLENAME = "gwt-Frame";

@@ -69,6 +75,8 @@
   public Frame() {
     setElement(Document.get().createIFrameElement());
     setStyleName(DEFAULT_STYLENAME);
+
+    sinkEvents(Event.ONLOAD);
   }

   /**
@@ -91,6 +99,17 @@
     IFrameElement.as(element);
     setElement(element);
   }
+
+  /**
+   * Adds a {@link LoadEvent} load handler which will be called
+   * when the frame loads.
+   *
+   * @param handler the load handler
+ * @return {@link HandlerRegistration} that can be used to remove this handler
+   */
+  public HandlerRegistration addLoadHandler(LoadHandler handler) {
+    return addHandler(handler, LoadEvent.getType());
+  }

   /**
    * Gets the URL of the frame's resource.
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Image.java Tue Nov 23 11:35:12 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/Image.java Tue Mar 1 05:24:17 2011
@@ -117,7 +117,7 @@
* The attribute that is set when an image fires a native load or error event
    * before it is attached.
    */
- private static final String UNHANDLED_EVENT_ATTR = "__gwtLastUnhandledEvent"; + private static final String UNHANDLED_EVENT_ATTR = "__gwtLastOnLoadEvent";

   /**
* Implementation of behaviors associated with the clipped state of an image.
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImpl.java Fri Nov 20 16:10:50 2009 +++ /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImpl.java Tue Mar 1 05:24:17 2011
@@ -51,7 +51,7 @@
         + (-top + "px");

     String clippedImgHtml = "<img "
-        + "onload='this.__gwtLastUnhandledEvent=\"load\";' src='"
+        + "onload='this.__gwtLastOnLoadEvent=\"load\";' src='"
         + GWT.getModuleBaseURL() + "clear.cache.gif' style='" + style
         + "' border='0'>";

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImplIE6.java Wed Mar 3 05:43:42 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/impl/ClippedImageImplIE6.java Tue Mar 1 05:24:17 2011
@@ -115,7 +115,7 @@
      */
     String clippedImgHtml = "<gwt:clipper style=\""
         + clipperStyle
-        + "\"><img onload='this.__gwtLastUnhandledEvent=\"load\";' src='"
+        + "\"><img onload='this.__gwtLastOnLoadEvent=\"load\";' src='"
         + moduleBaseUrlProtocol
+ "' onerror='if(window.__gwt_transparentImgHandler)window.__gwt_transparentImgHandler(this);else this.src=\"" + GWT.getModuleBaseURL() + "clear.cache.gif\"' style=\"" + imgStyle + "\" width=" + (left + width) + " height=" + (top + height)
=======================================
--- /trunk/user/test/com/google/gwt/dom/DOMSuite.java Fri May 15 04:43:01 2009 +++ /trunk/user/test/com/google/gwt/dom/DOMSuite.java Tue Mar 1 05:24:17 2011
@@ -18,6 +18,7 @@
 import com.google.gwt.dom.client.DocumentTest;
 import com.google.gwt.dom.client.ElementTest;
 import com.google.gwt.dom.client.FormTests;
+import com.google.gwt.dom.client.FrameTests;
 import com.google.gwt.dom.client.MapTests;
 import com.google.gwt.dom.client.NodeTest;
 import com.google.gwt.dom.client.SelectTests;
@@ -40,6 +41,7 @@
     suite.addTestSuite(NodeTest.class);
     suite.addTestSuite(ElementTest.class);
     suite.addTestSuite(FormTests.class);
+    suite.addTestSuite(FrameTests.class);
     suite.addTestSuite(MapTests.class);
     suite.addTestSuite(SelectTests.class);
     suite.addTestSuite(StyleInjectorTest.class);
=======================================
--- /trunk/user/test/com/google/gwt/dom/client/FrameTests.java Wed Jan 19 06:51:52 2011 +++ /trunk/user/test/com/google/gwt/dom/client/FrameTests.java Tue Mar 1 05:24:17 2011
@@ -16,12 +16,20 @@
 package com.google.gwt.dom.client;

 import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Frame;
+import com.google.gwt.user.client.ui.RootPanel;
+
+import com.google.gwt.event.dom.client.LoadEvent;
+import com.google.gwt.event.dom.client.LoadHandler;

 /**
  * Tests for the FrameElement and IFrameElement classes.
  */
 public class FrameTests extends GWTTestCase {

+  private static final int FRAME_LOAD_DELAY = 3000;
+
   @Override
   public String getModuleName() {
     return "com.google.gwt.dom.DOMTest";
@@ -34,4 +42,52 @@
     doc.getBody().appendChild(iframe);
     assertNotNull(iframe.getContentDocument());
   }
-}
+
+  public void testOnLoadEventFiresWithBrowerEvent() {
+    delayTestFinish(FRAME_LOAD_DELAY);
+
+    Frame frame = new Frame() {
+      public void onBrowserEvent(Event event) {
+        if (event.getTypeInt() == Event.ONLOAD) {
+          finishTest();
+        }
+        super.onBrowserEvent(event);
+      }
+    };
+
+    frame.sinkEvents(Event.ONLOAD);
+    RootPanel.get().add(frame);
+    frame.setUrl("iframetest.html");
+  }
+
+  public void testOnLoadEventFiresWithLoadHandler() {
+    delayTestFinish(FRAME_LOAD_DELAY);
+
+    Frame frame = new Frame();
+    frame.addLoadHandler(new LoadHandler() {
+      public void onLoad(LoadEvent event) {
+        finishTest();
+      }
+    });
+
+    RootPanel.get().add(frame);
+    frame.setUrl("iframetest.html");
+  }
+
+  public void testOnLoadEventFiresWithDomLoadHandler() {
+    delayTestFinish(FRAME_LOAD_DELAY);
+
+    Frame frame = new Frame() {
+      {
+        addDomHandler(new LoadHandler() {
+          public void onLoad(LoadEvent event) {
+            finishTest();
+          }
+        }, LoadEvent.getType());
+      }
+    };
+
+    RootPanel.get().add(frame);
+    frame.setUrl("iframetest.html");
+  }
+}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to