8379347: VoiceOver Doesn't Correctly Identify JToggleButtons as "toggle buttons"

Reviewed-by: honkar, kizune, prr
This commit is contained in:
Jeremy Wood 2026-03-28 09:33:31 +00:00 committed by Alexander Zuev
parent 7e4ac140d9
commit ac242550fe
3 changed files with 83 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2026, 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
@ -36,6 +36,18 @@
return NSAccessibilityCheckBoxRole;
}
- (NSAccessibilitySubrole _Nullable)accessibilitySubrole
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
if (env != NULL) {
NSString *javaRole = [self javaRole];
if ([javaRole isEqualToString:@"togglebutton"]) {
return NSAccessibilityToggleSubrole;
}
}
return [super accessibilitySubrole];
}
- (id _Nonnull) accessibilityValue
{
AWT_ASSERT_APPKIT_THREAD;

View File

@ -136,6 +136,7 @@ static jobject sAccessibilityClass = NULL;
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"togglebutton"];
[rolesMap setObject:@"SliderAccessibility" forKey:@"slider"];
[rolesMap setObject:@"ScrollAreaAccessibility" forKey:@"scrollpane"];
[rolesMap setObject:@"ScrollBarAccessibility" forKey:@"scrollbar"];

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2026, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.swing.JToggleButton;
import javax.swing.JFrame;
/*
* @test
* @key headful
* @bug 8379347
* @summary manual test for VoiceOver reading JToggleButtons correctly
* @requires os.family == "mac"
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual VoiceOverToggleButtonRole
*/
public class VoiceOverToggleButtonRole {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
INSTRUCTIONS (Mac-only):
1. Open VoiceOver
2. Move the VoiceOver cursor over the JToggleButton.
3. Observe how VoiceOver identifies the toggle button.
Expected behavior: VoiceOver should identify it as a
"toggle button" initially. (VO does still say "to select
or deselect this checkbox", though.)
If you select the link using "Accessibility Inspector":
it should identify its subrole as AXToggle.
""";
PassFailJFrame.builder()
.title("VoiceOverToggleButtonRole Instruction")
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(VoiceOverToggleButtonRole::createUI)
.build()
.awaitAndCheck();
}
private static JFrame createUI() {
JFrame frame = new JFrame();
frame.getContentPane().add(new JToggleButton("JToggleButton"));
frame.pack();
return frame;
}
}