Skip to content

Commit 1e87ff0

Browse files
author
Abhishek Kumar
committed
8348936: [Accessibility,macOS,VoiceOver] VoiceOver doesn't announce untick on toggling the checkbox with "space" key on macOS
8345728: [Accessibility,macOS,Screen Magnifier]: JCheckbox unchecked state does not magnify but works for checked state Reviewed-by: aivanov, kizune, dnguyen, asemenov
1 parent 86d0616 commit 1e87ff0

File tree

2 files changed

+133
-3
lines changed

2 files changed

+133
-3
lines changed

src/java.desktop/macosx/classes/sun/lwawt/macosx/CAccessible.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 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
@@ -28,6 +28,7 @@
2828
import java.awt.Component;
2929
import java.beans.PropertyChangeEvent;
3030
import java.beans.PropertyChangeListener;
31+
import java.util.Objects;
3132

3233
import javax.accessibility.Accessible;
3334
import javax.accessibility.AccessibleContext;
@@ -182,7 +183,7 @@ public void propertyChange(PropertyChangeEvent e) {
182183

183184
// Do send check box state changes to native side
184185
if (thisRole == AccessibleRole.CHECK_BOX) {
185-
if (newValue != null && !newValue.equals(oldValue)) {
186+
if (!Objects.equals(newValue, oldValue)) {
186187
valueChanged(ptr);
187188
}
188189

@@ -208,7 +209,7 @@ public void propertyChange(PropertyChangeEvent e) {
208209

209210
// Do send toggle button state changes to native side
210211
if (thisRole == AccessibleRole.TOGGLE_BUTTON) {
211-
if (newValue != null && !newValue.equals(oldValue)) {
212+
if (!Objects.equals(newValue, oldValue)) {
212213
valueChanged(ptr);
213214
}
214215
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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.BorderLayout;
25+
import java.awt.GridLayout;
26+
27+
import javax.swing.JCheckBox;
28+
import javax.swing.JFrame;
29+
import javax.swing.JPanel;
30+
import javax.swing.JToggleButton;
31+
32+
/*
33+
* @test
34+
* @bug 8348936 8345728
35+
* @summary Verifies that VoiceOver announces the untick state of CheckBox and
36+
* ToggleButton when space key is pressed. Also verifies that CheckBox
37+
* and ToggleButton untick state is magnified with Screen Magnifier.
38+
* @requires os.family == "mac"
39+
* @library /java/awt/regtesthelpers
40+
* @build PassFailJFrame
41+
* @run main/manual TestJCheckBoxToggleAccessibility
42+
*/
43+
44+
public class TestJCheckBoxToggleAccessibility {
45+
public static void main(String[] args) throws Exception {
46+
String INSTRUCTIONS = """
47+
<html><body>
48+
<p><b>Testing with VoiceOver</b></p>
49+
50+
<ol>
51+
<li>Start the VoiceOver application
52+
(Press <kbd>Command</kbd> + <kbd>F5</kbd>)
53+
<li>Click on the <i>Frame with CheckBox and ToggleButton</i>
54+
window to move focus
55+
<li>Press <kbd>Spacebar</kbd>
56+
<li>VO should announce the checked state
57+
<li>Press <kbd>Spacebar</kbd> again
58+
<li>VO should announce the unchecked state
59+
<li>Press <kbd>Tab</kbd> to move focus to <i>ToggleButton</i>
60+
<li>Repeat steps 3 to 6 and listen the announcement
61+
<li>If announcements are incorrect, press <b>Fail</b>
62+
<li>Stop the VoiceOver application
63+
(Press <kbd>Command</kbd> + <kbd>F5</kbd> again)
64+
</ol>
65+
66+
<p><b>Testing with Screen Magnifier</b></p>
67+
<ol style="margin-bottom: 0">
68+
<li>Enable Screen magnifier on the Mac:
69+
<b>System Settings</b> -> <b>Accessibility</b> ->
70+
<b>Hover Text</b> -> Enable <b>Hover Text</b><br>
71+
Default Hover Text Activation Modifier is <kbd>Command</kbd> key
72+
<li>Move focus back to the test application and perform the following tests
73+
74+
<ul style="margin-bottom: 0">
75+
<li>Test <i>CheckBox</i> states with Screen Magnifier
76+
<ol style="list-style-type: lower-alpha; margin-top: 0; margin-bottom: 0">
77+
<li>Click on <i>CheckBox</i> to select it
78+
<li>Press the <kbd>Command</kbd> key and
79+
hover mouse over <i>CheckBox</i>
80+
<li>CheckBox ticked state along with its label should be magnified
81+
<li>Keep the <kbd>Command</kbd> key pressed and
82+
click <i>CheckBox</i> to deselect it
83+
<li>CheckBox unticked state along with its label should be magnified
84+
<li>Release the <kbd>Command</kbd> key
85+
<li>If Screen Magnifier behaviour is incorrect, press <b>Fail</b>
86+
</ol>
87+
<li>Test <i>ToggleButton</i> states with Screen Magnifier
88+
<ol style="list-style-type: lower-alpha; margin-top: 0; margin-bottom: 0">
89+
<li>Click on <i>ToggleButton</i> to select it
90+
<li>Press the <kbd>Command</kbd> key and
91+
hover mouse over <i>ToggleButton</i>
92+
<li>Ticked state along with label should be magnified
93+
<li>Keep the <kbd>Command</kbd> button pressed and
94+
click <i>ToggleButton</i> to deselect it
95+
<li>Unticked state along with its label should be magnified
96+
<li>Release the <kbd>Command</kbd> key
97+
<li>If Screen Magnifier behaviour is incorrect, press <b>Fail</b>
98+
</ol>
99+
</ul>
100+
<li>Disable <b>Hover Text</b> (optionally) in the Settings
101+
</ol>
102+
103+
<p>Press <b>Pass</b> if you are able to hear correct VoiceOver announcements and
104+
able to see the correct screen magnifier behaviour.</p></body></html>""";
105+
106+
PassFailJFrame.builder()
107+
.title("TestJCheckBoxToggleAccessibility Instruction")
108+
.instructions(INSTRUCTIONS)
109+
.columns(40)
110+
.rows(25)
111+
.testUI(TestJCheckBoxToggleAccessibility::createUI)
112+
.testTimeOut(8)
113+
.build()
114+
.awaitAndCheck();
115+
}
116+
117+
private static JFrame createUI() {
118+
JFrame frame = new JFrame("A Frame with CheckBox and ToggleButton");
119+
JCheckBox cb = new JCheckBox("CheckBox", false);
120+
JToggleButton tb = new JToggleButton("ToggleButton");
121+
122+
JPanel p = new JPanel(new GridLayout(2, 1));
123+
p.add(cb);
124+
p.add(tb);
125+
frame.getContentPane().add(p, BorderLayout.CENTER);
126+
frame.setSize(400, 400);
127+
return frame;
128+
}
129+
}

0 commit comments

Comments
 (0)