changeset 5910:022d5863ddd9

Partial fix for RT-34620: [Default Button] Button set to default is not reacting to ComboBox enter key
author jgiles
date Thu, 12 Dec 2013 16:15:20 +1300
parents dcda500991c5
children 6aa65cf42394
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ComboBoxBaseBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java
diffstat 3 files changed, 35 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ComboBoxBaseBehavior.java	Thu Dec 12 14:31:07 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ComboBoxBaseBehavior.java	Thu Dec 12 16:15:20 2013 +1300
@@ -105,24 +105,12 @@
         COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(F4, KEY_RELEASED, "togglePopup"));
         COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(UP, "togglePopup").alt());
         COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(DOWN, "togglePopup").alt());
-        
-        if (Utils.isWindows()) {
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_PRESSED, PRESS_ACTION));
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_RELEASED, RELEASE_ACTION));
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_PRESSED, PRESS_ACTION));
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_RELEASED, RELEASE_ACTION));
-        } else {
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_PRESSED, PRESS_ACTION));
-            COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_RELEASED, RELEASE_ACTION));
-            if (com.sun.javafx.scene.control.skin.Utils.isTwoLevelFocus()) {
-                COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_PRESSED, PRESS_ACTION));
-                COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_RELEASED, RELEASE_ACTION));
-            }
-        }
+
+        COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_PRESSED, PRESS_ACTION));
+        COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(SPACE, KEY_RELEASED, RELEASE_ACTION));
 
         COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_PRESSED, PRESS_ACTION));
         COMBO_BOX_BASE_BINDINGS.add(new KeyBinding(ENTER, KEY_RELEASED, RELEASE_ACTION));
-        
     }
 
     @Override protected void callAction(String name) {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Dec 12 14:31:07 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Dec 12 16:15:20 2013 +1300
@@ -160,13 +160,6 @@
                 // ever giving the event to the TextField.
                 if (ke.getCode() == KeyCode.ENTER) {
                     setTextFromTextFieldIntoComboBoxValue();
-                    /*
-                    ** don't consume this if we're on an embedded
-                    ** platform that supports 5-button navigation 
-                    */
-                    if (!Utils.isTwoLevelFocus()) {
-                        ke.consume();
-                    }
                     return;
                 } else if (ke.getCode() == KeyCode.F4 && ke.getEventType() == KeyEvent.KEY_RELEASED) {
                     if (comboBox.isShowing()) comboBox.hide();
--- a/modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java	Thu Dec 12 14:31:07 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/ComboBoxTest.java	Thu Dec 12 16:15:20 2013 +1300
@@ -56,6 +56,7 @@
 import javafx.scene.Scene;
 import javafx.scene.input.KeyCode;
 import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
 import javafx.scene.shape.Circle;
 import javafx.stage.Stage;
@@ -1159,4 +1160,35 @@
         assertEquals(0, comboBox.getButtonCell().getIndex());
         assertFalse(customCell.getPseudoClassStates().contains(empty));
     }
+
+    private int test_rt34603_count = 0;
+    @Ignore("Bug has not yet been resolved")
+    @Test public void test_rt34603() {
+        assertEquals(0, test_rt34603_count);
+
+        VBox hbox = new VBox(10);
+
+        ComboBox<String> box = new ComboBox<>();
+        box.getItems().add("test");
+        box.setEditable(true);
+        box.getSelectionModel().selectFirst();
+
+        Button defaultButton = new Button("press");
+        defaultButton.setOnAction(new EventHandler<ActionEvent>() {
+            @Override public void handle(ActionEvent arg0) {
+                test_rt34603_count++;
+            }
+        });
+        defaultButton.setDefaultButton(true);
+
+        hbox.getChildren().addAll(box, defaultButton);
+
+        new StageLoader(hbox);
+
+        box.getEditor().requestFocus();
+        KeyEventFirer keyboard = new KeyEventFirer(box);
+        keyboard.doKeyPress(KeyCode.ENTER);
+
+        assertEquals(1, test_rt34603_count);
+    }
 }