changeset 1279:d5146a3b928f

RT-22150: fixed event delivery to nodes with non-invertible transformation.
author Pavel Safrata
date Fri, 08 Jun 2012 13:16:50 +0200
parents c9f8ab00f5be
children 796a3a759c37
files javafx-ui-common/src/com/sun/javafx/scene/input/InputEventUtils.java javafx-ui-common/src/javafx/scene/input/ContextMenuEvent.java javafx-ui-common/src/javafx/scene/input/DragEvent.java javafx-ui-common/src/javafx/scene/input/GestureEvent.java javafx-ui-common/src/javafx/scene/input/MouseEvent.java javafx-ui-common/src/javafx/scene/input/TouchPoint.java javafx-ui-common/test/unit/javafx/scene/MouseTest.java
diffstat 7 files changed, 48 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/scene/input/InputEventUtils.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/com/sun/javafx/scene/input/InputEventUtils.java	Fri Jun 08 13:16:50 2012 +0200
@@ -56,14 +56,24 @@
             if (oldSourceNode != null) {
                 Point2D pt = oldSourceNode.localToScene(newX, newY);
                 pt = newSourceNode.sceneToLocal(pt);
-                newX = pt.getX();
-                newY = pt.getY();
+                if (pt != null) {
+                    newX = pt.getX();
+                    newY = pt.getY();
+                } else {
+                    newX = Double.NaN;
+                    newY = Double.NaN;
+                }
             } else {
                 // assume that since no node was in the evt, then it was in
                 // terms of the scene
                 Point2D pt = newSourceNode.sceneToLocal(newX, newY);
-                newX = pt.getX();
-                newY = pt.getY();
+                if (pt != null) {
+                    newX = pt.getX();
+                    newY = pt.getY();
+                } else {
+                    newX = Double.NaN;
+                    newY = Double.NaN;
+                }
             }
         } else {
             if (oldSourceNode != null) {
--- a/javafx-ui-common/src/javafx/scene/input/ContextMenuEvent.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/ContextMenuEvent.java	Fri Jun 08 13:16:50 2012 +0200
@@ -81,12 +81,10 @@
     private void recomputeCoordinatesToSource(ContextMenuEvent newEvent, Object newSource) {
 
         final Point2D newCoordinates = InputEventUtils.recomputeCoordinates(
-                new Point2D(x, y), source, newSource);
+                new Point2D(sceneX, sceneY), null, newSource);
 
         newEvent.x = newCoordinates.getX();
         newEvent.y = newCoordinates.getY();
-        newEvent.sceneX = getSceneX();
-        newEvent.sceneY = getSceneY();
     }
 
     @Override
--- a/javafx-ui-common/src/javafx/scene/input/DragEvent.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/DragEvent.java	Fri Jun 08 13:16:50 2012 +0200
@@ -409,7 +409,7 @@
         }
 
         final Point2D newCoordinates = InputEventUtils.recomputeCoordinates(
-                new Point2D(x, y), source, newSource);
+                new Point2D(sceneX, sceneY), null, newSource);
 
         newEvent.x = newCoordinates.getX();
         newEvent.y = newCoordinates.getY();
--- a/javafx-ui-common/src/javafx/scene/input/GestureEvent.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/GestureEvent.java	Fri Jun 08 13:16:50 2012 +0200
@@ -91,12 +91,10 @@
     private void recomputeCoordinatesToSource(GestureEvent newEvent, Object newSource) {
 
         final Point2D newCoordinates = InputEventUtils.recomputeCoordinates(
-                new Point2D(x, y), source, newSource);
+                new Point2D(sceneX, sceneY), null, newSource);
 
         newEvent.x = newCoordinates.getX();
         newEvent.y = newCoordinates.getY();
-        newEvent.sceneX = getSceneX();
-        newEvent.sceneY = getSceneY();
     }
 
     /**
--- a/javafx-ui-common/src/javafx/scene/input/MouseEvent.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/MouseEvent.java	Fri Jun 08 13:16:50 2012 +0200
@@ -272,12 +272,10 @@
     private void recomputeCoordinatesToSource(MouseEvent newEvent, Object newSource) {
 
         final Point2D newCoordinates = InputEventUtils.recomputeCoordinates(
-                new Point2D(x, y), source, newSource);
+                new Point2D(sceneX, sceneY), null, newSource);
 
         newEvent.x = newCoordinates.getX();
         newEvent.y = newCoordinates.getY();
-        newEvent.sceneX = getSceneX();
-        newEvent.sceneY = getSceneY();
     }
 
     /**
--- a/javafx-ui-common/src/javafx/scene/input/TouchPoint.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/TouchPoint.java	Fri Jun 08 13:16:50 2012 +0200
@@ -75,7 +75,7 @@
     void recomputeToSource(Object oldSource, Object newSource) {
 
         final Point2D newCoordinates = InputEventUtils.recomputeCoordinates(
-                new Point2D(x, y), oldSource, newSource);
+                new Point2D(sceneX, sceneY), null, newSource);
 
         x = newCoordinates.getX();
         y = newCoordinates.getY();
--- a/javafx-ui-common/test/unit/javafx/scene/MouseTest.java	Fri Jun 08 09:39:08 2012 +0200
+++ b/javafx-ui-common/test/unit/javafx/scene/MouseTest.java	Fri Jun 08 13:16:50 2012 +0200
@@ -911,7 +911,7 @@
     }
 
     @Test
-    public void NodeMovementsWithStillMouseShouldFireEnteredExited() {
+    public void nodeMovementsWithStillMouseShouldFireEnteredExited() {
         SimpleTestScene scene = new SimpleTestScene();
         MouseEventGenerator generator = new MouseEventGenerator();
 
@@ -934,6 +934,34 @@
         assertTrue(scene.smallSquareTracker.enteredMe);
     }
 
+    @Test
+    public void nodeWithNoninvertibleTransformShouldGetNanCoords() {
+        SimpleTestScene scene = new SimpleTestScene();
+        MouseEventGenerator generator = new MouseEventGenerator();
+
+        scene.processEvent(generator.generateMouseEvent(
+                MouseEvent.MOUSE_PRESSED, 250, 250));
+        scene.smallSquareTracker.clear();
+
+        scene.smallSquareTracker.node.addEventHandler(MouseEvent.MOUSE_RELEASED,
+                new EventHandler<MouseEvent>() {
+
+            @Override public void handle(MouseEvent event) {
+                assertEquals(Double.NaN, event.getX(), 0.0001);
+                assertEquals(Double.NaN, event.getY(), 0.0001);
+                assertEquals(251.0, event.getSceneX(), 0.0001);
+                assertEquals(251.0, event.getSceneY(), 0.0001);
+            }
+        });
+
+        ((Rectangle) scene.smallSquareTracker.node).setScaleX(0);
+
+        scene.processEvent(generator.generateMouseEvent(
+                MouseEvent.MOUSE_RELEASED, 251, 251));
+
+        assertTrue(scene.smallSquareTracker.released);
+    }
+
     private static class SimpleTestScene {
 
         MouseEventTracker sceneTracker;