Revision: 5787
Author: [email protected]
Date: Fri Jul 24 10:34:50 2009
Log: WindowImplIE uses a TextResource as the source of JavaScript code  
instead of a JSNI mathed that uses function.toString().

Patch by: jlabanca
Review by: jgw
http://code.google.com/p/google-web-toolkit/source/detail?r=5787

Added:
  /trunk/user/src/com/google/gwt/user/client/impl/initWindowCloseHandler.js
  /trunk/user/src/com/google/gwt/user/client/impl/initWindowResizeHandler.js
  /trunk/user/src/com/google/gwt/user/client/impl/initWindowScrollHandler.js
Modified:
  /trunk/user/src/com/google/gwt/user/User.gwt.xml
  /trunk/user/src/com/google/gwt/user/client/impl/WindowImplIE.java

=======================================
--- /dev/null
+++  
/trunk/user/src/com/google/gwt/user/client/impl/initWindowCloseHandler.js       
 
Fri Jul 24 10:34:50 2009
@@ -0,0 +1,38 @@
+function __gwt_initWindowCloseHandler(beforeunload, unload) {
+  var wnd = window
+  , oldOnBeforeUnload = wnd.onbeforeunload
+  , oldOnUnload = wnd.onunload;
+
+  wnd.onbeforeunload = function(evt) {
+    var ret, oldRet;
+    try {
+      ret = beforeunload();
+    } finally {
+      oldRet = oldOnBeforeUnload && oldOnBeforeUnload(evt);
+    }
+    // Avoid returning null as IE6 will coerce it into a string.
+    // Ensure that "" gets returned properly.
+    if (ret != null) {
+      return ret;
+    }
+    if (oldRet != null) {
+      return oldRet;
+    }
+    // returns undefined.
+  };
+
+  wnd.onunload = function(evt) {
+    try {
+      unload();
+    } finally {
+      oldOnUnload && oldOnUnload(evt);
+      wnd.onresize = null;
+      wnd.onscroll = null;
+      wnd.onbeforeunload = null;
+      wnd.onunload = null;
+    }
+  };
+
+  // Remove the reference once we've initialize the handler
+  wnd.__gwt_initWindowCloseHandler = undefined;
+}
=======================================
--- /dev/null
+++  
/trunk/user/src/com/google/gwt/user/client/impl/initWindowResizeHandler.js      
 
Fri Jul 24 10:34:50 2009
@@ -0,0 +1,14 @@
+function __gwt_initWindowResizeHandler(resize) {
+  var wnd = window, oldOnResize = wnd.onresize;
+
+  wnd.onresize = function(evt) {
+    try {
+      resize();
+    } finally {
+      oldOnResize && oldOnResize(evt);
+    }
+  };
+
+  // Remove the reference once we've initialize the handler
+  wnd.__gwt_initWindowResizeHandler = undefined;
+}
=======================================
--- /dev/null
+++  
/trunk/user/src/com/google/gwt/user/client/impl/initWindowScrollHandler.js      
 
Fri Jul 24 10:34:50 2009
@@ -0,0 +1,14 @@
+function __gwt_initWindowScrollHandler(scroll) {
+  var wnd = window, oldOnScroll = wnd.onscroll;
+
+  wnd.onscroll = function(evt) {
+    try {
+      scroll();
+    } finally {
+      oldOnScroll && oldOnScroll(evt);
+    }
+  };
+
+  // Remove the reference once we've initialize the handler
+  wnd.__gwt_initWindowScrollHandler = undefined;
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/User.gwt.xml    Tue Feb 17 09:09:03  
2009
+++ /trunk/user/src/com/google/gwt/user/User.gwt.xml    Fri Jul 24 10:34:50  
2009
@@ -21,6 +21,7 @@
     <inherits name="com.google.gwt.core.Core"/>
     <inherits name="com.google.gwt.event.Event"/>
     <inherits name="com.google.gwt.animation.Animation"/>
+   <inherits name="com.google.gwt.resources.Resources"/>
     <inherits name="com.google.gwt.user.AsyncProxy"/>
     <inherits name="com.google.gwt.user.RemoteService"/>
     <inherits name="com.google.gwt.user.DocumentRoot" />
=======================================
--- /trunk/user/src/com/google/gwt/user/client/impl/WindowImplIE.java   Wed  
Sep  3 11:45:46 2008
+++ /trunk/user/src/com/google/gwt/user/client/impl/WindowImplIE.java   Fri  
Jul 24 10:34:50 2009
@@ -18,12 +18,39 @@
  import com.google.gwt.core.client.GWT;
  import com.google.gwt.dom.client.Document;
  import com.google.gwt.dom.client.ScriptElement;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.TextResource;
  import com.google.gwt.user.client.Command;

  /**
   * IE implementation of {...@link com.google.gwt.user.client.impl.WindowImpl}.
   */
  public class WindowImplIE extends WindowImpl {
+
+  /**
+   * The resources for this implementation.
+   */
+  public interface Resources extends ClientBundle {
+    Resources INSTANCE = GWT.create(Resources.class);
+
+    /**
+     * Contains the function body used to initialize the window close  
handler.
+     */
+    @Source("initWindowCloseHandler.js")
+    TextResource initWindowCloseHandler();
+
+    /**
+     * Contains the function body used to initialize the window resize  
handler.
+     */
+    @Source("initWindowResizeHandler.js")
+    TextResource initWindowResizeHandler();
+
+    /**
+     * Contains the function body used to initialize the window scroll  
handler.
+     */
+    @Source("initWindowScrollHandler.js")
+    TextResource initWindowScrollHandler();
+  }

    /**
     * For IE6, reading from $wnd.location.hash drops part of the fragment  
if the
@@ -54,8 +81,8 @@

    @Override
    public void initWindowCloseHandler() {
-    initHandler(getWindowCloseHandlerMethodString(),
-        "__gwt_initWindowCloseHandler", new Command() {
+    initHandler(Resources.INSTANCE.initWindowCloseHandler().getText(),
+        new Command() {
            public void execute() {
              initWindowCloseHandlerImpl();
            }
@@ -64,8 +91,8 @@

    @Override
    public void initWindowResizeHandler() {
-    initHandler(getWindowResizeHandlerMethodString(),
-        "__gwt_initWindowResizeHandler", new Command() {
+    initHandler(Resources.INSTANCE.initWindowResizeHandler().getText(),
+        new Command() {
            public void execute() {
              initWindowResizeHandlerImpl();
            }
@@ -74,105 +101,13 @@

    @Override
    public void initWindowScrollHandler() {
-    initHandler(getWindowScrollHandlerMethodString(),
-        "__gwt_initWindowScrollHandler", new Command() {
+    initHandler(Resources.INSTANCE.initWindowScrollHandler().getText(),
+        new Command() {
            public void execute() {
              initWindowScrollHandlerImpl();
            }
          });
    }
-
-  /**
-   * This method defines a function that sinks an event on the Window.   
However,
-   * this method returns the function as a String so it can be added to the
-   * outer window.
-   *
-   * We need to declare this method on the outer window because you cannot
-   * attach Window listeners from within an iframe on IE6.
-   *
-   * Per ECMAScript 262 spec 15.3.4.2, Function.prototype.toString()  
returns a
-   * string representation of the function that has the syntax of the  
function.
-   */
-  private native String getWindowCloseHandlerMethodString() /*-{
-    return function(beforeunload, unload) {
-      var wnd = window
-      , oldOnBeforeUnload = wnd.onbeforeunload
-      , oldOnUnload = wnd.onunload;
-
-      wnd.onbeforeunload = function(evt) {
-        var ret, oldRet;
-        try {
-          ret = beforeunload();
-        } finally {
-          oldRet = oldOnBeforeUnload && oldOnBeforeUnload(evt);
-        }
-        // Avoid returning null as IE6 will coerce it into a string.
-        // Ensure that "" gets returned properly.
-        if (ret != null) {
-          return ret;
-        }
-        if (oldRet != null) {
-          return oldRet;
-        }
-        // returns undefined.
-      };
-
-      wnd.onunload = function(evt) {
-        try {
-          unload();
-        } finally {
-          oldOnUnload && oldOnUnload(evt);
-          wnd.onresize = null;
-          wnd.onscroll = null;
-          wnd.onbeforeunload = null;
-          wnd.onunload = null;
-        }
-      };
-
-      // Remove the reference once we've initialize the handler
-      wnd.__gwt_initWindowCloseHandler = undefined;
-    }.toString();
-  }-*/;
-
-  /**
-   * @see #getWindowCloseHandlerMethodString()
-   */
-  private native String getWindowResizeHandlerMethodString() /*-{
-    return function(resize) {
-      var wnd = window, oldOnResize = wnd.onresize;
-
-      wnd.onresize = function(evt) {
-        try {
-          resize();
-        } finally {
-          oldOnResize && oldOnResize(evt);
-        }
-      };
-
-      // Remove the reference once we've initialize the handler
-      wnd.__gwt_initWindowResizeHandler = undefined;
-    }.toString();
-  }-*/;
-
-  /**
-   * @see #getWindowCloseHandlerMethodString()
-   */
-  private native String getWindowScrollHandlerMethodString() /*-{
-    return function(scroll) {
-      var wnd = window, oldOnScroll = wnd.onscroll;
-
-      wnd.onscroll = function(evt) {
-        try {
-          scroll();
-        } finally {
-          oldOnScroll && oldOnScroll(evt);
-        }
-      };
-
-      // Remove the reference once we've initialize the handler
-      wnd.__gwt_initWindowScrollHandler = undefined;
-    }.toString();
-  }-*/;

    /**
     * IE6 does not allow direct access to event handlers on the parent  
window,
@@ -180,13 +115,11 @@
     * handlers in the correct context.
     *
     * @param initFunc the string representation of the init function
-   * @param funcName the name to assign to the init function
     * @param cmd the command to execute the init function
     */
-  private void initHandler(String initFunc, String funcName, Command cmd) {
+  private void initHandler(String initFunc, Command cmd) {
      if (GWT.isClient()) {
        // Embed the init script on the page
-      initFunc = initFunc.replaceFirst("function", "function " + funcName);
        ScriptElement scriptElem =  
Document.get().createScriptElement(initFunc);
        Document.get().getBody().appendChild(scriptElem);



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

Reply via email to