From 645fa219442d111abb14192d37748dcd720ed7f3 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Fri, 8 Oct 2010 06:00:03 +0000 Subject: [PATCH] Fixes #4200 ESC keypress is now canceled when the XHR is active, to avoid accidentally svn changeset:15455/svn branch:6.4 --- .../gwt/client/ApplicationConnection.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 9cf14b4ec0..9d245ee99b 100755 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -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(); + } + } + } + }); + } /** -- 2.39.5