changeset 6445:b7dbbad9c9bd

RT-36065 [ScrollPane] Focus traversal to the first or last item does not make the ScrollPane to scroll to that item Reviewed by: dgrieve
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 11 Mar 2014 15:48:46 +0100
parents a64b40f8618b
children a4ee872a75bb
files modules/builders/src/main/java/javafx/scene/ParentBuilder.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ScrollPaneSkin.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Algorithm.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/ContainerTabOrder.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Direction.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Hueristic2D.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/ParentTraversalEngine.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/SceneTraversalEngine.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/SubSceneTraversalEngine.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TabOrderHelper.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TopMostTraversalEngine.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TraversalEngine.java modules/graphics/src/main/java/com/sun/javafx/scene/traversal/WeightedClosestCorner.java modules/graphics/src/main/java/javafx/scene/Node.java modules/graphics/src/main/java/javafx/scene/Parent.java modules/graphics/src/main/java/javafx/scene/Scene.java modules/graphics/src/main/java/javafx/scene/SubScene.java modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraversalTest.java modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraverseInvisibleTest.java modules/graphics/src/test/java/javafx/scene/RegistrationTest.java modules/web/src/main/java/com/sun/javafx/scene/web/behavior/HTMLEditorBehavior.java modules/web/src/main/java/com/sun/javafx/scene/web/skin/HTMLEditorSkin.java
diffstat 24 files changed, 606 insertions(+), 626 deletions(-) [+]
line wrap: on
line diff
--- a/modules/builders/src/main/java/javafx/scene/ParentBuilder.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/builders/src/main/java/javafx/scene/ParentBuilder.java	Tue Mar 11 15:48:46 2014 +0100
@@ -42,23 +42,9 @@
     public void applyTo(javafx.scene.Parent x) {
         super.applyTo(x);
         int set = __set;
-        if ((set & (1 << 0)) != 0) x.setImpl_traversalEngine(this.impl_traversalEngine);
         if ((set & (1 << 1)) != 0) x.getStylesheets().addAll(this.stylesheets);
     }
     
-    private com.sun.javafx.scene.traversal.TraversalEngine impl_traversalEngine;
-    /**
-    Set the value of the {@link javafx.scene.Parent#getImpl_traversalEngine() impl_traversalEngine} property for the instance constructed by this builder.
-    @treatAsPrivate
-    @deprecated This is an internal API that is not intended for use and will be removed in the next version
-    */
-    @SuppressWarnings("unchecked") @Deprecated
-    public B impl_traversalEngine(com.sun.javafx.scene.traversal.TraversalEngine x) {
-        this.impl_traversalEngine = x;
-        __set |= 1 << 0;
-        return (B) this;
-    }
-    
     private java.util.Collection<? extends java.lang.String> stylesheets;
     /**
     Add the given items to the List of items in the {@link javafx.scene.Parent#getStylesheets() stylesheets} property for the instance constructed by this builder.
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/MenuBarSkin.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,6 +25,7 @@
 
 package com.sun.javafx.scene.control.skin;
 
+import com.sun.javafx.scene.traversal.ParentTraversalEngine;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.beans.property.ReadOnlyProperty;
@@ -83,8 +84,6 @@
     private Menu openMenu;
     private MenuBarButton openMenuButton;
     private int focusedMenuIndex = -1;
-    private TraversalEngine engine;
-    private Direction direction;
 
     private static WeakHashMap<Stage, Reference<MenuBarSkin>> systemMenuMap;
     private static List<MenuBase> wrappedDefaultMenus = new ArrayList<MenuBase>();
@@ -372,15 +371,10 @@
            acceleratorKeyCombo = KeyCombination.keyCombination("F10");
         }
         getSkinnable().getScene().getAccelerators().put(acceleratorKeyCombo, firstMenuRunnable);
-        engine = new TraversalEngine(getSkinnable(), false) {
-            @Override public boolean trav(Node node, Direction dir) {
-                direction = dir;
-                return super.trav(node,dir);
-            }
-        };
+        ParentTraversalEngine engine = new ParentTraversalEngine(getSkinnable());
         engine.addTraverseListener(this);
         getSkinnable().setImpl_traversalEngine(engine);
-        
+
         control.sceneProperty().addListener(new ChangeListener<Scene>() {
             @Override
             public void changed(ObservableValue<? extends Scene> ov, Scene t, Scene t1) {
@@ -919,13 +913,8 @@
 
     @Override
     public void onTraverse(Node node, Bounds bounds) {
-        if (direction.equals(Direction.NEXT)) {
-            if (openMenu != null) openMenu.hide();
-            focusedMenuIndex = 0;
-            new TraversalEngine(getSkinnable(), false).trav(getSkinnable(), Direction.NEXT);
-        } else if (direction.equals(DOWN)) {
-            // do nothing 
-        }
+        if (openMenu != null) openMenu.hide();
+        focusedMenuIndex = 0;
     }
 
     static class MenuBarButton extends MenuButton {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ScrollPaneSkin.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ScrollPaneSkin.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,6 +25,9 @@
 
 package com.sun.javafx.scene.control.skin;
 
+import com.sun.javafx.scene.traversal.Direction;
+import com.sun.javafx.scene.traversal.ParentTraversalEngine;
+import com.sun.javafx.scene.traversal.TraversalEngine;
 import javafx.animation.Animation.Status;
 import javafx.animation.KeyFrame;
 import javafx.animation.KeyValue;
@@ -51,14 +54,11 @@
 import javafx.scene.input.MouseEvent;
 import javafx.scene.input.ScrollEvent;
 import javafx.scene.input.TouchEvent;
-import javafx.scene.layout.Region;
 import javafx.scene.layout.StackPane;
 import javafx.scene.shape.Rectangle;
 import javafx.util.Duration;
 import com.sun.javafx.Utils;
-import com.sun.javafx.application.PlatformImpl;
 import com.sun.javafx.scene.control.behavior.ScrollPaneBehavior;
-import com.sun.javafx.scene.traversal.TraversalEngine;
 import com.sun.javafx.scene.traversal.TraverseListener;
 import static com.sun.javafx.Utils.*;
 import static com.sun.javafx.scene.control.skin.Utils.*;
@@ -231,7 +231,6 @@
         }
    };
 
-
     private void initialize() {
         // requestLayout calls below should not trigger requestLayout above ScrollPane
 //        setManaged(false);
@@ -239,7 +238,7 @@
         ScrollPane control = getSkinnable();
         scrollNode = control.getContent();
 
-        TraversalEngine traversalEngine = new TraversalEngine(getSkinnable(), false);
+        ParentTraversalEngine traversalEngine = new ParentTraversalEngine(getSkinnable());
         traversalEngine.addTraverseListener(this);
         getSkinnable().setImpl_traversalEngine(traversalEngine);
 
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java	Tue Mar 11 15:48:46 2014 +0100
@@ -29,6 +29,8 @@
 import java.util.Collections;
 import java.util.List;
 
+import com.sun.javafx.scene.traversal.Algorithm;
+import com.sun.javafx.scene.traversal.ParentTraversalEngine;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.value.ChangeListener;
@@ -45,6 +47,7 @@
 import javafx.geometry.Side;
 import javafx.geometry.VPos;
 import javafx.scene.Node;
+import javafx.scene.Parent;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.MenuItem;
 import javafx.scene.control.CustomMenuItem;
@@ -72,7 +75,7 @@
 import com.sun.javafx.scene.traversal.TraverseListener;
 import javafx.css.Styleable;
 
-public class ToolBarSkin extends BehaviorSkinBase<ToolBar, ToolBarBehavior> implements TraverseListener {
+public class ToolBarSkin extends BehaviorSkinBase<ToolBar, ToolBarBehavior> {
 
     private Pane box;
     private ToolBarOverflowMenu overflowMenu;
@@ -83,8 +86,7 @@
     private double savedPrefHeight = 0;
     private ObservableList<MenuItem> overflowMenuItems;
     private boolean needsUpdate = false;
-    private TraversalEngine engine;
-    private Direction direction;
+    private final ParentTraversalEngine engine;
 
     public ToolBarSkin(ToolBar toolbar) {
         super(toolbar, new ToolBarBehavior(toolbar));
@@ -92,22 +94,74 @@
         initialize();
         registerChangeListener(toolbar.orientationProperty(), "ORIENTATION");
 
-        engine = new TraversalEngine(getSkinnable(), false) {
-            @Override public boolean trav(Node owner, Direction dir) {
-                // This allows the right arrow to select the overflow menu
-                // without it only the tab key can select the overflow menu.
+        engine = new ParentTraversalEngine(getSkinnable(), new Algorithm() {
+
+
+            @Override
+            public Node select(Node owner, Direction dir, TraversalEngine engine) {
+                final ObservableList<Node> boxChildren = box.getChildren();
+                if (owner == overflowMenu) {
+                    if (dir.isForward(overflowMenu.getEffectiveNodeOrientation())) {
+                        return null;
+                    } else {
+                        for (int i = boxChildren.size() - 1; i >= 0; --i) {
+                            Node n = box.getChildren().get(i);
+                            if (n.isFocusTraversable() && !n.isDisabled() && n.impl_isTreeVisible()) {
+                                return n;
+                            }
+                        }
+                    }
+                }
+                int idx = boxChildren.indexOf(owner);
+                if (dir.isForward(overflowMenu.getEffectiveNodeOrientation())) {
+                    for (int i = idx + 1; i < boxChildren.size(); ++i) {
+                        Node n = box.getChildren().get(i);
+                        if (n.isFocusTraversable() && !n.isDisabled() && n.impl_isTreeVisible()) {
+                            return n;
+                        }
+                    }
+                    if (overflow) {
+                        overflowMenu.requestFocus();
+                        return overflowMenu;
+                    }
+                } else {
+                    for (int i = idx - 1; i >= 0; --i) {
+                        Node n = box.getChildren().get(i);
+                        if (n.isFocusTraversable() && !n.isDisabled() && n.impl_isTreeVisible()) {
+                            return n;
+                        }
+                    }
+                }
+                return null;
+            }
+
+            @Override
+            public Node selectFirst(TraversalEngine engine) {
+                final ObservableList<Node> boxChildren = box.getChildren();
+                for (int i = 0; i < boxChildren.size(); ++i) {
+                    Node n = box.getChildren().get(i);
+                    if (n.isFocusTraversable() && !n.isDisabled() && n.impl_isTreeVisible()) {
+                        return n;
+                    }
+                }
+                return null;
+            }
+
+            @Override
+            public Node selectLast(TraversalEngine engine) {
                 if (overflow) {
-                    engine.reg(overflowMenu);
+                    return overflowMenu;
                 }
-                direction = dir;
-                boolean result = super.trav(owner, dir);
-                if (overflow) {
-                    engine.unreg(overflowMenu);
+                final ObservableList<Node> boxChildren = box.getChildren();
+                for (int i = boxChildren.size() - 1; i >= 0; --i) {
+                    Node n = box.getChildren().get(i);
+                    if (n.isFocusTraversable() && !n.isDisabled() && n.impl_isTreeVisible()) {
+                        return n;
+                    }
                 }
-                return result;
+                return null;
             }
-        };
-        engine.addTraverseListener(this);
+        });
         getSkinnable().setImpl_traversalEngine(engine);
 
         toolbar.focusedProperty().addListener(new ChangeListener<Boolean>() {
@@ -457,7 +511,10 @@
             } else {
                 if (node.isFocused()) {
                     if (!box.getChildren().isEmpty()) {
-                        engine.registeredNodes.get(engine.registeredNodes.size() - 1).requestFocus();
+                        Node last = engine.selectLast();
+                        if (last != null) {
+                            last.requestFocus();
+                        }
                     } else {
                         overflowMenu.requestFocus();                        
                     }
@@ -473,22 +530,15 @@
         // Check if we overflowed.
         overflow = overflowMenuItems.size() > 0;
         if (!overflow && overflowMenu.isFocused()) {
-            engine.registeredNodes.get(engine.registeredNodes.size() - 1).requestFocus();
+            Node last = engine.selectLast();
+            if (last != null) {
+                last.requestFocus();
+            }
         }
         overflowMenu.setVisible(overflow);
         overflowMenu.setManaged(overflow);
     }
 
-    @Override
-    public void onTraverse(Node node, Bounds bounds) {
-        int index = engine.registeredNodes.indexOf(node);
-        if (index == -1 && direction.equals(Direction.NEXT)) {
-            if (overflow) {
-                overflowMenu.requestFocus();
-            }
-        }
-    }
-
     class ToolBarOverflowMenu extends StackPane {
         private StackPane downArrow;
         private ContextMenu popup;
@@ -496,6 +546,7 @@
 
         public ToolBarOverflowMenu(ObservableList<MenuItem> items) {
             getStyleClass().setAll("tool-bar-overflow-button");
+            setFocusTraversable(true);
             this.menuItems = items;
             downArrow = new StackPane();
             downArrow.getStyleClass().setAll("arrow");
@@ -519,10 +570,12 @@
                             popup.getItems().addAll(menuItems);
                             popup.show(downArrow, Side.BOTTOM, 0, 0);
                         }
+                        ke.consume();
                     } else if (KeyCode.ESCAPE.equals(ke.getCode())) {
                         if (popup.isShowing()) {
                             popup.hide();
                         }
+                        ke.consume();
                     } else if (KeyCode.ENTER.equals(ke.getCode())) {
                         if (popup.isShowing()) {
                             popup.hide();
@@ -531,35 +584,8 @@
                             popup.getItems().addAll(menuItems);
                             popup.show(downArrow, Side.BOTTOM, 0, 0);
                         }
-                    } else {
-                        boolean isRTL = getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT;
-                        boolean leftAction = KeyCode.LEFT.equals(ke.getCode());
-                        boolean rightAction = KeyCode.RIGHT.equals(ke.getCode()) || KeyCode.TAB.equals(ke.getCode());
-                        if (isRTL) {
-                            boolean swap = leftAction;
-                            leftAction = rightAction;
-                            rightAction = swap;
-                        }
-                        if (KeyCode.UP.equals(ke.getCode()) || leftAction ||
-                            (KeyCode.TAB.equals(ke.getCode()) && ke.isShiftDown())) {
-                            if (engine.registeredNodes.isEmpty()) {
-                                return;
-                            }
-                            int index = box.getChildren().indexOf(engine.registeredNodes.get(engine.registeredNodes.size() - 1));
-                            if (index != -1) {
-                                box.getChildren().get(index).requestFocus();                            
-                            } else {
-                                if (!box.getChildren().isEmpty()) {
-                                    box.getChildren().get(0).requestFocus();
-                                } else {
-                                    new TraversalEngine(getSkinnable(), false).trav(getSkinnable(), Direction.PREVIOUS);
-                                }
-                            }
-                        } else if (KeyCode.DOWN.equals(ke.getCode()) || rightAction) {                        
-                            new TraversalEngine(getSkinnable(), false).trav(getSkinnable(), Direction.NEXT);
-                        }
+                        ke.consume();
                     }
-                    ke.consume();
                 }
             });
 
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Algorithm.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Algorithm.java	Tue Mar 11 15:48:46 2014 +0100
@@ -34,6 +34,10 @@
      * Traverse from origin, in direction dir.
      * Return a the new target Node or null if no suitable target is found.
      */
-    public Node traverse(Node owner, Direction dir, TraversalEngine engine);
+    public Node select(Node owner, Direction dir, TraversalEngine engine);
+
+    public Node selectFirst(TraversalEngine engine);
+
+    public Node selectLast(TraversalEngine engine);
     
 }
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/ContainerTabOrder.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/ContainerTabOrder.java	Tue Mar 11 15:48:46 2014 +0100
@@ -38,19 +38,11 @@
 
 public class ContainerTabOrder implements Algorithm {
 
-    PlatformLogger focusLogger;
-
     ContainerTabOrder() {
-        focusLogger = Logging.getFocusLogger();
     }
 
-    public Node traverse(Node node, Direction dir, TraversalEngine engine) {
+    public Node select(Node node, Direction dir, TraversalEngine engine) {
         Node newNode = null;
-
-        if (focusLogger.isLoggable(Level.FINER)) {
-            focusLogger.finer("old focus owner : "+node+", bounds : "+engine.getBounds(node));
-        }
-
         if (NEXT.equals(dir)) {
             newNode = TabOrderHelper.findNextFocusablePeer(node);
         }
@@ -59,37 +51,34 @@
         }
         else if (UP.equals(dir) || DOWN.equals(dir) || LEFT.equals(dir) || RIGHT.equals(dir) ) {
             List<Node> nodes = engine.getAllTargetNodes();
-            List<Bounds> bounds = engine.getTargetBounds(nodes);
 
-            int target = trav2D(engine.getBounds(node), dir, bounds);
+            int target = trav2D(engine.getSceneLayoutBounds(node), dir, nodes, engine);
             if (target != -1) {
                 newNode = nodes.get(target);
             }
-            nodes.clear();
-            bounds.clear();
-
-        }
-
-        if (focusLogger.isLoggable(Level.FINER)) {
-            if (newNode != null) {
-                focusLogger.finer("new focus owner : "+newNode+", bounds : "+engine.getBounds(newNode));
-            }
-            else {
-                focusLogger.finer("no focus transfer");
-            }
         }
 
         return newNode;
     }
 
-    private int trav2D(Bounds origin, Direction dir, List<Bounds> targets) {
+    @Override
+    public Node selectFirst(TraversalEngine engine) {
+        return TabOrderHelper.getFirstTargetNode(engine.getRoot());
+    }
+
+    @Override
+    public Node selectLast(TraversalEngine engine) {
+        return TabOrderHelper.getLastTargetNode(engine.getRoot());
+    }
+
+    private int trav2D(Bounds origin, Direction dir, List<Node> peers, TraversalEngine engine) {
 
         Bounds bestBounds = null;
         double bestMetric = 0.0;
         int bestIndex = -1;
 
-        for (int i = 0; i < targets.size(); i++) {
-            final Bounds targetBounds = targets.get(i);
+        for (int i = 0; i < peers.size(); i++) {
+            final Bounds targetBounds = engine.getSceneLayoutBounds(peers.get(i));
             final double outd = outDistance(dir, origin, targetBounds);
             final double metric;
 
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Direction.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Direction.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,13 +25,36 @@
 
 package com.sun.javafx.scene.traversal;
 
+import javafx.geometry.NodeOrientation;
+
 public enum Direction {
     
-    UP,
-    DOWN,
-    LEFT,
-    RIGHT,
-    NEXT,
-    PREVIOUS
-    
+    UP(false),
+    DOWN(true),
+    LEFT(false),
+    RIGHT(true),
+    NEXT(true),
+    PREVIOUS(false);
+    private final boolean forward;
+
+    Direction(boolean forward) {
+        this.forward = forward;
+    }
+
+    public boolean isForward() {
+        return forward;
+    }
+
+    public boolean isForward(NodeOrientation orientation) {
+        switch(this) {
+            case LEFT:
+            case RIGHT:
+            case NEXT:
+            case PREVIOUS:
+                return forward ^ (orientation == NodeOrientation.RIGHT_TO_LEFT);
+            default:
+                return forward;
+        }
+
+    }
 }
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Hueristic2D.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/Hueristic2D.java	Tue Mar 11 15:48:46 2014 +0100
@@ -44,22 +44,15 @@
 
 public class Hueristic2D implements Algorithm {
 
-    PlatformLogger focusLogger;
-
     Hueristic2D() {
-        focusLogger = Logging.getFocusLogger();
     }
 
     @Override
-    public Node traverse(Node node, Direction dir, TraversalEngine engine) {
+    public Node select(Node node, Direction dir, TraversalEngine engine) {
         Node newNode = null;
 
         cacheTraversal(node, dir, engine);
 
-        if (focusLogger.isLoggable(Level.FINER)) {
-            focusLogger.finer("old focus owner : "+node+", bounds : "+engine.getBounds(node));
-        }
-
         if (NEXT.equals(dir)) {
             newNode = TabOrderHelper.findNextFocusablePeer(node);
         }
@@ -99,15 +92,6 @@
             }
         }
 
-        if (focusLogger.isLoggable(Level.FINER)) {
-            if (newNode != null) {
-                focusLogger.finer("new focus owner : "+newNode+", bounds : "+engine.getBounds(newNode));
-            }
-            else {
-                focusLogger.finer("no focus transfer");
-            }
-        }
-
         /*
         ** newNode will be null if there are no
         ** possible targets in the direction.
@@ -122,6 +106,16 @@
         return newNode;
     }
 
+    @Override
+    public Node selectFirst(TraversalEngine engine) {
+        return TabOrderHelper.getFirstTargetNode(engine.getRoot());
+    }
+
+    @Override
+    public Node selectLast(TraversalEngine engine) {
+        return TabOrderHelper.getLastTargetNode(engine.getRoot());
+    }
+
     private boolean isOnAxis(Direction dir, Bounds cur, Bounds tgt) {
 
         final double cmin, cmax, tmin, tmax;
@@ -474,30 +468,6 @@
             nearestNodeAverage.originLeftCornerDistance = originLeftCorner2D.distance(nearestNodeAverage.bounds.getMinX(), ySideInOpositeDirection.apply(nearestNodeAverage.bounds));
         }
 
-        if (focusLogger.isLoggable(Level.FINER)) {
-            if (nearestNodeOriginSimple2D != null) {
-                focusLogger.finer("nearestNodeOriginSimple2D.node : "+nearestNodeOriginSimple2D.node);
-            }
-            if (nearestNodeCurrentSimple2D != null) {
-                focusLogger.finer("nearestNodeCurrentSimple2D.node : "+nearestNodeCurrentSimple2D.node);
-            }
-            if (nearestNodeOnOriginX != null) {
-                focusLogger.finer("nearestNodeOnOriginX.node : "+nearestNodeOnOriginX.node);
-            }
-            if (nearestNodeOnCurrentX != null) {
-                focusLogger.finer("nearestNodeOnCurrentX.node : "+nearestNodeOnCurrentX.node);
-            }
-            if (nearestNodeAverage != null) {
-                focusLogger.finer("nearestNodeAverageUp.node : "+nearestNodeAverage.node);
-            }
-            if (nearestNodeLeft != null) {
-                focusLogger.finer("nearestNodeTopLeft.node : "+nearestNodeLeft.node);
-            }
-            if (nearestNodeAnythingAnywhere != null) {
-                focusLogger.finer("nearestNodeAnythingAnywhereUp.node : "+nearestNodeAnythingAnywhere.node);
-            }
-        }
-
         if (nearestNodeOnOriginX != null) {
             /*
             ** there's a preference, all else being equal, to return nearestNodeOnOriginX
@@ -805,30 +775,6 @@
             traversalNodeStack.clear();
         }
 
-        if (focusLogger.isLoggable(Level.FINER)) {
-            if (nearestNodeOriginSimple2D != null) {
-                focusLogger.finer("nearestNodeOriginSimple2D.node : "+nearestNodeOriginSimple2D.node);
-            }
-            if (nearestNodeCurrentSimple2D != null) {
-                focusLogger.finer("nearestNodeCurrentSimple2D.node : "+nearestNodeCurrentSimple2D.node);
-            }
-            if (nearestNodeOnOriginY != null) {
-                focusLogger.finer("nearestNodeOnOriginY.node : "+nearestNodeOnOriginY.node);
-            }
-            if (nearestNodeOnCurrentY != null) {
-                focusLogger.finer("nearestNodeOnCurrentY.node : "+nearestNodeOnCurrentY.node);
-            }
-            if (nearestNodeAverage != null) {
-                focusLogger.finer("nearestNodeAverageLeft.node : "+nearestNodeAverage.node);
-            }
-            if (nearestNodeTopLeft != null) {
-                focusLogger.finer("nearestNodeTopLeft.node : "+nearestNodeTopLeft.node);
-            }
-            if (nearestNodeAnythingAnywhereLeft != null) {
-                focusLogger.finer("nearestNodeAnythingAnywhereLeft.node : "+nearestNodeAnythingAnywhereLeft.node);
-            }
-        }
-
         if (nearestNodeOnOriginY != null) {
             /*
              ** there's a preference, all else being equal, to return nearestNodeOnOriginY
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/ParentTraversalEngine.java	Tue Mar 11 15:48:46 2014 +0100
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011, 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.scene.traversal;
+
+import javafx.scene.Parent;
+
+public final class ParentTraversalEngine extends TraversalEngine{
+
+    private final Parent root;
+
+    public ParentTraversalEngine(Parent root, Algorithm algorithm) {
+        super(algorithm);
+        this.root = root;
+    }
+
+    public ParentTraversalEngine(Parent root) {
+        super();
+        this.root = root;
+    }
+
+    @Override
+    protected Parent getRoot() {
+        return root;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/SceneTraversalEngine.java	Tue Mar 11 15:48:46 2014 +0100
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.scene.traversal;
+
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+
+public final class SceneTraversalEngine extends TopMostTraversalEngine{
+
+    private final Scene scene;
+
+    public SceneTraversalEngine(Scene scene) {
+        this.scene = scene;
+    }
+
+    protected Parent getRoot() {
+        return scene.getRoot();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/SubSceneTraversalEngine.java	Tue Mar 11 15:48:46 2014 +0100
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2011, 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.scene.traversal;
+
+import javafx.scene.Parent;
+import javafx.scene.SubScene;
+
+public final class SubSceneTraversalEngine extends TopMostTraversalEngine{
+
+    private final SubScene subScene;
+
+    public SubSceneTraversalEngine(SubScene scene) {
+        this.subScene = scene;
+    }
+
+    protected Parent getRoot() {
+        return subScene.getRoot();
+    }
+}
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TabOrderHelper.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TabOrderHelper.java	Tue Mar 11 15:48:46 2014 +0100
@@ -33,35 +33,39 @@
 import java.util.List;
 
 final class TabOrderHelper {
-    static Node findPreviousFocusableInList(List<Node> nodeList, int startIndex) {
-        Node newNode = null;
-
+    private static Node findPreviousFocusableInList(List<Node> nodeList, int startIndex) {
         for (int i = startIndex ; i >= 0 ; i--) {
             Node prevNode = nodeList.get(i);
             if (isDisabledOrInvisible(prevNode)) continue;
-
             if (prevNode instanceof javafx.scene.Parent) {
-                List<Node> prevNodesList = ((Parent)prevNode).getChildrenUnmodifiable();
-                if (prevNodesList.size() > 0) {
-                    newNode = findPreviousFocusableInList(prevNodesList, prevNodesList.size()-1);
-                    if (newNode != null) {
-                        break;
+                final ParentTraversalEngine impl_traversalEngine = ((Parent)prevNode).getImpl_traversalEngine();
+                if (impl_traversalEngine!= null && impl_traversalEngine.canTraverse()) {
+                    Node selected = impl_traversalEngine.selectLast();
+                    if (selected != null) {
+                        return selected;
+                    }
+                } else {
+                    List<Node> prevNodesList = ((Parent)prevNode).getChildrenUnmodifiable();
+                    if (prevNodesList.size() > 0) {
+                        Node newNode = findPreviousFocusableInList(prevNodesList, prevNodesList.size()-1);
+                        if (newNode != null) {
+                            return newNode;
+                        }
                     }
                 }
             }
             if (prevNode.isFocusTraversable()) {
-                newNode = prevNode;
-                break;
+                return prevNode;
             }
         }
-        return newNode;
+        return null;
     }
 
     private static boolean isDisabledOrInvisible(Node prevNode) {
         return prevNode.isDisabled() || !prevNode.impl_isTreeVisible();
     }
 
-    static Node findPreviousFocusablePeer(Node node) {
+    public static Node findPreviousFocusablePeer(Node node) {
         Node startNode = node;
         Node newNode = null;
         List<Node> parentNodes = findPeers(startNode);
@@ -103,21 +107,17 @@
 
         // None of the ancestor siblings is traversable, so start from the last traversable item
         if (newNode == null) {
-            Parent parent = null;
             Parent p1 = node.getParent();
-            while (p1 != null) {
-                parent = p1;
+            while (p1 != null && p1.getParent() != null) {
                 p1 = p1.getParent();
             }
-
-            parentNodes = parent.getChildrenUnmodifiable();
-            newNode = findPreviousFocusableInList(parentNodes, parentNodes.size() - 1);
+            newNode =  getLastTargetNode(p1);
         }
 
         return newNode;
     }
 
-    static List<Node> findPeers(Node node) {
+    private static List<Node> findPeers(Node node) {
         List<Node> parentNodes = null;
         Parent parent = node.getParent();
         /*
@@ -129,31 +129,37 @@
         return parentNodes;
     }
 
-    static Node findNextFocusableInList(List<Node> nodeList, int startIndex) {
-        Node newNode = null;
-
+    private static Node findNextFocusableInList(List<Node> nodeList, int startIndex) {
         for (int i = startIndex ; i < nodeList.size() ; i++) {
-
             Node nextNode = nodeList.get(i);
             if (isDisabledOrInvisible(nextNode)) continue;
             if (nextNode.isFocusTraversable()) {
-                newNode = nextNode;
-                break;
+                return nextNode;
             }
             else if (nextNode instanceof Parent) {
+                final ParentTraversalEngine impl_traversalEngine = ((Parent)nextNode).getImpl_traversalEngine();
+                if (impl_traversalEngine!= null && impl_traversalEngine.canTraverse()) {
+                    Node selected = impl_traversalEngine.selectFirst();
+                    if (selected != null) {
+                        return selected;
+                    } else {
+                        // If the Parent has it's own engine, but no selection can be done, skip it
+                        continue;
+                    }
+                }
                 List<Node> nextNodesList = ((Parent)nextNode).getChildrenUnmodifiable();
                 if (nextNodesList.size() > 0) {
-                    newNode = findNextFocusableInList(nextNodesList, 0);
+                    Node newNode = findNextFocusableInList(nextNodesList, 0);
                     if (newNode != null) {
-                        break;
+                        return newNode;
                     }
                 }
             }
         }
-        return newNode;
+        return null;
     }
 
-    static Node findNextFocusablePeer(Node node) {
+    public static Node findNextFocusablePeer(Node node) {
         Node startNode = node;
         Node newNode = null;
 
@@ -162,7 +168,7 @@
             newNode = findNextFocusableInList(((Parent)node).getChildrenUnmodifiable(), 0);
         }
 
-        // Next step is to traverse the siblings "to the right"
+        // Next step is to select the siblings "to the right"
         if (newNode == null) {
             List<Node> parentNodes = findPeers(startNode);
             if (parentNodes == null) {
@@ -195,16 +201,60 @@
 
         // None of the ancestors siblings is traversable, so find the first traversable Node from the root
         if (newNode == null) {
-            Parent parent = null;
             Parent p1 = node.getParent();
-            while (p1 != null) {
-                parent = p1;
+            while (p1 != null && p1.getParent() != null) {
                 p1 = p1.getParent();
             }
-            List<Node> parentNodes = parent.getChildrenUnmodifiable();
-            newNode = findNextFocusableInList(parentNodes, 0);
+            newNode = getFirstTargetNode(p1);
         }
 
         return newNode;
     }
+
+    public static Node getFirstTargetNode(Parent p) {
+        if (p == null || isDisabledOrInvisible(p)) return null;
+        final ParentTraversalEngine impl_traversalEngine = p.getImpl_traversalEngine();
+        if (impl_traversalEngine!= null && impl_traversalEngine.canTraverse()) {
+            Node selected = impl_traversalEngine.selectFirst();
+            if (selected != null) {
+                return selected;
+            }
+        }
+        List<Node> parentsNodes = p.getChildrenUnmodifiable();
+        for (Node n : parentsNodes) {
+            if (isDisabledOrInvisible(n)) continue;;
+            if (n.isFocusTraversable()) {
+                return n;
+            }
+            if (n instanceof Parent) {
+                Node result = getFirstTargetNode((Parent)n);
+                if (result != null) return result;
+            }
+        }
+        return null;
+    }
+
+    public static Node getLastTargetNode(Parent p) {
+        if (p == null || isDisabledOrInvisible(p)) return null;
+        final ParentTraversalEngine impl_traversalEngine = p.getImpl_traversalEngine();
+        if (impl_traversalEngine!= null && impl_traversalEngine.canTraverse()) {
+            Node selected = impl_traversalEngine.selectLast();
+            if (selected != null) {
+                return selected;
+            }
+        }
+        List<Node> parentsNodes = p.getChildrenUnmodifiable();
+        for (int i = parentsNodes.size() - 1; i >= 0; --i) {
+            Node n = parentsNodes.get(i);
+            if (isDisabledOrInvisible(n)) continue;
+            if (n instanceof Parent) {
+                Node result = getLastTargetNode((Parent) n);
+                if (result != null) return result;
+            }
+            if (n.isFocusTraversable() && n.impl_isTreeVisible() && !n.isDisabled()) {
+                return n;
+            }
+        }
+        return null;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TopMostTraversalEngine.java	Tue Mar 11 15:48:46 2014 +0100
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2011, 2014, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.scene.traversal;
+
+import com.sun.javafx.application.PlatformImpl;
+import javafx.scene.Node;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+
+public abstract class TopMostTraversalEngine extends TraversalEngine{
+
+    protected TopMostTraversalEngine() {
+        /*
+         * for 2d behaviour from TAB use :
+         *    algorithm = new WeightedClosestCorner();
+         * for Container sequence TAB behaviour and 2d arrow behaviour use :
+         *    algorithm = new ContainerTabOrder();
+         * for 2D arrow behaviour with a target bias and a stack use :
+         *    algorithm = new Biased2DWithStack();
+         */
+        super(PlatformImpl.isContextual2DNavigation() ? new Hueristic2D() : new ContainerTabOrder());
+    }
+
+    public final Node trav(Node node, Direction dir) {
+        Node newNode = null;
+        Parent p = node.getParent();
+        Node traverseNode = node;
+        while (p != null) {
+            ParentTraversalEngine engine = p.getImpl_traversalEngine();
+            if (engine != null && engine.canTraverse()) {
+                newNode = engine.select(node, dir);
+                if (newNode != null) {
+                    break;
+                } else {
+                    // The inner traversal engine wasn't able to select anything in the specified direction.
+                    // So now we try to traverse from the whole parent (associated with that traversal engine)
+                    // by a traversal engine that's higher in the hierarchy
+                    traverseNode = dir.isForward() ? engine.selectLast() : p;
+                }
+            }
+            p = p.getParent();
+        }
+        if (newNode == null) {
+            newNode = algorithm.select(traverseNode, dir, this);
+        }
+        if (newNode != null) {
+            focusAndNotify(newNode);
+        }
+        return newNode;
+    }
+
+    private void focusAndNotify(Node newNode) {
+        newNode.requestFocus();
+        notifyTreeTraversedTo(newNode);
+    }
+
+    private void notifyTreeTraversedTo(Node newNode) {
+        Parent p = newNode.getParent();
+        while (p != null) {
+            final ParentTraversalEngine impl_traversalEngine = p.getImpl_traversalEngine();
+            if (impl_traversalEngine != null) {
+                impl_traversalEngine.notifyTraversedTo(newNode);
+            }
+            p = p.getParent();
+        }
+        notifyTraversedTo(newNode);
+    }
+
+    public final Node traverseToFirst() {
+        Node n = algorithm.selectFirst(this);
+        if (n != null) focusAndNotify(n);
+        return n;
+    }
+
+
+    public final Node traverseToLast() {
+        Node n = algorithm.selectLast(this);
+        if (n != null) focusAndNotify(n);
+        return n;
+    }
+}
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TraversalEngine.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/TraversalEngine.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,162 +25,62 @@
 
 package com.sun.javafx.scene.traversal;
 
-import javafx.application.ConditionalFeature;
 import javafx.geometry.BoundingBox;
 import javafx.geometry.Bounds;
-import javafx.geometry.Point2D;
 import javafx.scene.Node;
 import javafx.scene.Parent;
-import javafx.scene.Scene;
+
 import java.util.ArrayList;
-import java.util.LinkedList;
 import java.util.List;
-import com.sun.javafx.Logging;
-import com.sun.javafx.application.PlatformImpl;
-import sun.util.logging.PlatformLogger;
-import sun.util.logging.PlatformLogger.Level;
 
-public class TraversalEngine {
+public abstract class TraversalEngine {
 
-    private final Algorithm algorithm;
+    protected final Algorithm algorithm;
 
-    private final Parent root;
+    private final Bounds initialBounds =  new BoundingBox(0, 0, 1, 1);
+    final ArrayList<TraverseListener> listeners = new ArrayList<>();
 
-    private final boolean isScene;
-
-    private final Bounds initialBounds;
-
-    public final List<Node> registeredNodes;
-
-    private final List<TraverseListener> listeners;
-
-    PlatformLogger focusLogger;
-
-    protected boolean isScene() {
-        return isScene;
-    }
-    protected Parent getRoot() {
-        return root;
+    protected TraversalEngine(Algorithm algorithm) {
+        this.algorithm = algorithm;
     }
 
-    public TraversalEngine(Parent root, boolean isScene) {
-        this.root = root;
-        this.isScene = isScene;
-        /*
-         * for 2d behaviour from TAB use :
-         *    algorithm = new WeightedClosestCorner();
-         * for Container sequence TAB behaviour and 2d arrow behaviour use :
-         *    algorithm = new ContainerTabOrder();
-         * for 2D arrow behaviour with a target bias and a stack use :
-         *    algorithm = new Biased2DWithStack();
-         */
-        if (PlatformImpl.isContextual2DNavigation()) {
-            algorithm = new Hueristic2D();
-        }
-        else {
-            algorithm = new ContainerTabOrder();
-        }
+    protected TraversalEngine() {
+        this.algorithm = null;
+    }
 
-        initialBounds = new BoundingBox(0, 0, 1, 1);
-        registeredNodes = new ArrayList<Node>();
-        listeners = new LinkedList<TraverseListener>();
-        focusLogger = Logging.getFocusLogger();
-        if (focusLogger.isLoggable(Level.FINER)) {
-            focusLogger.finer("TraversalEngine constructor");
+    public final void addTraverseListener(TraverseListener listener) {
+        listeners.add(listener);
+    }
+
+    void notifyTraversedTo(Node newNode) {
+        for (TraverseListener l : listeners) {
+            l.onTraverse(newNode, getLayoutBounds(newNode, getRoot()));
         }
     }
 
-    public void addTraverseListener(TraverseListener listener) {
-        listeners.add(listener);
+    public final Node select(Node from, Direction dir) {
+        return algorithm.select(from, dir, this);
     }
 
-    public void removeTraverseListener(TraverseListener listener) {
-        listeners.remove(listener);
+    public final Node selectFirst() {
+        return algorithm.selectFirst(this);
     }
 
-    public void reg(Node n) {
-        registeredNodes.add(n);
+    public final Node selectLast() {
+        return algorithm.selectLast(this);
     }
 
-    public void unreg(Node n) {
-        registeredNodes.remove(n);
+    // get all focusable nodes in tree...
+    public final List<Node> getAllTargetNodes() {
+        final List<Node> targetNodes = new ArrayList<>();
+        addFocusableChildrenToList(targetNodes, getRoot());
+        return targetNodes;
     }
 
-    public boolean trav(Node owner, Direction dir) {
-        Node newNode = algorithm.traverse(owner, dir, this);
-        if (newNode == null) {
-            if (focusLogger.isLoggable(Level.FINE)) {
-                focusLogger.fine("new node is null, focus not moved");
-            }
-            return false;
-        } else {
-            if (focusLogger.isLoggable(Level.FINER)) {
-                focusLogger.finer("new focus owner : "+newNode);
-            }
-            newNode.requestFocus();
-            for (TraverseListener listener : listeners) {
-                listener.onTraverse(newNode, getBounds(newNode));
-            }
-            return true;
-        }
-    }
-
-    public int getTopLeftFocusableNode() {
-        List<Node> nodes = getAllTargetNodes();
-        final int target = 0;
-        Point2D zeroZero = new Point2D(0,0);
-
-        if (nodes.size() > 0) {
-            int nodeIndex;
-            Node nearestNode = nodes.get(0);
-            double nearestDistance = zeroZero.distance(getBounds(nodes.get(0)).getMinX(), getBounds(nodes.get(0)).getMinY());
-            double distance;
-
-            for (nodeIndex = 1; nodeIndex < nodes.size(); nodeIndex++) {
-
-                if (focusLogger.isLoggable(Level.FINEST)) {
-                    focusLogger.finest("getTopLeftFocusableNode(), distance : "+zeroZero.distance(getBounds(nodes.get(nodeIndex)).getMinX(), getBounds(nodes.get(nodeIndex)).getMinY())+" to  : "+nodes.get(nodeIndex)+". @ : "+getBounds(nodes.get(nodeIndex)).getMinX()+":"+getBounds(nodes.get(nodeIndex)).getMinY());
-                }
-                distance = zeroZero.distance(getBounds(nodes.get(nodeIndex)).getMinX(), getBounds(nodes.get(nodeIndex)).getMinY());
-                if (nearestDistance > distance) {
-                    nearestDistance = distance;
-                    nearestNode = nodes.get(nodeIndex);
-                }
-
-            }
-            if (focusLogger.isLoggable(Level.FINER)) {
-                focusLogger.finer("getTopLeftFocusableNode(), nearest  : "+nearestNode+", at : "+nearestDistance);
-            }
-
-            nearestNode.requestFocus();
-            for (TraverseListener listener : listeners) {
-                listener.onTraverse(nearestNode, getBounds(nearestNode));
-            }
-
-        }
-        nodes.clear();
-
-        return target;
-    }
-
-
-    // get all focusable nodes in tree...
-    protected List<Node> getAllTargetNodes() {
-        final List<Node> targetNodes = new ArrayList<Node>();
-
-        /*
-        ** get top level container
-        */
-        Scene s = root.getScene();
-
-        addFocusableChildrenToList(targetNodes, s.getRoot());
-        return targetNodes;
-    }
     private void addFocusableChildrenToList(List<Node> list, Parent parent) {
         List<Node> parentsNodes = parent.getChildrenUnmodifiable();
         for (Node n : parentsNodes) {
             if (n.isFocusTraversable() && !n.isFocused() && n.impl_isTreeVisible() && !n.isDisabled()) {
-
                 list.add(n);
             }
             if (n instanceof Parent) {
@@ -189,41 +89,27 @@
         }
     }
 
-    /**
-     * Returns nodes to be processed.
-     */
-    protected List<Node> getContainerTargetNodes() {
-        final List<Node> targetNodes = new ArrayList<Node>();
-        for (Node n : registeredNodes) {
-            if (!n.isFocused() && n.impl_isTreeVisible() && !n.isDisabled()) {
-                targetNodes.add(n);
-            }
-        }
-        return targetNodes;
+    protected abstract Parent getRoot();
+
+    public final Bounds getSceneLayoutBounds(Node n) {
+        return getLayoutBounds(n, null);
     }
 
-    /**
-     * Gets a list of bounds for a list of nodes.
-     */
-    protected List<Bounds> getTargetBounds(List<Node> nodes) {
-        final List<Bounds> targetBounds = new ArrayList<Bounds>();
-        for (Node n : nodes) {
-            targetBounds.add(getBounds(n));
-        }
-        return targetBounds;
+    public final boolean canTraverse() {
+        return algorithm != null;
     }
 
     /**
      * Gets the appropriate bounds for the given node, transformed into
      * the scene's or the traversal root's coordinates.
      */
-    protected Bounds getBounds(Node n) {
+    private Bounds getLayoutBounds(Node n, Parent forParent) {
         final Bounds bounds;
         if (n != null) {
-            if (isScene) {
+            if (forParent == null) {
                 bounds = n.localToScene(n.getLayoutBounds());
             } else {
-                bounds = root.sceneToLocal(n.localToScene(n.getLayoutBounds()));
+                bounds = forParent.sceneToLocal(n.localToScene(n.getLayoutBounds()));
             }
         } else {
             bounds = initialBounds;
--- a/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/WeightedClosestCorner.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/scene/traversal/WeightedClosestCorner.java	Tue Mar 11 15:48:46 2014 +0100
@@ -27,6 +27,7 @@
 
 import java.util.List;
 import javafx.geometry.Bounds;
+import javafx.geometry.Point2D;
 import javafx.scene.Node;
 import com.sun.javafx.Logging;
 import sun.util.logging.PlatformLogger;
@@ -59,10 +60,8 @@
 
 public class WeightedClosestCorner implements Algorithm {
 
-    PlatformLogger focusLogger;
 
     WeightedClosestCorner() {
-        focusLogger = Logging.getFocusLogger();
     }
 
     private boolean isOnAxis(Direction dir, Bounds cur, Bounds tgt) {
@@ -164,55 +163,69 @@
         return distance;
     }
 
-    public Node traverse(Node node, Direction dir, TraversalEngine engine) {
+    public Node select(Node node, Direction dir, TraversalEngine engine) {
         Node newNode = null;
         List<Node> nodes = engine.getAllTargetNodes();
-        List<Bounds> bounds = engine.getTargetBounds(nodes);
 
-        if (focusLogger.isLoggable(Level.FINER)) {
-            focusLogger.finer("old focus owner : "+node+", bounds : "+engine.getBounds(node));
-        }
-
-        int target = traverse(engine.getBounds(node), dir, bounds);
+        int target = traverse(engine.getSceneLayoutBounds(node), dir, nodes, engine);
         if (target != -1) {
             newNode = nodes.get(target);
-            if (focusLogger.isLoggable(Level.FINER)) {
-                focusLogger.finer("new focus owner : "+newNode+", bounds : "+engine.getBounds(newNode));
-            }
         }
-        else {
-            if (focusLogger.isLoggable(Level.FINER)) {
-                focusLogger.finer("no focus transfer");
-            }
-        }
-
-        nodes.clear();
-        bounds.clear();
 
         return newNode;
     }
 
-    public int traverse(Bounds origin, Direction dir, List<Bounds> targets) {
+    @Override
+    public Node selectFirst(TraversalEngine engine) {
+        List<Node> nodes = engine.getAllTargetNodes();
+        Point2D zeroZero = new Point2D(0,0);
+
+        if (nodes.size() > 0) {
+            int nodeIndex;
+            Node nearestNode = nodes.get(0);
+            double nearestDistance = zeroZero.distance(engine.getSceneLayoutBounds(nodes.get(0)).getMinX(),
+                    engine.getSceneLayoutBounds(nodes.get(0)).getMinY());
+            double distance;
+
+            for (nodeIndex = 1; nodeIndex < nodes.size(); nodeIndex++) {
+                distance = zeroZero.distance(engine.getSceneLayoutBounds(nodes.get(nodeIndex)).getMinX(),
+                        engine.getSceneLayoutBounds(nodes.get(nodeIndex)).getMinY());
+                if (nearestDistance > distance) {
+                    nearestDistance = distance;
+                    nearestNode = nodes.get(nodeIndex);
+                }
+            }
+            return nearestNode;
+        }
+        return null;
+    }
+
+    @Override
+    public Node selectLast(TraversalEngine engine) {
+        return null;
+    }
+
+    public int traverse(Bounds origin, Direction dir, List<Node> targets, TraversalEngine engine) {
 
         final int target;
 
         if (dir == NEXT || dir == PREVIOUS) {
-            target = trav1D(origin, dir, targets);
+            target = trav1D(origin, dir, targets, engine);
         } else {
-            target = trav2D(origin, dir, targets);
+            target = trav2D(origin, dir, targets, engine);
         }
 
         return target;
     }
 
-    private int trav2D(Bounds origin, Direction dir, List<Bounds> targets) {
+    private int trav2D(Bounds origin, Direction dir, List<Node> targets, TraversalEngine engine) {
 
         Bounds bestBounds = null;
         double bestMetric = 0.0;
         int bestIndex = -1;
 
         for (int i = 0; i < targets.size(); i++) {
-            final Bounds targetBounds = targets.get(i);
+            final Bounds targetBounds = engine.getSceneLayoutBounds(targets.get(i));
             final double outd = outDistance(dir, origin, targetBounds);
             final double metric;
 
@@ -281,22 +294,23 @@
         return (dir == NEXT) ? compare1D(a, b) : -compare1D(a, b);
     }
 
-    private int trav1D(Bounds origin, Direction dir, List<Bounds> targets) {
+    private int trav1D(Bounds origin, Direction dir, List<Node> targets, TraversalEngine engine) {
         int bestSoFar = -1;
         int leastSoFar = -1;
 
         for (int i = 0; i < targets.size(); i++) {
             if (leastSoFar == -1 ||
-                    compare1D(targets.get(i), targets.get(leastSoFar), dir) < 0) {
+                    compare1D(engine.getSceneLayoutBounds(targets.get(i)),
+                            engine.getSceneLayoutBounds(targets.get(leastSoFar)), dir) < 0) {
                 leastSoFar = i;
             }
 
-            if (compare1D(targets.get(i), origin, dir) < 0) {
+            if (compare1D(engine.getSceneLayoutBounds(targets.get(i)), origin, dir) < 0) {
                 continue;
             }
 
             if (bestSoFar == -1 ||
-                    compare1D(targets.get(i), targets.get(bestSoFar), dir) < 0) {
+                    compare1D(engine.getSceneLayoutBounds(targets.get(i)), engine.getSceneLayoutBounds(targets.get(bestSoFar)), dir) < 0) {
                 bestSoFar = i;
             }
         }
--- a/modules/graphics/src/main/java/javafx/scene/Node.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/Node.java	Tue Mar 11 15:48:46 2014 +0100
@@ -814,11 +814,8 @@
         if (sceneChanged) {
             updateCanReceiveFocus();
             if (isFocusTraversable()) {
-                if (oldScene != null) {
-                    oldScene.unregisterTraversable(Node.this);
-                }
                 if (newScene != null) {
-                    newScene.registerTraversable(Node.this);
+                    newScene.initializeInternalEventDispatcher();
                 }
             }
             focusSetDirty(oldScene);
@@ -7607,9 +7604,7 @@
                     Scene _scene = getScene();
                     if (_scene != null) {
                         if (get()) {
-                            _scene.registerTraversable(Node.this);
-                        } else {
-                            _scene.unregisterTraversable(Node.this);
+                            _scene.initializeInternalEventDispatcher();
                         }
                         focusSetDirty(_scene);
                     }
--- a/modules/graphics/src/main/java/javafx/scene/Parent.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/Parent.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,6 +25,7 @@
 
 package javafx.scene;
 
+import com.sun.javafx.scene.traversal.ParentTraversalEngine;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.ReadOnlyBooleanProperty;
 import javafx.beans.property.ReadOnlyBooleanWrapper;
@@ -733,7 +734,7 @@
     }
 
     /** @treatAsPrivate implementation detail */
-    private javafx.beans.property.ObjectProperty<TraversalEngine> impl_traversalEngine;
+    private javafx.beans.property.ObjectProperty<ParentTraversalEngine> impl_traversalEngine;
 
     /**
      * @treatAsPrivate implementation detail
@@ -741,7 +742,7 @@
      */
     // SB-dependency: RT-21209 has been filed to track this
     @Deprecated
-    public final void setImpl_traversalEngine(TraversalEngine value) {
+    public final void setImpl_traversalEngine(ParentTraversalEngine value) {
         impl_traversalEngineProperty().set(value);
     }
 
@@ -750,7 +751,7 @@
      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
      */
     @Deprecated
-    public final TraversalEngine getImpl_traversalEngine() {
+    public final ParentTraversalEngine getImpl_traversalEngine() {
         return impl_traversalEngine == null ? null : impl_traversalEngine.get();
     }
 
@@ -759,10 +760,10 @@
      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
      */
     @Deprecated
-    public final ObjectProperty<TraversalEngine> impl_traversalEngineProperty() {
+    public final ObjectProperty<ParentTraversalEngine> impl_traversalEngineProperty() {
         if (impl_traversalEngine == null) {
             impl_traversalEngine =
-                    new SimpleObjectProperty<TraversalEngine>(
+                    new SimpleObjectProperty<>(
                             this, "impl_traversalEngine");
         }
         return impl_traversalEngine;
--- a/modules/graphics/src/main/java/javafx/scene/Scene.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/Scene.java	Tue Mar 11 15:48:46 2014 +0100
@@ -47,7 +47,8 @@
 import com.sun.javafx.scene.input.InputEventUtils;
 import com.sun.javafx.scene.input.PickResultChooser;
 import com.sun.javafx.scene.traversal.Direction;
-import com.sun.javafx.scene.traversal.TraversalEngine;
+import com.sun.javafx.scene.traversal.SceneTraversalEngine;
+import com.sun.javafx.scene.traversal.TopMostTraversalEngine;
 import com.sun.javafx.sg.prism.NGCamera;
 import com.sun.javafx.sg.prism.NGLightBase;
 import com.sun.javafx.tk.*;
@@ -1055,12 +1056,8 @@
 
                     if (oldRoot != null) {
                         oldRoot.setScenes(null, null);
-                        oldRoot.setImpl_traversalEngine(null);
                     }
                     oldRoot = _value;
-                    if (_value.getImpl_traversalEngine() == null) {
-                        _value.setImpl_traversalEngine(new TraversalEngine(_value, true));
-                    }
                     _value.getStyleClass().add(0, "root");
                     _value.setScenes(Scene.this, null);
                     markDirty(DirtyBits.ROOT_DIRTY);
@@ -1894,80 +1891,16 @@
         return focusDirty;
     }
 
-    /**
-     * This is a map from focusTraversable nodes within this scene
-     * to instances of a traversal engine. The traversal engine is
-     * either the instance for the scene itself, or for a Parent
-     * nested somewhere within this scene.
-     *
-     * This has package access for testing purposes.
-     */
-    Map traversalRegistry; // Map<Node,TraversalEngine>
-
-    /**
-     * Searches up the scene graph for a Parent with a traversal engine.
-     */
-    private TraversalEngine lookupTraversalEngine(Node node) {
-        Parent p = node.getParent();
-
-        while (p != null) {
-            if (p.getImpl_traversalEngine() != null) {
-                return p.getImpl_traversalEngine();
-            }
-            p = p.getParent();
-        }
-
-        // This shouldn't ever occur, since walking up the tree
-        // should always find the Scene's root, which always has
-        // a traversal engine. But if for some reason we get here,
-        // just return the root's traversal engine.
-
-        return getRoot().getImpl_traversalEngine();
-    }
-
-    /**
-     * Registers a traversable node with a traversal engine
-     * on this scene.
-     */
-    void registerTraversable(Node n) {
-        initializeInternalEventDispatcher();
-
-        final TraversalEngine te = lookupTraversalEngine(n);
-        if (te != null) {
-            if (traversalRegistry == null) {
-                traversalRegistry = new HashMap();
-            }
-            traversalRegistry.put(n, te);
-            te.reg(n);
-        }
-    }
-
-    /**
-     * Unregisters a traversable node from this scene.
-     */
-    void unregisterTraversable(Node n) {
-        final TraversalEngine te = (TraversalEngine) traversalRegistry.remove(n);
-        if (te != null) {
-            te.unreg(n);
-        }
-    }
+    private TopMostTraversalEngine traversalEngine = new SceneTraversalEngine(this);
 
     /**
      * Traverses focus from the given node in the given direction.
      */
     boolean traverse(Node node, Direction dir) {
-        /*
-        ** if the registry is null then there are no
-        ** registered traversable nodes in this scene
-        */
-        if (traversalRegistry != null) {
-            TraversalEngine te = (TraversalEngine) traversalRegistry.get(node);
-            if (te == null) {
-                te = lookupTraversalEngine(node);
-            }
-            return te.trav(node, dir);
-        }
-        return false;
+        if (node.getSubScene() != null) {
+            return node.getSubScene().traverse(node, dir);
+        }
+        return traversalEngine.trav(node, dir) != null;
     }
 
     /**
@@ -1976,7 +1909,7 @@
      * removed from the scene.
      */
     private void focusInitial() {
-        getRoot().getImpl_traversalEngine().getTopLeftFocusableNode();
+        traversalEngine.traverseToFirst();
     }
 
     /**
@@ -4128,7 +4061,7 @@
         return internalEventDispatcher;
     }
 
-    private void initializeInternalEventDispatcher() {
+    final void initializeInternalEventDispatcher() {
         if (internalEventDispatcher == null) {
             internalEventDispatcher = createInternalEventDispatcher();
             eventDispatcher = new SimpleObjectProperty<EventDispatcher>(
--- a/modules/graphics/src/main/java/javafx/scene/SubScene.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/SubScene.java	Tue Mar 11 15:48:46 2014 +0100
@@ -25,6 +25,9 @@
 
 package javafx.scene;
 
+import com.sun.javafx.scene.traversal.Direction;
+import com.sun.javafx.scene.traversal.SubSceneTraversalEngine;
+import com.sun.javafx.scene.traversal.TopMostTraversalEngine;
 import javafx.application.ConditionalFeature;
 import javafx.application.Platform;
 import javafx.beans.NamedArg;
@@ -50,7 +53,6 @@
 import com.sun.javafx.scene.DirtyBits;
 import com.sun.javafx.scene.SubSceneHelper;
 import com.sun.javafx.scene.input.PickResultChooser;
-import com.sun.javafx.scene.traversal.TraversalEngine;
 import com.sun.javafx.sg.prism.NGCamera;
 import com.sun.javafx.sg.prism.NGLightBase;
 import com.sun.javafx.sg.prism.NGNode;
@@ -241,12 +243,8 @@
 
                     if (oldRoot != null) {
                         oldRoot.setScenes(null, null);
-                        oldRoot.setImpl_traversalEngine(null);
                     }
                     oldRoot = _value;
-                    if (_value.getImpl_traversalEngine() == null) {
-                        _value.setImpl_traversalEngine(new TraversalEngine(_value, true));
-                    }
                     _value.getStyleClass().add(0, "root");
                     _value.setScenes(getScene(), SubScene.this);
                     markDirty(SubSceneDirtyBits.ROOT_SG_DIRTY);
@@ -644,6 +642,12 @@
         }
     }
 
+    private TopMostTraversalEngine traversalEngine = new SubSceneTraversalEngine(this);
+
+    boolean traverse(Node node, Direction dir) {
+        return traversalEngine.trav(node, dir) != null;
+    }
+
     private enum SubSceneDirtyBits {
         SIZE_DIRTY,
         FILL_DIRTY,
--- a/modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraversalTest.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraversalTest.java	Tue Mar 11 15:48:46 2014 +0100
@@ -78,7 +78,7 @@
      * </ul>
      */
     private Node[] keypadNodes;
-    private TraversalEngine traversalEngine;
+    private SceneTraversalEngine traversalEngine;
 
     /*
      * Parameters: [fromNumber], [direction], [toNumber], [toNumberTransformed]
@@ -154,7 +154,7 @@
         scene = new Scene(new Group(), 500, 500);
         stage.setScene(scene);
 
-        traversalEngine = new TraversalEngine(scene.getRoot(), true);
+        traversalEngine = new SceneTraversalEngine(scene);
 
         keypadNodes = createKeypadNodesInScene(scene, traversalEngine);
 
@@ -216,7 +216,6 @@
 
                 keypad[index++] = keyNode;
                 ((Group)scene.getRoot()).getChildren().add(keyNode);
-                traversalEngine.reg(keyNode);
             }
         }
 
--- a/modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraverseInvisibleTest.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/graphics/src/test/java/com/sun/javafx/scene/traversal/TraverseInvisibleTest.java	Tue Mar 11 15:48:46 2014 +0100
@@ -59,7 +59,7 @@
     private Stage stage;
     private Scene scene;
     private Node[] keypadNodes;
-    private TraversalEngine traversalEngine;
+    private SceneTraversalEngine traversalEngine;
 
     /*
     **
@@ -97,7 +97,7 @@
         scene = new Scene(new Group(), 500, 500);
         stage.setScene(scene);
 
-        traversalEngine = new TraversalEngine(scene.getRoot(), true);
+        traversalEngine = new SceneTraversalEngine(scene);
 
         keypadNodes = createKeypadNodesInScene(scene, traversalEngine);
         stage.show();
@@ -140,7 +140,6 @@
 
                 keypad[index++] = keyNode;
                 ((Group)scene.getRoot()).getChildren().add(keyNode);
-                traversalEngine.reg(keyNode);
             }
         }
 
--- a/modules/graphics/src/test/java/javafx/scene/RegistrationTest.java	Mon Mar 10 19:31:43 2014 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,102 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package javafx.scene;
-
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-import com.sun.javafx.scene.traversal.TraversalEngine;
-
-public class RegistrationTest {
-    /**
-     * Asserts that this node is registered with this traversal engine.
-     */
-    void assertIsRegistered(Node n, TraversalEngine te) {
-        assertTrue(te.registeredNodes.contains(n));
-    }
-
-    /**
-     * Asserts that this node is not registered with this traversal engine.
-     */
-    void assertNotRegistered(Node n, TraversalEngine te) {
-        assertTrue(te.registeredNodes.contains(n) == false);
-    }
-
-    /**
-     * Helper function to return a node for testing.
-     * The boolean parameter determines whether it's traversable.
-     */
-    Node node(boolean traversable) {
-        Group g = new Group();
-        g.setFocusTraversable(traversable);
-        return g;
-    }
-
-    @Test
-    public void testAddRemoveTraversable() {
-        Node n = node(true);
-        Group root = new Group();
-        root.getChildren().addAll(n);
-        Scene s = new Scene(root);
-
-        System.out.println("n.scene="+n.getScene()+" s.traversalRegistry="+s.traversalRegistry);
-
-        assertTrue(s.traversalRegistry.containsKey(n));
-        TraversalEngine te = (TraversalEngine)s.traversalRegistry.get(n);
-        assertNotNull(te);
-        assertIsRegistered(n, te);
-
-        root.getChildren().remove(n);
-        assertFalse(s.traversalRegistry.containsKey(n));
-        assertNotRegistered(n, te);
-    }
-
-    @Test
-    public void testToggleTraversable() {
-        Node n = node(false);
-        Group root = new Group();
-        root.getChildren().addAll(n);
-        Scene s = new Scene(root);
-
-        assertTrue(s.traversalRegistry == null || !s.traversalRegistry.containsKey(n));
-
-        n.setFocusTraversable(true);
-        // note: reg is most likely null until we make a node traversable!
-        assertNotNull(s.traversalRegistry);
-        assertTrue(s.traversalRegistry.containsKey(n));
-        TraversalEngine te = (TraversalEngine)s.traversalRegistry.get(n);
-        assertNotNull(te);
-        assertIsRegistered(n, te);
-
-        n.setFocusTraversable(false);
-        assertFalse(s.traversalRegistry.containsKey(n));
-        assertNotRegistered(n, te);
-    }
-}
--- a/modules/web/src/main/java/com/sun/javafx/scene/web/behavior/HTMLEditorBehavior.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/web/src/main/java/com/sun/javafx/scene/web/behavior/HTMLEditorBehavior.java	Tue Mar 11 15:48:46 2014 +0100
@@ -65,7 +65,7 @@
             HTMLEditorSkin editorSkin = (HTMLEditorSkin)editor.getSkin();
             editorSkin.keyboardShortcuts(name);
         } else if ("F12".equals(name)) {
-            getControl().getImpl_traversalEngine().getTopLeftFocusableNode();
+            getControl().getImpl_traversalEngine().selectFirst().requestFocus();
         } else {
             super.callAction(name);
         }
--- a/modules/web/src/main/java/com/sun/javafx/scene/web/skin/HTMLEditorSkin.java	Mon Mar 10 19:31:43 2014 -0400
+++ b/modules/web/src/main/java/com/sun/javafx/scene/web/skin/HTMLEditorSkin.java	Tue Mar 11 15:48:46 2014 +0100
@@ -28,6 +28,9 @@
 import java.util.ResourceBundle;
 
 import com.sun.javafx.application.PlatformImpl;
+import com.sun.javafx.scene.traversal.Algorithm;
+import com.sun.javafx.scene.traversal.Direction;
+import com.sun.javafx.scene.traversal.ParentTraversalEngine;
 import org.w3c.dom.html.HTMLDocument;
 import org.w3c.dom.html.HTMLElement;
 
@@ -42,18 +45,13 @@
 import javafx.event.EventHandler;
 import javafx.geometry.Bounds;
 import javafx.geometry.NodeOrientation;
-import javafx.scene.Group;
 import javafx.scene.Node;
 import javafx.scene.control.Button;
 import javafx.scene.control.ComboBox;
 import javafx.scene.control.ListCell;
 import javafx.scene.control.ListView;
-import javafx.scene.control.MenuButton;
-import javafx.scene.control.MenuItem;
-import javafx.scene.control.RadioMenuItem;
 import javafx.scene.control.Separator;
 import javafx.scene.control.TextInputControl;
-import javafx.scene.control.Toggle;
 import javafx.scene.control.ToggleButton;
 import javafx.scene.control.ToggleGroup;
 import javafx.scene.control.ToolBar;
@@ -67,21 +65,17 @@
 import javafx.scene.layout.GridPane;
 import javafx.scene.layout.Priority;
 import javafx.scene.paint.Color;
-import javafx.scene.shape.Rectangle;
 import javafx.scene.text.Font;
 import javafx.scene.web.HTMLEditor;
 import javafx.scene.web.WebView;
 import javafx.util.Callback;
 
-import com.sun.javafx.PlatformUtil;
-import com.sun.javafx.scene.control.behavior.BehaviorBase;
 import com.sun.javafx.scene.control.skin.ColorPickerSkin;
 import com.sun.javafx.scene.control.skin.FXVK;
 import com.sun.javafx.scene.web.behavior.HTMLEditorBehavior;
 import com.sun.javafx.scene.traversal.TraversalEngine;
 import com.sun.javafx.scene.traversal.TraverseListener;
 import com.sun.webkit.WebPage;
-import com.sun.webkit.event.WCFocusEvent;
 import com.sun.javafx.webkit.Accessor;
 
 import java.security.AccessController;
@@ -102,7 +96,7 @@
 /**
  * HTML editor skin.
  */
-public class HTMLEditorSkin extends BehaviorSkinBase<HTMLEditor, HTMLEditorBehavior> implements TraverseListener {
+public class HTMLEditorSkin extends BehaviorSkinBase<HTMLEditor, HTMLEditorBehavior> {
     private GridPane gridPane;
 
     private ToolBar toolbar1;
@@ -240,7 +234,7 @@
         return DEFAULT_WINDOWS_7_MAPPINGS;
     }
 
-    private TraversalEngine engine;
+    private ParentTraversalEngine engine;
 
     private boolean resetToolbarState = false;
     private String cachedHTMLText = "<html><head></head><body contenteditable=\"true\"></body></html>";
@@ -480,9 +474,22 @@
         enableToolbar(true);
         setHTMLText(cachedHTMLText);
 
-        engine = new TraversalEngine(getSkinnable(), false);
-        engine.addTraverseListener(this);
-        engine.reg(toolbar1);
+        engine = new ParentTraversalEngine(getSkinnable(), new Algorithm() {
+            @Override
+            public Node select(Node owner, Direction dir, TraversalEngine engine) {
+                return cutButton;
+            }
+
+            @Override
+            public Node selectFirst(TraversalEngine engine) {
+                return cutButton;
+            }
+
+            @Override
+            public Node selectLast(TraversalEngine engine) {
+                return cutButton;
+            }
+        });
         getSkinnable().setImpl_traversalEngine(engine);
         webView.setFocusTraversable(true);
         gridPane.getChildren().addListener(itemsListener);
@@ -1183,11 +1190,6 @@
         }
     }
 
-    @Override
-    public void onTraverse(Node node, Bounds bounds) {
-        cutButton.requestFocus();
-    }
-    
     private boolean isFirstRun = true;
 
     @Override