You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2011/06/22 21:21:49 UTC

svn commit: r1138592 - /pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java

Author: rwhitcomb
Date: Wed Jun 22 19:21:49 2011
New Revision: 1138592

URL: http://svn.apache.org/viewvc?rev=1138592&view=rev
Log:
Incorrect handling of TAB key in SuggestionPopup

This is part of the fix for JIRA PIVOT-762.

Straightens out the handling of Tab/Shift-Tab keys in SuggestionPopup
(in the TerraSuggestionPopupSkin) by correctly checking for these keys
in the ListView rather than the SuggestionPopup itself, and then
setting a variable everywhere: "returnFocusToTextInput" which
determines whether the key or mouse click is trying to focus
elsewhere once the popup is closed, or whether (in the case of
ENTER or ESCAPE) the focus should go right back to the TextInput.

Note: there are still issues of whether ESCAPE should restore
the "previous" text or not and there are other components that
"pop up" that should have similar fixes for Tab/Shift-Tab handling.

Modified:
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java?rev=1138592&r1=1138591&r2=1138592&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraSuggestionPopupSkin.java Wed Jun 22 19:21:49 2011
@@ -63,6 +63,7 @@ public class TerraSuggestionPopupSkin ex
 
     private DropShadowDecorator dropShadowDecorator = null;
     private Transition closeTransition = null;
+    private boolean returnFocusToTextInput = true;
 
     private int closeTransitionDuration = DEFAULT_CLOSE_TRANSITION_DURATION;
     private int closeTransitionRate = DEFAULT_CLOSE_TRANSITION_RATE;
@@ -78,6 +79,7 @@ public class TerraSuggestionPopupSkin ex
 
             if (!suggestionPopup.isAncestor(descendant)
                 && descendant != textInput) {
+                returnFocusToTextInput = false;
                 suggestionPopup.close(false);
             }
 
@@ -98,6 +100,7 @@ public class TerraSuggestionPopupSkin ex
 
             if (!component.isFocused()
                 && !suggestionPopup.containsFocus()) {
+                returnFocusToTextInput = false;
                 suggestionPopup.close();
             }
         }
@@ -144,12 +147,43 @@ public class TerraSuggestionPopupSkin ex
         }
     };
 
+    private ComponentKeyListener listViewKeyListener = new ComponentKeyListener.Adapter() {
+        /**
+         * {@link KeyCode#TAB TAB} Close the suggestion popup with a 'result' of
+         * true, and transfer focus forwards from the TextInput.<br>
+         * {@link KeyCode#TAB TAB} + {@link Modifier#SHIFT SHIFT} Close the
+         * suggestion popup with a 'result' of true, and transfer focus backwards
+         * from the TextInput.<br>
+         */
+        @Override
+        public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
+            SuggestionPopup suggestionPopup = (SuggestionPopup)getComponent();
+            TextInput textInput = suggestionPopup.getTextInput();
+
+            switch (keyCode) {
+                case Keyboard.KeyCode.TAB: {
+                    returnFocusToTextInput = false;
+                    suggestionPopup.close(true);
+
+                    FocusTraversalDirection direction = (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) ?
+                        FocusTraversalDirection.BACKWARD : FocusTraversalDirection.FORWARD;
+                    textInput.transferFocus(direction);
+
+                    break;
+                }
+            }
+
+            return false;
+        }
+    };
+
     private static final int DEFAULT_CLOSE_TRANSITION_DURATION = 150;
     private static final int DEFAULT_CLOSE_TRANSITION_RATE = 30;
 
     public TerraSuggestionPopupSkin () {
         listView.getStyles().put("variableItemHeight", true);
         listView.getListViewSelectionListeners().add(listViewSelectionListener);
+        listView.getComponentKeyListeners().add(listViewKeyListener);
 
         listViewPanorama = new Panorama(listView);
         listViewPanorama.getStyles().put("buttonBackgroundColor",
@@ -261,11 +295,6 @@ public class TerraSuggestionPopupSkin ex
     /**
      * {@link KeyCode#ENTER ENTER} Close the suggestion popup with a 'result' of
      * true.<br>
-     * {@link KeyCode#TAB TAB} Close the suggestion popup with a 'result' of
-     * true, and transfer focus forwards from the TextInput.<br>
-     * {@link KeyCode#TAB TAB} + {@link Modifier#SHIFT SHIFT} Close the
-     * suggestion popup with a 'result' of true, and transfer focus backwards
-     * from the TextInput.<br>
      * {@link KeyCode#ESCAPE ESCAPE} Close the suggestion popup with a 'result'
      * of false.
      */
@@ -280,16 +309,6 @@ public class TerraSuggestionPopupSkin ex
                 break;
             }
 
-            case Keyboard.KeyCode.TAB: {
-                suggestionPopup.close(true);
-
-                FocusTraversalDirection direction = (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) ?
-                    FocusTraversalDirection.BACKWARD : FocusTraversalDirection.FORWARD;
-                textInput.transferFocus(direction);
-
-                break;
-            }
-
             case Keyboard.KeyCode.ESCAPE: {
                 suggestionPopup.close(false);
                 break;
@@ -327,6 +346,8 @@ public class TerraSuggestionPopupSkin ex
 
         dropShadowDecorator.setShadowOpacity(DropShadowDecorator.DEFAULT_SHADOW_OPACITY);
 
+        returnFocusToTextInput = true;
+
         TextInput textInput = suggestionPopup.getTextInput();
         textInput.getComponentStateListeners().add(textInputStateListener);
         textInput.getComponentKeyListeners().add(textInputKeyListener);
@@ -428,7 +449,9 @@ public class TerraSuggestionPopupSkin ex
         textInput.getComponentStateListeners().remove(textInputStateListener);
         textInput.getComponentKeyListeners().remove(textInputKeyListener);
 
-        textInput.requestFocus();
+        if (returnFocusToTextInput) {
+            textInput.requestFocus();
+        }
 
         listViewBorder.setEnabled(true);
         closeTransition = null;