changeset 10814:ed5f1fe60f02

8194913: Focus traversal is broken if a Pane is added to a ToolBar Reviewed-by: kcr
author aghaisas
date Tue, 23 Jan 2018 11:54:33 +0530
parents a455aff48e48
children 3d5c22069d1f
files modules/javafx.controls/src/main/java/javafx/scene/control/skin/ToolBarSkin.java modules/javafx.controls/src/test/java/test/javafx/scene/control/ToolbarTest.java
diffstat 2 files changed, 57 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ToolBarSkin.java	Fri Jan 19 12:08:49 2018 +0530
+++ b/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ToolBarSkin.java	Tue Jan 23 11:54:33 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -185,7 +185,7 @@
                     }
                     Node selected = context.selectInSubtree(item, owner, dir);
                     if (selected != null) return selected;
-                    idx = boxChildren.indexOf(owner);
+                    idx = boxChildren.indexOf(item);
                     if (dir == Direction.NEXT) dir = Direction.NEXT_IN_LINE;
                 }
 
--- a/modules/javafx.controls/src/test/java/test/javafx/scene/control/ToolbarTest.java	Fri Jan 19 12:08:49 2018 +0530
+++ b/modules/javafx.controls/src/test/java/test/javafx/scene/control/ToolbarTest.java	Tue Jan 23 11:54:33 2018 +0530
@@ -27,7 +27,7 @@
 
 import javafx.css.CssMetaData;
 import static test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils.*;
-
+import test.com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
 import test.com.sun.javafx.pgstub.StubToolkit;
 import javafx.scene.control.skin.ToolBarSkin;
 import com.sun.javafx.tk.Toolkit;
@@ -38,9 +38,13 @@
 import javafx.css.StyleableProperty;
 import javafx.geometry.Orientation;
 import javafx.scene.Node;
+import javafx.scene.Scene;
 import javafx.scene.control.Button;
 import javafx.scene.control.ToolBar;
+import javafx.scene.input.KeyCode;
+import javafx.scene.layout.Pane;
 import javafx.scene.shape.Rectangle;
+import javafx.stage.Stage;
 import static org.junit.Assert.*;
 
 
@@ -167,4 +171,54 @@
         b3.fire();
     }
 
+    @Test public void toolBarFocusTraversalTest() {
+        toolBar.getItems().clear();
+
+        toolBar.setFocusTraversable(true);
+        assertTrue(toolBar.isFocusTraversable());
+
+        // Create 5 buttons - put 2 of them in a Pane
+        Button btn1 = new Button("Btn1");
+        Button btn2 = new Button("Btn2");
+
+        Button btn3 = new Button("Btn3");
+        Button btn4 = new Button("Btn4");
+        Pane p1 = new Pane(btn3, btn4);
+
+        Button btn5 = new Button("Btn5");
+
+        toolBar.getItems().addAll(btn1, btn2, p1, btn5);
+
+        ToolBarSkin toolbarSkin = new ToolBarSkin(toolBar);
+        toolBar.setSkin(toolbarSkin);
+
+        Scene scene = new Scene(toolBar);
+        Stage stage = new Stage();
+        stage.setScene(scene);
+        stage.show();
+        tk.firePulse();
+
+        toolBar.getScene().getWindow().requestFocus();
+        assertTrue(btn1.isFocused());
+
+        KeyEventFirer keyboard1 = new KeyEventFirer(btn1);
+        keyboard1.doKeyPress(KeyCode.TAB);
+        tk.firePulse();
+        assertTrue(btn2.isFocused());
+
+        KeyEventFirer keyboard2 = new KeyEventFirer(btn2);
+        keyboard2.doKeyPress(KeyCode.TAB);
+        tk.firePulse();
+        assertTrue(btn3.isFocused());
+
+        KeyEventFirer keyboard3 = new KeyEventFirer(btn3);
+        keyboard3.doKeyPress(KeyCode.TAB);
+        tk.firePulse();
+        assertTrue(btn4.isFocused());
+
+        KeyEventFirer keyboard4 = new KeyEventFirer(btn4);
+        keyboard4.doKeyPress(KeyCode.TAB);
+        tk.firePulse();
+        assertTrue(btn5.isFocused());
+    }
 }