changeset 1251:defcb2e3aa77

RT-21952 : Click on button opens context menu
author mickf
date Thu, 07 Jun 2012 18:03:06 +0100
parents 60301b7fd01f
children 966cbfed8d62
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ButtonSkin.java javafx-ui-controls/test/javafx/scene/control/ButtonTest.java
diffstat 2 files changed, 47 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ButtonSkin.java	Thu Jun 07 13:43:46 2012 +1200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ButtonSkin.java	Thu Jun 07 18:03:06 2012 +0100
@@ -25,7 +25,6 @@
 
 package com.sun.javafx.scene.control.skin;
 
-import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.geometry.Side;
 import javafx.scene.control.Button;
@@ -66,22 +65,6 @@
             setCancelButton(true);
         }       
 
-        button.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>() {
-            @Override public void handle(ActionEvent e) {
-
-                ContextMenu cm = getSkinnable().getContextMenu();
-                if (cm != null) {
-                    if (!cm.isShowing()) {
-                        cm.show(getSkinnable(), Side.RIGHT, 0, 0);
-                        Utils.addMnemonics(cm, getSkinnable().getScene());
-                    }
-                    else {
-                        cm.hide();
-                        Utils.removeMnemonics(cm, getSkinnable().getScene());
-                    }
-                }
-            }
-        });                
     }
 
 
--- a/javafx-ui-controls/test/javafx/scene/control/ButtonTest.java	Thu Jun 07 13:43:46 2012 +1200
+++ b/javafx-ui-controls/test/javafx/scene/control/ButtonTest.java	Thu Jun 07 18:03:06 2012 +0100
@@ -16,10 +16,13 @@
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
 import javafx.scene.Scene;
+import javafx.scene.control.ContextMenu;
 import javafx.scene.input.KeyCode;
+import javafx.scene.input.MouseEvent;
 import javafx.scene.layout.StackPane;
 import javafx.scene.shape.Rectangle;
 import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
 
 import org.junit.Before;
 import org.junit.Ignore;
@@ -295,6 +298,50 @@
 
         tk.firePulse();                      
     }
+
+
+    @Test public void conextMenuShouldntShowOnAction() {
+        final MouseEventGenerator generator = new MouseEventGenerator();
+
+        ContextMenu popupMenu = new ContextMenu();
+        MenuItem item1 = new MenuItem("_About");
+        popupMenu.getItems().add(item1);
+        popupMenu.setOnShown(new EventHandler<WindowEvent>() {
+            @Override public void handle(WindowEvent w) {
+                fail();
+            }
+        });
+
+        btn.setContextMenu(popupMenu);
+        btn.setDefaultButton(true);
+
+        root.getChildren().add(btn);
+        show();
+
+        double xval = (btn.localToScene(btn.getLayoutBounds())).getMinX();
+        double yval = (btn.localToScene(btn.getLayoutBounds())).getMinY();
+
+
+        /*
+        ** none of these should cause the context menu to appear,
+        ** so fire them all, and see if anything happens.
+        */
+        KeyEventFirer keyboard = new KeyEventFirer(btn);        
+        keyboard.doKeyPress(KeyCode.ENTER);
+
+        btn.fireEvent(new ActionEvent());
+        btn.fire();
+        scene.impl_processMouseEvent(
+            generator.generateMouseEvent(MouseEvent.MOUSE_PRESSED, xval+10, yval+10));
+        scene.impl_processMouseEvent(
+            generator.generateMouseEvent(MouseEvent.MOUSE_RELEASED, xval+10, yval+10));
+        scene.impl_processMouseEvent(
+            generator.generateMouseEvent(MouseEvent.MOUSE_CLICKED, xval+10, yval+10));
+       
+        tk.firePulse();                      
+    }
+
+
     
 //  private Button button1;
 //  private Button button2;