Re-apply r5787.
$ svn diff -c5787 | patch -p0 && svn commit user
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5810 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/User.gwt.xml b/user/src/com/google/gwt/user/User.gwt.xml
index 87c4bb7..2e31cd1 100644
--- a/user/src/com/google/gwt/user/User.gwt.xml
+++ b/user/src/com/google/gwt/user/User.gwt.xml
@@ -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" />
diff --git a/user/src/com/google/gwt/user/client/impl/WindowImplIE.java b/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
index 46ec347..386aa35 100644
--- a/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
+++ b/user/src/com/google/gwt/user/client/impl/WindowImplIE.java
@@ -18,6 +18,8 @@
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;
/**
@@ -26,6 +28,31 @@
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
* fragment contains a '?'. To avoid this bug, we use location.href instead.
*/
@@ -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,8 +101,8 @@
@Override
public void initWindowScrollHandler() {
- initHandler(getWindowScrollHandlerMethodString(),
- "__gwt_initWindowScrollHandler", new Command() {
+ initHandler(Resources.INSTANCE.initWindowScrollHandler().getText(),
+ new Command() {
public void execute() {
initWindowScrollHandlerImpl();
}
@@ -83,110 +110,16 @@
}
/**
- * 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,
* so we must embed a script in the parent window that will set the event
* 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);
diff --git a/user/src/com/google/gwt/user/client/impl/initWindowCloseHandler.js b/user/src/com/google/gwt/user/client/impl/initWindowCloseHandler.js
new file mode 100644
index 0000000..f0f923d
--- /dev/null
+++ b/user/src/com/google/gwt/user/client/impl/initWindowCloseHandler.js
@@ -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;
+}
diff --git a/user/src/com/google/gwt/user/client/impl/initWindowResizeHandler.js b/user/src/com/google/gwt/user/client/impl/initWindowResizeHandler.js
new file mode 100644
index 0000000..f1631be
--- /dev/null
+++ b/user/src/com/google/gwt/user/client/impl/initWindowResizeHandler.js
@@ -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;
+}
diff --git a/user/src/com/google/gwt/user/client/impl/initWindowScrollHandler.js b/user/src/com/google/gwt/user/client/impl/initWindowScrollHandler.js
new file mode 100644
index 0000000..3713092
--- /dev/null
+++ b/user/src/com/google/gwt/user/client/impl/initWindowScrollHandler.js
@@ -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;
+}