8061381: [macosx] Accelerators does not spelled for JMenuItems by Voice Over
Reviewed-by: prr, kaddepalli
This commit is contained in:
parent
46c0ea0234
commit
996ee174b3
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, 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
|
||||
@ -31,6 +31,7 @@ import java.awt.Dimension;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -54,7 +55,9 @@ import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.lwawt.LWWindowPeer;
|
||||
@ -355,6 +358,10 @@ class CAccessibility implements PropertyChangeListener {
|
||||
if (accessibleName == null) {
|
||||
return ac.getAccessibleDescription();
|
||||
}
|
||||
final String acceleratorText = getAcceleratorText(ac);
|
||||
if (!acceleratorText.isEmpty()) {
|
||||
return accessibleName +' '+ acceleratorText;
|
||||
}
|
||||
return accessibleName;
|
||||
}
|
||||
}, c);
|
||||
@ -374,6 +381,41 @@ class CAccessibility implements PropertyChangeListener {
|
||||
}, c);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the JMenuItem accelerator. Implementation of this method is based
|
||||
* on AccessBridge.getAccelerator(AccessibleContext) to access the KeyStroke
|
||||
* and on AquaMenuPainter.paintMenuItem() to convert it to string.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private static String getAcceleratorText(AccessibleContext ac) {
|
||||
String accText = "";
|
||||
Accessible parent = ac.getAccessibleParent();
|
||||
if (parent != null) {
|
||||
// workaround for getAccessibleKeyBinding not returning the
|
||||
// JMenuItem accelerator
|
||||
int indexInParent = ac.getAccessibleIndexInParent();
|
||||
Accessible child = parent.getAccessibleContext()
|
||||
.getAccessibleChild(indexInParent);
|
||||
if (child instanceof JMenuItem) {
|
||||
JMenuItem menuItem = (JMenuItem) child;
|
||||
KeyStroke keyStroke = menuItem.getAccelerator();
|
||||
if (keyStroke != null) {
|
||||
int modifiers = keyStroke.getModifiers();
|
||||
if (modifiers > 0) {
|
||||
accText = KeyEvent.getKeyModifiersText(modifiers);
|
||||
}
|
||||
int keyCode = keyStroke.getKeyCode();
|
||||
if (keyCode != 0) {
|
||||
accText += KeyEvent.getKeyText(keyCode);
|
||||
} else {
|
||||
accText += keyStroke.getKeyChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return accText;
|
||||
}
|
||||
|
||||
public static String getAccessibleDescription(final Accessible a, final Component c) {
|
||||
if (a == null) return null;
|
||||
|
||||
|
@ -3779,7 +3779,8 @@ final public class AccessBridge {
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the JMenuItem accelerator
|
||||
* Returns the JMenuItem accelerator. Similar implementation is used on
|
||||
* macOS, see CAccessibility.getAcceleratorText(AccessibleContext).
|
||||
*/
|
||||
private KeyStroke getAccelerator(final AccessibleContext ac) {
|
||||
// workaround for getAccessibleKeyBinding not returning the
|
||||
|
Loading…
x
Reference in New Issue
Block a user