Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8350551

Simple press-drag-release gesture delivers drag events to wrong node

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      macOS 15.3 (24D60)
      OpenJDK 23.0.2
      JavaFX 23.0.2

      A DESCRIPTION OF THE PROBLEM :
      The MouseEvent documentation says "The simple press-drag-release gesture is default. It's best used to allow changing size of a shape, dragging it around and so on. Whole press-drag-release gesture is delivered to one node. When a mouse button is pressed, the top-most node is picked and all subsequent mouse events are delivered to the same node until the button is released. If a mouse clicked event is generated from these events, it is still delivered to the same node." https://openjfx.io/javadoc/23/javafx.graphics/javafx/scene/input/MouseEvent.html

      This behavior recently broke for me on macOS 15: If a press and subsequent drag fires on a node X, dragging the mouse out of X will sometimes continue to deliver the drag events to X but sometimes deliver them to the parent of X. From the description above, I expect the correct behavior should be to deliver all drag events to X. However, the behavior must at least be consistent; at the moment it's random.

      I cannot pin point the exact macOS update or change that caused this issue however. The issue is also present with JDK 21 and JavaFX 21.


      REGRESSION : Last worked in version 23.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code below. Start dragging the mouse inside the blue rectangle. Drag the mouse out of the blue rectangle. Repeat several times and vary the speed from fast to slow and direction of the dragging.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      If you press the mouse down in the blue rectangle and drag it out of the blue rectangle, the background stays green.
      ACTUAL -
      The background sometimes stays green (all drag events are delivered to the rectangle node) and sometimes turns red. There's no discernible pattern.

      ---------- BEGIN SOURCE ----------
      package org.example;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.Pane;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      public class Test extends Application {
          @Override
          public void start(Stage primaryStage) {
              Rectangle rectangle = new Rectangle(100.0, 100.0, 200.0, 150.0);
              rectangle.setFill(Color.BLUE);

              Pane pane = new Pane(rectangle);

              rectangle.setOnMouseDragged(event -> {
                  pane.setBackground(new Background(new BackgroundFill(Color.GREEN, null, null)));
                  event.consume();
              });

              pane.setOnMouseDragged(event -> {
                  pane.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
              });

              Scene scene = new Scene(pane, 800.0, 600.0);

              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              Application.launch(Test.class, args);
          }
      }
      ---------- END SOURCE ----------


       

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: