changeset 6350:1e1033a2eb1c

RT-35876: Focus change on TableView scroll
author jgiles
date Mon, 24 Feb 2014 10:26:25 +1300
parents 89603b0381ec
children 7a8fde19001f
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Mon Feb 24 10:21:46 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Mon Feb 24 10:26:25 2014 +1300
@@ -43,6 +43,7 @@
 import javafx.scene.Group;
 import javafx.scene.Node;
 import javafx.scene.Parent;
+import javafx.scene.Scene;
 import javafx.scene.control.Cell;
 import javafx.scene.control.IndexedCell;
 import javafx.scene.control.ScrollBar;
@@ -1887,10 +1888,41 @@
     }
 
     private void cleanPile() {
+        boolean wasFocusOwner = false;
+
         for (int i = 0, max = pile.size(); i < max; i++) {
             T cell = pile.get(i);
+            wasFocusOwner = wasFocusOwner || doesCellContainFocus(cell);
             cell.setVisible(false);
         }
+
+        // Fix for RT-35876: Rather than have the cells do weird things with
+        // focus (in particular, have focus jump between cells), we return focus
+        // to the VirtualFlow itself.
+        if (wasFocusOwner) {
+            requestFocus();
+        }
+    }
+
+    private boolean doesCellContainFocus(Cell c) {
+        Scene scene = c.getScene();
+        final Node focusOwner = scene == null ? null : scene.getFocusOwner();
+
+        if (focusOwner != null) {
+            if (c.equals(focusOwner)) {
+                return true;
+            }
+
+            Parent p = focusOwner.getParent();
+            while (p != null && ! (p instanceof VirtualFlow)) {
+                if (c.equals(p)) {
+                    return true;
+                }
+                p = p.getParent();
+            }
+        }
+
+        return false;
     }
 
     /**