Skip to content

Commit ecdc322

Browse files
author
Abhishek Kumar
committedJan 13, 2025
8339728: [Accessibility,Windows,JAWS] Bug in the getKeyChar method of the AccessBridge class
Reviewed-by: aivanov, kizune Backport-of: a46ae70
1 parent da74fbd commit ecdc322

File tree

3 files changed

+122
-11
lines changed

3 files changed

+122
-11
lines changed
 

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, 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
@@ -3904,6 +3904,8 @@ private int controlCode(KeyStroke keyStroke) {
39043904
return 0;
39053905
int code = keyStroke.getKeyCode();
39063906
switch (code) {
3907+
case KeyEvent.VK_TAB:
3908+
case KeyEvent.VK_SPACE:
39073909
case KeyEvent.VK_BACK_SPACE:
39083910
case KeyEvent.VK_DELETE:
39093911
case KeyEvent.VK_DOWN:
@@ -3946,15 +3948,10 @@ private char getKeyChar(KeyStroke keyStroke) {
39463948
debugString("[INFO]: Shortcut is control character: " + Integer.toHexString(keyCode));
39473949
return (char)keyCode;
39483950
}
3949-
String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
3950-
debugString("[INFO]: Shortcut is: " + keyText);
3951-
if (keyText != null || keyText.length() > 0) {
3952-
CharSequence seq = keyText.subSequence(0, 1);
3953-
if (seq != null || seq.length() > 0) {
3954-
return seq.charAt(0);
3955-
}
3956-
}
3957-
return 0;
3951+
3952+
keyCode = keyStroke.getKeyCode();
3953+
debugString("[INFO]: Shortcut is: " + Integer.toHexString(keyCode));
3954+
return (char)keyCode;
39583955
}
39593956

39603957
/*

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

+3-1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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
46+
2. Press Alt + M to open application Menu
47+
3. Navigate the Menu Items by using UP / DOWN arrow key
48+
4. Press Pass if you are able to hear correct JAWS announcements
49+
(JAWS should read full shortcut text and not only the 1st
50+
character of shortcut text for each menu item) else Fail
51+
""";
52+
53+
PassFailJFrame.builder()
54+
.title("TestJMenuItemShortcutAccessibility Instruction")
55+
.instructions(INSTRUCTIONS)
56+
.columns(35)
57+
.testUI(TestJMenuItemShortcutAccessibility::createUI)
58+
.build()
59+
.awaitAndCheck();
60+
}
61+
62+
private static JFrame createUI() {
63+
JFrame frame = new JFrame("A Frame with Menu");
64+
65+
JMenuBar menuBar = new JMenuBar();
66+
JMenu menu = new JMenu("Menu with shortcuts");
67+
menu.setMnemonic(KeyEvent.VK_M);
68+
menuBar.add(menu);
69+
70+
KeyStroke keyStroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_F,
71+
InputEvent.CTRL_DOWN_MASK);
72+
KeyStroke keyStroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_2,
73+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
74+
KeyStroke keyStroke3 = KeyStroke.getKeyStroke(KeyEvent.VK_F1,
75+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
76+
KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_COMMA,
77+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
78+
KeyStroke keyStroke5 = KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD,
79+
InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK);
80+
KeyStroke keyStroke6 = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
81+
InputEvent.CTRL_DOWN_MASK);
82+
KeyStroke keyStroke7 = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,
83+
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK);
84+
85+
JMenuItem menuItem1 = new JMenuItem("First Menu Item");
86+
menuItem1.setAccelerator(keyStroke1);
87+
JMenuItem menuItem2 = new JMenuItem("Second Menu Item");
88+
menuItem2.setAccelerator(keyStroke2);
89+
JMenuItem menuItem3 = new JMenuItem("Third Menu Item");
90+
menuItem3.setAccelerator(keyStroke3);
91+
JMenuItem menuItem4 = new JMenuItem("Fourth Menu Item");
92+
menuItem4.setAccelerator(keyStroke4);
93+
JMenuItem menuItem5 = new JMenuItem("Fifth Menu Item");
94+
menuItem5.setAccelerator(keyStroke5);
95+
JMenuItem menuItem6 = new JMenuItem("Sixth Menu Item");
96+
menuItem6.setAccelerator(keyStroke6);
97+
JMenuItem menuItem7 = new JMenuItem("Seventh Menu Item");
98+
menuItem7.setAccelerator(keyStroke7);
99+
100+
menu.add(menuItem1);
101+
menu.add(menuItem2);
102+
menu.add(menuItem3);
103+
menu.add(menuItem4);
104+
menu.add(menuItem5);
105+
menu.add(menuItem6);
106+
menu.add(menuItem7);
107+
108+
frame.setJMenuBar(menuBar);
109+
frame.setSize(300, 200);
110+
return frame;
111+
}
112+
}

0 commit comments

Comments
 (0)