8261352: Create implementation for component peer for all the components who should be ignored in a11y interactions

Reviewed-by: serb
This commit is contained in:
Alexander Zuev 2021-03-18 19:50:20 +00:00
parent 21db0f6768
commit e543a50098
5 changed files with 137 additions and 37 deletions

View File

@ -84,9 +84,6 @@ static jclass sjc_CAccessible = NULL;
#define GET_CACCESSIBLE_CLASS_RETURN(ret) \
GET_CLASS_RETURN(sjc_CAccessible, "sun/lwawt/macosx/CAccessible", ret);
static jobject sAccessibilityClass = NULL;
// sAttributeNamesForRoleCache holds the names of the attributes to which each java
// AccessibleRole responds (see AccessibleRole.java).
// This cache is queried before attempting to access a given attribute for a particular role.
@ -286,39 +283,6 @@ static NSObject *sAttributeNamesLOCK = nil;
if (sRoles == nil) {
initializeRoles();
}
if (sAccessibilityClass == NULL) {
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CACCESSIBILITY_CLASS();
DECLARE_STATIC_METHOD(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;");
#ifdef JAVA_AX_NO_IGNORES
NSArray *ignoredKeys = [NSArray array];
#else
NSArray *ignoredKeys = [sRoles allKeysForObject:JavaAccessibilityIgnore];
#endif
jobjectArray result = NULL;
jsize count = [ignoredKeys count];
DECLARE_CLASS(jc_String, "java/lang/String");
result = (*env)->NewObjectArray(env, count, jc_String, NULL);
CHECK_EXCEPTION();
if (!result) {
NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
return;
}
NSInteger i;
for (i = 0; i < count; i++) {
jstring jString = NSStringToJavaString(env, [ignoredKeys objectAtIndex:i]);
(*env)->SetObjectArrayElement(env, result, i, jString);
(*env)->DeleteLocalRef(env, jString);
}
sAccessibilityClass = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibility, result); // AWT_THREADING Safe (known object)
CHECK_EXCEPTION();
}
}
+ (void)postFocusChanged:(id)message

View File

@ -37,6 +37,7 @@
- (NSRect)accessibilityFrame;
- (nullable id)accessibilityParent;
- (BOOL)performAccessibleAction:(int)index;
- (BOOL)isAccessibilityElement;
@end
#endif

View File

@ -36,6 +36,8 @@ static jmethodID sjm_getAccessibleComponent = NULL;
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;", ret);
static NSMutableDictionary * _Nullable rolesMap;
NSString *const IgnoreClassName = @"IgnoreAccessibility";
static jobject sAccessibilityClass = NULL;
/*
* Common ancestor for all the accessibility peers that implements the new method-based accessibility API
@ -46,7 +48,7 @@ static NSMutableDictionary * _Nullable rolesMap;
/*
* Here we should keep all the mapping between the accessibility roles and implementing classes
*/
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:8];
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:26];
[rolesMap setObject:@"ButtonAccessibility" forKey:@"pushbutton"];
[rolesMap setObject:@"ImageAccessibility" forKey:@"icon"];
@ -56,6 +58,63 @@ static NSMutableDictionary * _Nullable rolesMap;
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
/*
* All the components below should be ignored by the accessibility subsystem,
* If any of the enclosed component asks for a parent the first ancestor
* participating in accessibility exchange should be returned.
*/
[rolesMap setObject:IgnoreClassName forKey:@"alert"];
[rolesMap setObject:IgnoreClassName forKey:@"colorchooser"];
[rolesMap setObject:IgnoreClassName forKey:@"desktoppane"];
[rolesMap setObject:IgnoreClassName forKey:@"dialog"];
[rolesMap setObject:IgnoreClassName forKey:@"directorypane"];
[rolesMap setObject:IgnoreClassName forKey:@"filechooser"];
[rolesMap setObject:IgnoreClassName forKey:@"filler"];
[rolesMap setObject:IgnoreClassName forKey:@"fontchooser"];
[rolesMap setObject:IgnoreClassName forKey:@"frame"];
[rolesMap setObject:IgnoreClassName forKey:@"glasspane"];
[rolesMap setObject:IgnoreClassName forKey:@"layeredpane"];
[rolesMap setObject:IgnoreClassName forKey:@"optionpane"];
[rolesMap setObject:IgnoreClassName forKey:@"panel"];
[rolesMap setObject:IgnoreClassName forKey:@"rootpane"];
[rolesMap setObject:IgnoreClassName forKey:@"separator"];
[rolesMap setObject:IgnoreClassName forKey:@"tooltip"];
[rolesMap setObject:IgnoreClassName forKey:@"viewport"];
[rolesMap setObject:IgnoreClassName forKey:@"window"];
/*
* Initialize CAccessibility instance
*/
#ifdef JAVA_AX_NO_IGNORES
NSArray *ignoredKeys = [NSArray array];
#else
NSArray *ignoredKeys = [rolesMap allKeysForObject:IgnoreClassName];
#endif
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CACCESSIBILITY_CLASS();
DECLARE_STATIC_METHOD(jm_getAccessibility, sjc_CAccessibility, "getAccessibility", "([Ljava/lang/String;)Lsun/lwawt/macosx/CAccessibility;");
jobjectArray result = NULL;
jsize count = [ignoredKeys count];
DECLARE_CLASS(jc_String, "java/lang/String");
result = (*env)->NewObjectArray(env, count, jc_String, NULL);
CHECK_EXCEPTION();
if (!result) {
NSLog(@"In %s, can't create Java array of String objects", __FUNCTION__);
return;
}
NSInteger i;
for (i = 0; i < count; i++) {
jstring jString = NSStringToJavaString(env, [ignoredKeys objectAtIndex:i]);
(*env)->SetObjectArrayElement(env, result, i, jString);
(*env)->DeleteLocalRef(env, jString);
}
sAccessibilityClass = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getAccessibility, result);
CHECK_EXCEPTION();
}
/*
@ -117,4 +176,8 @@ static NSMutableDictionary * _Nullable rolesMap;
return TRUE;
}
- (BOOL)isAccessibilityElement {
return YES;
}
@end

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 "JavaComponentAccessibility.h"
#import "CommonComponentAccessibility.h"
#import <AppKit/AppKit.h>
@interface IgnoreAccessibility : CommonComponentAccessibility {
};
- (BOOL)isAccessibilityElement;
@end

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 "IgnoreAccessibility.h"
/*
* Indicates that component does not participate in accessibility exchange
*/
@implementation IgnoreAccessibility
- (BOOL)isAccessibilityElement
{
return NO;
}
@end