changeset 6592:d7e80f499365 8u20-b08

[Accessibility] Show Menu action support
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Fri, 28 Mar 2014 17:00:45 -0700
parents 5ff2177ef9b6
children 6c7201f0f984 ca7a0e1f961e babda162124b
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java modules/controls/src/main/java/javafx/scene/control/Control.java modules/graphics/src/main/java/com/sun/glass/ui/mac/MacAccessible.java
diffstat 3 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Fri Mar 28 16:10:41 2014 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Fri Mar 28 17:00:45 2014 -0700
@@ -1414,6 +1414,13 @@
         @Override
         public void accExecuteAction(Action action, Object... parameters) {
             switch (action) {
+                case SHOW_MENU:{
+                    if (item instanceof Menu) {
+                        final Menu menuItem = (Menu) item;
+                        menuItem.hide();
+                    }
+                    break;
+                }
                 case FIRE: 
                     doSelect();
                     break;
--- a/modules/controls/src/main/java/javafx/scene/control/Control.java	Fri Mar 28 16:10:41 2014 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/Control.java	Fri Mar 28 17:00:45 2014 -0700
@@ -38,6 +38,7 @@
 import javafx.beans.value.WritableValue;
 import javafx.collections.ObservableList;
 import javafx.event.EventHandler;
+import javafx.geometry.Side;
 import javafx.scene.Node;
 import javafx.scene.accessibility.Action;
 import javafx.scene.accessibility.Attribute;
@@ -925,6 +926,15 @@
 
     /** @treatAsPrivate */
     @Override public void accExecuteAction(Action action, Object... parameters) {
+        switch (action) {
+            case SHOW_MENU:
+                ContextMenu menu = getContextMenu();
+                if (menu != null) {
+                    menu.show(this, Side.RIGHT, 0, 0);
+                }
+                break;
+            default:
+        }
         if (skinBase != null) {
             skinBase.accExecuteAction(action);
         }
--- a/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacAccessible.java	Fri Mar 28 16:10:41 2014 -0700
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacAccessible.java	Fri Mar 28 17:00:45 2014 -0700
@@ -25,6 +25,9 @@
 
 package com.sun.glass.ui.mac;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.function.Function;
 import java.util.stream.Stream;
 import javafx.collections.ObservableList;
@@ -221,10 +224,7 @@
                 /* Expanded only needed for Combobox, and not for PopUpButton */
 //                MacAttributes.NSAccessibilityExpandedAttribute,
             },
-            new MacActions[] {
-                MacActions.NSAccessibilityPressAction,
-                MacActions.NSAccessibilityShowMenuAction,
-            },
+            new MacActions[] {MacActions.NSAccessibilityPressAction},
             null
         ),
         NSAccessibilityTabGroupRole(new Role[] {Role.TAB_PANE, Role.PAGINATION},
@@ -430,9 +430,7 @@
                 MacAttributes.NSAccessibilityEnabledAttribute,
                 MacAttributes.NSAccessibilityOverflowButtonAttribute,
             },
-            new MacActions[] {
-                MacActions.NSAccessibilityShowMenuAction,
-            }
+            null
         ),
         ;
 
@@ -440,7 +438,7 @@
         Role[] jfxRoles;
         MacAttributes[] macAttributes;
         MacAttributes[] macParameterizedAttributes;
-        MacActions[] macActions;
+        List<MacActions> macActions;
         MacRoles(Role jfxRole, MacAttributes[] macAttributes, MacActions[] macActions) {
             this(new Role[] {jfxRole}, macAttributes, macActions, null);
         }
@@ -448,7 +446,7 @@
         MacRoles(Role[] jfxRoles, MacAttributes[] macAttributes, MacActions[] macActions, MacAttributes[] macParameterizedAttributes) {
             this.jfxRoles = jfxRoles;
             this.macAttributes = macAttributes;
-            this.macActions = macActions;
+            this.macActions = macActions != null ? Arrays.asList(macActions) : null;
             this.macParameterizedAttributes = macParameterizedAttributes;
         }
 
@@ -1200,16 +1198,22 @@
     long[] accessibilityActionNames() {
         if (getView() != null) return null; /* Let NSView answer for the Scene */
         Role role = (Role)getAttribute(ROLE);
+        List<MacActions> actions = new  ArrayList<>();
         if (role != null) {
-            Stream<MacActions> actions = Stream.empty();
             MacRoles macRole = MacRoles.getRole(role);
             if (macRole != null && macRole.macActions != null) {
-                actions = Stream.concat(actions, Stream.of(macRole.macActions));
+                actions.addAll(macRole.macActions);
             }
-            return actions.mapToLong(a -> a.ptr).toArray();
+            /* 
+             * Consider add a attribute to indicate when the node
+             * has a menu instead of using the role.
+             */
+            if (role != Role.NODE && role != Role.PARENT) {
+                actions.add(MacActions.NSAccessibilityShowMenuAction);
+            }
         }
         /* Return empty array instead of null to prevent warnings in the accessibility verifier */
-        return new long[0];
+        return actions.stream().mapToLong(a -> a.ptr).toArray();
     }
 
     String accessibilityActionDescription(long action) {