Skip to content

Commit bf78d9b

Browse files
vieirojerboaa
authored andcommitted
8339728: [Accessibility,Windows,JAWS] Bug in the getKeyChar method of the AccessBridge class
Reviewed-by: sgehwolf Backport-of: 01d107aea8eca4f4d2863deb30ac60e802debe15
1 parent 624cef6 commit bf78d9b

File tree

3 files changed

+121
-11
lines changed

3 files changed

+121
-11
lines changed

src/jdk.accessibility/windows/classes/com/sun/java/accessibility/internal/AccessBridge.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -3838,6 +3838,8 @@ private int controlCode(KeyStroke keyStroke) {
38383838
return 0;
38393839
int code = keyStroke.getKeyCode();
38403840
switch (code) {
3841+
case KeyEvent.VK_TAB:
3842+
case KeyEvent.VK_SPACE:
38413843
case KeyEvent.VK_BACK_SPACE:
38423844
case KeyEvent.VK_DELETE:
38433845
case KeyEvent.VK_DOWN:
@@ -3880,15 +3882,10 @@ private char getKeyChar(KeyStroke keyStroke) {
38803882
debugString("[INFO]: Shortcut is control character: " + Integer.toHexString(keyCode));
38813883
return (char)keyCode;
38823884
}
3883-
String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
3884-
debugString("[INFO]: Shortcut is: " + keyText);
3885-
if (keyText != null || keyText.length() > 0) {
3886-
CharSequence seq = keyText.subSequence(0, 1);
3887-
if (seq != null || seq.length() > 0) {
3888-
return seq.charAt(0);
3889-
}
3890-
}
3891-
return 0;
3885+
3886+
keyCode = keyStroke.getKeyCode();
3887+
debugString("[INFO]: Shortcut is: " + Integer.toHexString(keyCode));
3888+
return (char)keyCode;
38923889
}
38933890

38943891
/*

src/jdk.accessibility/windows/native/include/bridge/AccessBridgePackages.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1108,6 +1108,8 @@ typedef long ABHWND64;
11081108
#define ACCESSIBLE_CONTROLCODE_KEYSTROKE 512 // Control code key pressed, character contains control code.
11091109

11101110
// The supported control code keys are:
1111+
#define ACCESSIBLE_VK_TAB 9
1112+
#define ACCESSIBLE_VK_SPACE 32
11111113
#define ACCESSIBLE_VK_BACK_SPACE 8
11121114
#define ACCESSIBLE_VK_DELETE 127
11131115
#define ACCESSIBLE_VK_DOWN 40
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.event.InputEvent;
25+
import java.awt.event.KeyEvent;
26+
import javax.swing.JFrame;
27+
import javax.swing.JMenu;
28+
import javax.swing.JMenuBar;
29+
import javax.swing.JMenuItem;
30+
import javax.swing.KeyStroke;
31+
32+
/*
33+
* @test
34+
* @bug 8339728
35+
* @summary Tests that JAWS announce the shortcuts for JMenuItems.
36+
* @requires os.family == "windows"
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual TestJMenuItemShortcutAccessibility
40+
*/
41+
42+
public class TestJMenuItemShortcutAccessibility {
43+
public static void main(String[] args) throws Exception {
44+
String INSTRUCTIONS = ""
45+
+ "1. Start the JAWS application\n"
46+
+ "2. Press Alt + M to open application Menu\n"
47+
+ "3. Navigate the Menu Items by using UP / DOWN arrow key\n"
48+
+ "4. Press Pass if you are able to hear correct JAWS announcements\n"
49+
+ " (JAWS should read full shortcut text and not only the 1st\n"
50+
+ " character of shortcut text for each menu item) else Fail\n";
51+
52+
PassFailJFrame.builder()
53+
.title("TestJMenuItemShortcutAccessibility Instruction")
54+
.instructions(INSTRUCTIONS)
55+
.columns(35)
56+
.testUI(TestJMenuItemShortcutAccessibility::createUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
private static JFrame createUI() {
62+
JFrame frame = new JFrame("A Frame with Menu");
63+
64+
JMenuBar menuBar = new JMenuBar();
65+
JMenu menu = new JMenu("Menu with shortcuts");
66+
menu.setMnemonic(KeyEvent.VK_M);
67+
menuBar.add(menu);
68+
69+
KeyStroke keyStroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_F,
70+
InputEvent.CTRL_DOWN_MASK);
71+
KeyStroke keyStroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_2,
72+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
73+
KeyStroke keyStroke3 = KeyStroke.getKeyStroke(KeyEvent.VK_F1,
74+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
75+
KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_COMMA,
76+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
77+
KeyStroke keyStroke5 = KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD,
78+
InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
79+
KeyStroke keyStroke6 = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
80+
InputEvent.CTRL_DOWN_MASK);
81+
KeyStroke keyStroke7 = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
82+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
83+
84+
JMenuItem menuItem1 = new JMenuItem("First Menu Item");
85+
menuItem1.setAccelerator(keyStroke1);
86+
JMenuItem menuItem2 = new JMenuItem("Second Menu Item");
87+
menuItem2.setAccelerator(keyStroke2);
88+
JMenuItem menuItem3 = new JMenuItem("Third Menu Item");
89+
menuItem3.setAccelerator(keyStroke3);
90+
JMenuItem menuItem4 = new JMenuItem("Fourth Menu Item");
91+
menuItem4.setAccelerator(keyStroke4);
92+
JMenuItem menuItem5 = new JMenuItem("Fifth Menu Item");
93+
menuItem5.setAccelerator(keyStroke5);
94+
JMenuItem menuItem6 = new JMenuItem("Sixth Menu Item");
95+
menuItem6.setAccelerator(keyStroke6);
96+
JMenuItem menuItem7 = new JMenuItem("Seventh Menu Item");
97+
menuItem7.setAccelerator(keyStroke7);
98+
99+
menu.add(menuItem1);
100+
menu.add(menuItem2);
101+
menu.add(menuItem3);
102+
menu.add(menuItem4);
103+
menu.add(menuItem5);
104+
menu.add(menuItem6);
105+
menu.add(menuItem7);
106+
107+
frame.setJMenuBar(menuBar);
108+
frame.setSize(300, 200);
109+
return frame;
110+
}
111+
}

0 commit comments

Comments
 (0)