From 811eb1e6d69028505f9b9ccf82196809ce1186a4 Mon Sep 17 00:00:00 2001 From: michaelvogt Date: Wed, 21 Aug 2013 14:09:19 +0200 Subject: [PATCH] Activate tab stop automatically for modal windows (#12344) Change-Id: Icef7a3bb3729ebd407fe53af334f93e1e5c0a7cb --- client/src/com/vaadin/client/ui/VWindow.java | 28 ++++++++++++++------ server/src/com/vaadin/ui/Window.java | 12 ++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 7c0c875072..fd28e4137e 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -254,6 +254,15 @@ public class VWindow extends VWindowOverlay implements removeTabBlockHandlers(); } + private void addTabBlockHandlers() { + if (topBlockerRegistration == null) { + topBlockerRegistration = Event + .addNativePreviewHandler(topEventBlocker); + bottomBlockerRegistration = Event + .addNativePreviewHandler(bottomEventBlocker); + } + } + private void removeTabBlockHandlers() { if (topBlockerRegistration != null) { topBlockerRegistration.removeHandler(); @@ -646,6 +655,7 @@ public class VWindow extends VWindowOverlay implements if (isAttached()) { showModalityCurtain(); } + addTabBlockHandlers(); deferOrdering(); } else { if (modalityCurtain != null) { @@ -654,6 +664,9 @@ public class VWindow extends VWindowOverlay implements } modalityCurtain = null; } + if (!doTabStop) { + removeTabBlockHandlers(); + } } } @@ -1342,21 +1355,20 @@ public class VWindow extends VWindowOverlay implements /** * Registers the handlers that prevent to leave the window using the * Tab-key. + *

+ * The value of the parameter doTabStop is stored and used for non-modal + * windows. For modal windows, the handlers are always registered, while + * preserving the stored value. * * @param doTabStop * true to prevent leaving the window, false to allow leaving the - * window + * window for non modal windows */ public void setTabStopEnabled(boolean doTabStop) { this.doTabStop = doTabStop; - if (doTabStop) { - if (topBlockerRegistration == null) { - topBlockerRegistration = Event - .addNativePreviewHandler(topEventBlocker); - bottomBlockerRegistration = Event - .addNativePreviewHandler(bottomEventBlocker); - } + if (doTabStop || vaadinModality) { + addTabBlockHandlers(); } else { removeTabBlockHandlers(); } diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index dfe83d48a1..8e7c6dbc80 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -637,7 +637,10 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, /** * Sets window modality. When a modal window is open, components outside - * that window it cannot be accessed. + * that window cannot be accessed. + *

+ * Keyboard navigation is restricted by blocking the tab key at the top and + * bottom of the window by activating the tab stop function internally. * * @param modal * true if modality is to be turned on @@ -1110,11 +1113,14 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, } /** - * Set if it should be prevented to set the focus to a component outside the - * window with the tab key. + * Set if it should be prevented to set the focus to a component outside a + * non-modal window with the tab key. *

* This is meant to help users of assistive devices to not leaving the * window unintentionally. + *

+ * For modal windows, this function is activated automatically, while + * preserving the stored value of tabStop. * * @param tabStop * true to keep the focus inside the window when reaching the top -- 2.39.5