]> source.dussan.org Git - vaadin-framework.git/commitdiff
Activate tab stop automatically for modal windows (#12344)
authormichaelvogt <michael@vaadin.com>
Wed, 21 Aug 2013 12:09:19 +0000 (14:09 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 26 Aug 2013 11:32:17 +0000 (11:32 +0000)
Change-Id: Icef7a3bb3729ebd407fe53af334f93e1e5c0a7cb

client/src/com/vaadin/client/ui/VWindow.java
server/src/com/vaadin/ui/Window.java

index 7c0c875072d0e8872219cd0f328d46e201a3f3a1..fd28e4137e63d4c68a25ffdcc01baafef4d3bed4 100644 (file)
@@ -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.
+     * <p>
+     * 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();
         }
index dfe83d48a19237e3df94197cca82d146116fa11d..8e7c6dbc8084eae7018ddd7b44faee9e7efddcf1 100644 (file)
@@ -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.
+     * <p>
+     * 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.
      * <p>
      * This is meant to help users of assistive devices to not leaving the
      * window unintentionally.
+     * <p>
+     * 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