Skip to content

Commit ac24255

Browse files
Jeremy WoodAlexander Zuev
authored andcommitted
8379347: VoiceOver Doesn't Correctly Identify JToggleButtons as "toggle buttons"
Reviewed-by: honkar, kizune, prr
1 parent 7e4ac14 commit ac24255

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CheckboxAccessibility.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2026, 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
@@ -36,6 +36,18 @@ - (NSAccessibilityRole _Nonnull)accessibilityRole
3636
return NSAccessibilityCheckBoxRole;
3737
}
3838

39+
- (NSAccessibilitySubrole _Nullable)accessibilitySubrole
40+
{
41+
JNIEnv *env = [ThreadUtilities getJNIEnv];
42+
if (env != NULL) {
43+
NSString *javaRole = [self javaRole];
44+
if ([javaRole isEqualToString:@"togglebutton"]) {
45+
return NSAccessibilityToggleSubrole;
46+
}
47+
}
48+
return [super accessibilitySubrole];
49+
}
50+
3951
- (id _Nonnull) accessibilityValue
4052
{
4153
AWT_ASSERT_APPKIT_THREAD;

src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ + (void) initializeRolesMap {
136136
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
137137
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
138138
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
139+
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"togglebutton"];
139140
[rolesMap setObject:@"SliderAccessibility" forKey:@"slider"];
140141
[rolesMap setObject:@"ScrollAreaAccessibility" forKey:@"scrollpane"];
141142
[rolesMap setObject:@"ScrollBarAccessibility" forKey:@"scrollbar"];
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2026, 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 javax.swing.JToggleButton;
25+
import javax.swing.JFrame;
26+
27+
/*
28+
* @test
29+
* @key headful
30+
* @bug 8379347
31+
* @summary manual test for VoiceOver reading JToggleButtons correctly
32+
* @requires os.family == "mac"
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual VoiceOverToggleButtonRole
36+
*/
37+
38+
public class VoiceOverToggleButtonRole {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS = """
41+
INSTRUCTIONS (Mac-only):
42+
1. Open VoiceOver
43+
2. Move the VoiceOver cursor over the JToggleButton.
44+
3. Observe how VoiceOver identifies the toggle button.
45+
46+
Expected behavior: VoiceOver should identify it as a
47+
"toggle button" initially. (VO does still say "to select
48+
or deselect this checkbox", though.)
49+
50+
If you select the link using "Accessibility Inspector":
51+
it should identify its subrole as AXToggle.
52+
""";
53+
54+
PassFailJFrame.builder()
55+
.title("VoiceOverToggleButtonRole Instruction")
56+
.instructions(INSTRUCTIONS)
57+
.columns(40)
58+
.testUI(VoiceOverToggleButtonRole::createUI)
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
private static JFrame createUI() {
64+
JFrame frame = new JFrame();
65+
frame.getContentPane().add(new JToggleButton("JToggleButton"));
66+
frame.pack();
67+
return frame;
68+
}
69+
}

0 commit comments

Comments
 (0)