Skip to content
Permalink
Browse files
8261352: Create implementation for component peer for all the compone…
…nts who should be ignored in a11y interactions

Reviewed-by: serb
  • Loading branch information
Alexander Zuev committed Mar 18, 2021
1 parent 21db0f6 commit e543a5009847a8e3ccbb047b93e3cc6fb261ef8c
@@ -84,9 +84,6 @@
#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 @@ + (void)initialize
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
@@ -37,6 +37,7 @@
- (NSRect)accessibilityFrame;
- (nullable id)accessibilityParent;
- (BOOL)performAccessibleAction:(int)index;
- (BOOL)isAccessibilityElement;
@end

#endif
@@ -36,6 +36,8 @@
"(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 @@ + (void) initializeRolesMap {
/*
* 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 @@ + (void) initializeRolesMap {
[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 @@ - (BOOL)performAccessibleAction:(int)index
return TRUE;
}

- (BOOL)isAccessibilityElement {
return YES;
}

@end
@@ -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
@@ -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

1 comment on commit e543a50

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on e543a50 Mar 18, 2021

Please sign in to comment.