]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes #4200 ESC keypress is now canceled when the XHR is active, to avoid accidentally
authorMarc Englund <marc.englund@itmill.com>
Fri, 8 Oct 2010 06:00:03 +0000 (06:00 +0000)
committerMarc Englund <marc.englund@itmill.com>
Fri, 8 Oct 2010 06:00:03 +0000 (06:00 +0000)
svn changeset:15455/svn branch:6.4

src/com/vaadin/terminal/gwt/client/ApplicationConnection.java

index 9cf14b4ec0f8c3cd2640e9150f8569f790cc964d..9d245ee99bdfa6dcb6df657ca6bebc3ecc2cb683 100755 (executable)
@@ -15,6 +15,8 @@ import java.util.Set;
 import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.core.client.JsArrayString;
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.event.dom.client.KeyCodes;
 import com.google.gwt.http.client.Request;
 import com.google.gwt.http.client.RequestBuilder;
 import com.google.gwt.http.client.RequestCallback;
@@ -25,6 +27,8 @@ import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Event.NativePreviewEvent;
+import com.google.gwt.user.client.Event.NativePreviewHandler;
 import com.google.gwt.user.client.History;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
@@ -176,6 +180,26 @@ public class ApplicationConnection {
         view.init(cnf.getRootPanelId());
         showLoadingIndicator();
 
+        /*
+         * This is used to cancel ESC keypresses while the XHR is active,
+         * otherwise the XHR might be canceled, at least in some browsers. We'll
+         * pass trough the keypress if no XHR is active, so that other stuff
+         * might still be canceled (e.g large images).
+         */
+        Event.addNativePreviewHandler(new NativePreviewHandler() {
+            public void onPreviewNativeEvent(NativePreviewEvent event) {
+                if (activeRequests <= 0) {
+                    return;
+                }
+                if (event.getTypeInt() == Event.ONKEYDOWN) {
+                    NativeEvent nativeEvent = event.getNativeEvent();
+                    if (nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE) {
+                        nativeEvent.preventDefault();
+                    }
+                }
+            }
+        });
+
     }
 
     /**