Skip to content

Commit c9ce60b

Browse files
WithEnoughCoffeePaul Hohensee
authored and
Paul Hohensee
committed
8261352: Create implementation for component peer for all the components who should be ignored in a11y interactions
Backport-of: e543a50
1 parent 0422f05 commit c9ce60b

File tree

5 files changed

+137
-37
lines changed

5 files changed

+137
-37
lines changed

src/java.desktop/macosx/native/libawt_lwawt/awt/JavaComponentAccessibility.m

-36
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@
9090
#define GET_CACCESSIBLE_CLASS_RETURN(ret) \
9191
GET_CLASS_RETURN(sjc_CAccessible, "sun/lwawt/macosx/CAccessible", ret);
9292

93-
94-
static jobject sAccessibilityClass = NULL;
95-
9693
// sAttributeNamesForRoleCache holds the names of the attributes to which each java
9794
// AccessibleRole responds (see AccessibleRole.java).
9895
// This cache is queried before attempting to access a given attribute for a particular role.
@@ -292,39 +289,6 @@ + (void)initialize
292289
if (sRoles == nil) {
293290
initializeRoles();
294291
}
295-
296-
if (sAccessibilityClass == NULL) {
297-
JNIEnv *env = [ThreadUtilities getJNIEnv];
298-
299-
GET_CACCESSIBILITY_CLASS();
300-
DECLARE_STATIC_METHOD(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;");
301-
302-
#ifdef JAVA_AX_NO_IGNORES
303-
NSArray *ignoredKeys = [NSArray array];
304-
#else
305-
NSArray *ignoredKeys = [sRoles allKeysForObject:JavaAccessibilityIgnore];
306-
#endif
307-
jobjectArray result = NULL;
308-
jsize count = [ignoredKeys count];
309-
310-
DECLARE_CLASS(jc_String, "java/lang/String");
311-
result = (*env)->NewObjectArray(env, count, jc_String, NULL);
312-
CHECK_EXCEPTION();
313-
if (!result) {
314-
NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
315-
return;
316-
}
317-
318-
NSInteger i;
319-
for (i = 0; i < count; i++) {
320-
jstring jString = NSStringToJavaString(env, [ignoredKeys objectAtIndex:i]);
321-
(*env)->SetObjectArrayElement(env, result, i, jString);
322-
(*env)->DeleteLocalRef(env, jString);
323-
}
324-
325-
sAccessibilityClass = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibility, result); // AWT_THREADING Safe (known object)
326-
CHECK_EXCEPTION();
327-
}
328292
}
329293

330294
+ (void)postFocusChanged:(id)message

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- (NSRect)accessibilityFrame;
3838
- (nullable id)accessibilityParent;
3939
- (BOOL)performAccessibleAction:(int)index;
40+
- (BOOL)isAccessibilityElement;
4041
@end
4142

4243
#endif

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

+64-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;", ret);
3737

3838
static NSMutableDictionary * _Nullable rolesMap;
39+
NSString *const IgnoreClassName = @"IgnoreAccessibility";
40+
static jobject sAccessibilityClass = NULL;
3941

4042
/*
4143
* Common ancestor for all the accessibility peers that implements the new method-based accessibility API
@@ -46,7 +48,7 @@ + (void) initializeRolesMap {
4648
/*
4749
* Here we should keep all the mapping between the accessibility roles and implementing classes
4850
*/
49-
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:8];
51+
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:26];
5052

5153
[rolesMap setObject:@"ButtonAccessibility" forKey:@"pushbutton"];
5254
[rolesMap setObject:@"ImageAccessibility" forKey:@"icon"];
@@ -56,6 +58,63 @@ + (void) initializeRolesMap {
5658
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
5759
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
5860
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
61+
62+
/*
63+
* All the components below should be ignored by the accessibility subsystem,
64+
* If any of the enclosed component asks for a parent the first ancestor
65+
* participating in accessibility exchange should be returned.
66+
*/
67+
[rolesMap setObject:IgnoreClassName forKey:@"alert"];
68+
[rolesMap setObject:IgnoreClassName forKey:@"colorchooser"];
69+
[rolesMap setObject:IgnoreClassName forKey:@"desktoppane"];
70+
[rolesMap setObject:IgnoreClassName forKey:@"dialog"];
71+
[rolesMap setObject:IgnoreClassName forKey:@"directorypane"];
72+
[rolesMap setObject:IgnoreClassName forKey:@"filechooser"];
73+
[rolesMap setObject:IgnoreClassName forKey:@"filler"];
74+
[rolesMap setObject:IgnoreClassName forKey:@"fontchooser"];
75+
[rolesMap setObject:IgnoreClassName forKey:@"frame"];
76+
[rolesMap setObject:IgnoreClassName forKey:@"glasspane"];
77+
[rolesMap setObject:IgnoreClassName forKey:@"layeredpane"];
78+
[rolesMap setObject:IgnoreClassName forKey:@"optionpane"];
79+
[rolesMap setObject:IgnoreClassName forKey:@"panel"];
80+
[rolesMap setObject:IgnoreClassName forKey:@"rootpane"];
81+
[rolesMap setObject:IgnoreClassName forKey:@"separator"];
82+
[rolesMap setObject:IgnoreClassName forKey:@"tooltip"];
83+
[rolesMap setObject:IgnoreClassName forKey:@"viewport"];
84+
[rolesMap setObject:IgnoreClassName forKey:@"window"];
85+
86+
/*
87+
* Initialize CAccessibility instance
88+
*/
89+
#ifdef JAVA_AX_NO_IGNORES
90+
NSArray *ignoredKeys = [NSArray array];
91+
#else
92+
NSArray *ignoredKeys = [rolesMap allKeysForObject:IgnoreClassName];
93+
#endif
94+
95+
JNIEnv *env = [ThreadUtilities getJNIEnv];
96+
GET_CACCESSIBILITY_CLASS();
97+
DECLARE_STATIC_METHOD(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;");
98+
jobjectArray result = NULL;
99+
jsize count = [ignoredKeys count];
100+
101+
DECLARE_CLASS(jc_String, "java/lang/String");
102+
result = (*env)->NewObjectArray(env, count, jc_String, NULL);
103+
CHECK_EXCEPTION();
104+
if (!result) {
105+
NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
106+
return;
107+
}
108+
109+
NSInteger i;
110+
for (i = 0; i < count; i++) {
111+
jstring jString = NSStringToJavaString(env, [ignoredKeys objectAtIndex:i]);
112+
(*env)->SetObjectArrayElement(env, result, i, jString);
113+
(*env)->DeleteLocalRef(env, jString);
114+
}
115+
116+
sAccessibilityClass = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibility, result);
117+
CHECK_EXCEPTION();
59118
}
60119

61120
/*
@@ -117,4 +176,8 @@ - (BOOL)performAccessibleAction:(int)index
117176
return TRUE;
118177
}
119178

179+
- (BOOL)isAccessibilityElement {
180+
return YES;
181+
}
182+
120183
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2021, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
#import "JavaComponentAccessibility.h"
27+
#import "CommonComponentAccessibility.h"
28+
29+
#import <AppKit/AppKit.h>
30+
31+
@interface IgnoreAccessibility : CommonComponentAccessibility {
32+
33+
};
34+
- (BOOL)isAccessibilityElement;
35+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021, 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. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
#import "IgnoreAccessibility.h"
27+
28+
/*
29+
* Indicates that component does not participate in accessibility exchange
30+
*/
31+
@implementation IgnoreAccessibility
32+
- (BOOL)isAccessibilityElement
33+
{
34+
return NO;
35+
}
36+
37+
@end

0 commit comments

Comments
 (0)