Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8267385: Create NSAccessibilityElement implementation for JavaComponentAccessibility #4412

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -769,6 +769,23 @@ public static int getTableInfo(final Accessible a, final Component c,
}, c);
}

private static int[] getTableSelectedInfo(final Accessible a, final Component c,
final int info) {
if (a == null) return null;
return invokeAndWait(() -> {
AccessibleContext ac = a.getAccessibleContext();
AccessibleTable table = ac.getAccessibleTable();
if (table != null) {
if (info == JAVA_AX_COLS) {
return table.getSelectedAccessibleColumns();
} else if (info == JAVA_AX_ROWS) {
return table.getSelectedAccessibleRows();
}
}
return null;
}, c);
}

private static AccessibleRole getAccessibleRoleForLabel(JLabel l, AccessibleRole fallback) {
String text = l.getText();
if (text != null && text.length() > 0) {
@@ -676,7 +676,7 @@ - (NSString *)accessibilitySelectedText

- (void)setAccessibilitySelectedText:(NSString *)accessibilitySelectedText {
id focused = [self accessibilityFocusedUIElement];
if ([focused respondsToSelector:@selector(setAccessibilitySelectedText)]) {
if ([focused respondsToSelector:@selector(setAccessibilitySelectedText:)]) {
[focused setAccessibilitySelectedText:accessibilitySelectedText];
}
}
@@ -66,7 +66,7 @@ - (NSArray *)accessibilityChildren

NSUInteger childIndex = [self columnNumberInTable];

int inc = [(TableAccessibility *)[self accessibilityParent] accessibleColCount] * 2;
int inc = [(TableAccessibility *)[self accessibilityParent] accessibilityRowCount] * 2;
NSInteger i = childIndex * 2;
for(i; i < arrayLen; i += inc)
{
@@ -89,7 +89,7 @@ - (NSArray *)accessibilityChildren
withIndex:childIndex
withView:self->fView
withJavaRole:childJavaRole];
[childrenCells addObject:[child autorelease]];
[childrenCells addObject:[[child retain] autorelease]];

(*env)->DeleteLocalRef(env, jchild);
(*env)->DeleteLocalRef(env, jchildJavaRole);
@@ -46,13 +46,15 @@ - (id)accessibilityValue {
jclass axContextClass = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getAccessibleSelection, axContextClass, "getAccessibleSelection", "(I)Ljavax/accessibility/Accessible;", nil);
jobject axSelectedChild = (*env)->CallObjectMethod(env, axContext, jm_getAccessibleSelection, 0);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, axContext);
if (axSelectedChild == NULL) {
return nil;
}
GET_CACCESSIBILITY_CLASS_RETURN(nil);
GET_ACCESSIBLENAME_METHOD_RETURN(nil);
jobject childName = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleName, axSelectedChild, fComponent);
CHECK_EXCEPTION();
if (childName == NULL) {
(*env)->DeleteLocalRef(env, axSelectedChild);
return nil;
@@ -629,7 +629,7 @@ - (NSArray *)accessibleChildrenWithChildCode:(NSInteger)childCode
NSArray *children = [CommonComponentAccessibility childrenOfParent:self
withEnv:env
withChildrenCode:childCode
allowIgnored:([[self accessibilityRole] isEqualToString:NSAccessibilityListRole] || [[self accessibilityRole] isEqualToString:NSAccessibilityOutlineRole])
allowIgnored:([[self accessibilityRole] isEqualToString:NSAccessibilityListRole] || [[self accessibilityRole] isEqualToString:NSAccessibilityOutlineRole] || [[self accessibilityRole] isEqualToString:NSAccessibilityTableRole])
recursive:[[self accessibilityRole] isEqualToString:NSAccessibilityOutlineRole]];

NSArray *value = nil;
@@ -49,7 +49,7 @@ - (NSArray *)accessibilityChildren
withEnv:[ThreadUtilities getJNIEnv]
withView:self->fView
isWrapped:YES];
return [NSArray arrayWithObject:[newChild autorelease]];
return [NSArray arrayWithObject:newChild];
} else {
return children;
}
@@ -41,7 +41,9 @@ - (BOOL)isTreeRootVisible
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_ISTREEROOTVISIBLE_METHOD_RETURN(NO);
return (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, sjm_isTreeRootVisible, fAccessible, fComponent);
bool isTreeRootVisible = (*env)->CallStaticBooleanMethod(env, sjc_CAccessibility, sjm_isTreeRootVisible, fAccessible, fComponent);
CHECK_EXCEPTION();
return isTreeRootVisible;
}

// NSAccessibilityElement protocol methods
@@ -44,11 +44,13 @@ - (jobject)currentAccessibleWithENV:(JNIEnv *)env
jclass axContextClass = (*env)->GetObjectClass(env, jAxContext);
DECLARE_METHOD_RETURN(jm_getCurrentComponent, axContextClass, "getCurrentComponent", "()Ljava/awt/Component;", NULL);
jobject newComponent = (*env)->CallObjectMethod(env, jAxContext, jm_getCurrentComponent);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, jAxContext);
if (newComponent != NULL) {
GET_CACCESSIBLE_CLASS_RETURN(NULL);
DECLARE_STATIC_METHOD_RETURN(sjm_getCAccessible, sjc_CAccessible, "getCAccessible", "(Ljavax/accessibility/Accessible;)Lsun/lwawt/macosx/CAccessible;", NULL);
jobject currentAccessible = (*env)->CallStaticObjectMethod(env, sjc_CAccessible, sjm_getCAccessible, newComponent);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, newComponent);
return currentAccessible;
} else {
@@ -26,10 +26,6 @@

@interface TableAccessibility : CommonComponentAccessibility <NSAccessibilityTable>

@property(readonly) int accessibleRowCount;
@property(readonly) int accessibleColCount;
@property(readonly) NSArray<NSNumber *> *selectedAccessibleRows;
@property(readonly) NSArray<NSNumber *> *selectedAccessibleColumns;
- (BOOL)isAccessibleChildSelectedFromIndex:(int)index;
- (int) accessibleRowAtIndex:(int)index;
- (int) accessibleColumnAtIndex:(int)index;
@@ -31,75 +31,58 @@
#import "ColumnAccessibility.h"
#import "ThreadUtilities.h"
#import "JNIUtilities.h"
#import "CellAccessibility.h"

#define JAVA_AX_ROWS (1)
#define JAVA_AX_COLS (2)

static jclass sjc_CAccessibility = NULL;

static jmethodID sjm_getAccessibleName = NULL;
#define GET_ACCESSIBLENAME_METHOD_RETURN(ret) \
GET_CACCESSIBILITY_CLASS_RETURN(ret); \
GET_STATIC_METHOD_RETURN(sjm_getAccessibleName, sjc_CAccessibility, "getAccessibleName", \
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljava/lang/String;", ret);

@implementation TableAccessibility

- (int)accessibleRowCount
- (id)getTableInfo:(jint)info
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject axContext = [self axContextWithEnv:env];
if (axContext == NULL) return 0;
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getAccessibleRowCount, clsInfo, "getAccessibleRowCount", "()I", 0);
jint javaRowsCount = (*env)->CallIntMethod(env, axContext, jm_getAccessibleRowCount);
(*env)->DeleteLocalRef(env, axContext);
return (int)javaRowsCount;
}
if (fAccessible == NULL) return 0;

- (int)accessibleColCount
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject axContext = [self axContextWithEnv:env];
if (axContext == NULL) return 0;
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getAccessibleColumnCount, clsInfo, "getAccessibleColumnCount", "()I", 0);
jint javaColsCount = (*env)->CallIntMethod(env, axContext, jm_getAccessibleColumnCount);
(*env)->DeleteLocalRef(env, axContext);
return (int)javaColsCount;
JNIEnv* env = [ThreadUtilities getJNIEnv];
GET_CACCESSIBILITY_CLASS_RETURN(nil);
DECLARE_STATIC_METHOD_RETURN(jm_getTableInfo, sjc_CAccessibility, "getTableInfo",
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I", nil);
jint count = (*env)->CallStaticIntMethod(env, sjc_CAccessibility, jm_getTableInfo, fAccessible,
fComponent, info);
CHECK_EXCEPTION();
NSNumber *index = [NSNumber numberWithInt:count];
return index;
}

- (NSArray<NSNumber *> *)selectedAccessibleRows
- (NSArray<NSNumber *> *)getTableSelectedInfo:(jint)info
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject axContext = [self axContextWithEnv:env];
if (axContext == NULL) return nil;
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getSelectedAccessibleRows, clsInfo, "getSelectedAccessibleRows", "()[I", nil);
jintArray selectedRowNumbers = (*env)->CallObjectMethod(env, axContext, jm_getSelectedAccessibleRows);
(*env)->DeleteLocalRef(env, axContext);
if (selectedRowNumbers == NULL) {
return nil;
}
jsize arrayLen = (*env)->GetArrayLength(env, selectedRowNumbers);
jint *indexsis = (*env)->GetIntArrayElements(env, selectedRowNumbers, 0);
NSMutableArray<NSNumber *> *nsArraySelectedRowNumbers = [NSMutableArray<NSNumber *> arrayWithCapacity:arrayLen];
for (int i = 0; i < arrayLen; i++) {
[nsArraySelectedRowNumbers addObject:[NSNumber numberWithInt:indexsis[i]]];
}
(*env)->DeleteLocalRef(env, selectedRowNumbers);
return [NSArray<NSNumber *> arrayWithArray:nsArraySelectedRowNumbers];
}
if (fAccessible == NULL) return 0;

- (NSArray<NSNumber *> *)selectedAccessibleColumns
{
JNIEnv *env = [ThreadUtilities getJNIEnv];
jobject axContext = [self axContextWithEnv:env];
if (axContext == NULL) return nil;
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getSelectedAccessibleColumns, clsInfo, "getSelectedAccessibleColumns", "()[I", nil);
jintArray selectedColumnNumbers = (*env)->CallObjectMethod(env, axContext, jm_getSelectedAccessibleColumns);
(*env)->DeleteLocalRef(env, axContext);
if (selectedColumnNumbers == NULL) {
JNIEnv* env = [ThreadUtilities getJNIEnv];
GET_CACCESSIBILITY_CLASS_RETURN(nil);
DECLARE_STATIC_METHOD_RETURN(jm_getTableSelectedInfo, sjc_CAccessibility, "getTableSelectedInfo",
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I", nil);
jintArray selected = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, jm_getTableSelectedInfo, fAccessible,
fComponent, info);
CHECK_EXCEPTION();
if (selected == NULL) {
return nil;
}
jsize arrayLen = (*env)->GetArrayLength(env, selectedColumnNumbers);
jint *indexsis = (*env)->GetIntArrayElements(env, selectedColumnNumbers, 0);
NSMutableArray<NSNumber *> *nsArraySelectedColumnNumbers = [NSMutableArray<NSNumber *> arrayWithCapacity:arrayLen];
jsize arrayLen = (*env)->GetArrayLength(env, selected);
jint *indexsis = (*env)->GetIntArrayElements(env, selected, 0);
NSMutableArray<NSNumber *> *nsArraySelected = [NSMutableArray<NSNumber *> arrayWithCapacity:arrayLen];
for (int i = 0; i < arrayLen; i++) {
[nsArraySelectedColumnNumbers addObject:[NSNumber numberWithInt:indexsis[i]]];
[nsArraySelected addObject:[NSNumber numberWithInt:indexsis[i]]];
}
(*env)->DeleteLocalRef(env, selectedColumnNumbers);
return [NSArray<NSNumber *> arrayWithArray:nsArraySelectedColumnNumbers];
(*env)->DeleteLocalRef(env, selected);
return [NSArray<NSNumber *> arrayWithArray:nsArraySelected];
}

- (int)accessibleRowAtIndex:(int)index
@@ -110,6 +93,7 @@ - (int)accessibleRowAtIndex:(int)index
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getAccessibleRowAtIndex, clsInfo, "getAccessibleRowAtIndex", "(I)I", -1);
jint rowAtIndex = (*env)->CallIntMethod(env, axContext, jm_getAccessibleRowAtIndex, (jint)index);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, axContext);
return (int)rowAtIndex;
}
@@ -122,6 +106,7 @@ - (int)accessibleColumnAtIndex:(int)index
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_getAccessibleColumnAtIndex, clsInfo, "getAccessibleColumnAtIndex", "(I)I", -1);
jint columnAtIndex = (*env)->CallIntMethod(env, axContext, jm_getAccessibleColumnAtIndex, (jint)index);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, axContext);
return (int)columnAtIndex;
}
@@ -134,6 +119,7 @@ - (BOOL) isAccessibleChildSelectedFromIndex:(int)index
jclass clsInfo = (*env)->GetObjectClass(env, axContext);
DECLARE_METHOD_RETURN(jm_isAccessibleChildSelected, clsInfo, "isAccessibleChildSelected", "(I)Z", NO);
jboolean isAccessibleChildSelected = (*env)->CallIntMethod(env, axContext, jm_isAccessibleChildSelected, (jint)index);
CHECK_EXCEPTION();
(*env)->DeleteLocalRef(env, axContext);
return isAccessibleChildSelected;
}
@@ -142,12 +128,7 @@ - (BOOL) isAccessibleChildSelectedFromIndex:(int)index

- (NSArray *)accessibilityChildren
{
NSArray *children = [self accessibilityRows];
NSArray *columns = [self accessibilityColumns];
NSMutableArray *results = [NSMutableArray arrayWithCapacity:[children count] + [columns count]];
[results addObjectsFromArray:children];
[results addObjectsFromArray:columns];
return [NSArray arrayWithArray:results];
return [self accessibilityRows];
}

- (NSArray *)accessibilitySelectedChildren
@@ -157,7 +138,7 @@ - (NSArray *)accessibilitySelectedChildren

- (NSArray *)accessibilityRows
{
int rowCount = [self accessibleRowCount];
int rowCount = [self accessibilityRowCount];
NSMutableArray *children = [NSMutableArray arrayWithCapacity:rowCount];
for (int i = 0; i < rowCount; i++) {
[children addObject:[[TableRowAccessibility alloc] initWithParent:self
@@ -172,7 +153,7 @@ - (NSArray *)accessibilityRows

- (nullable NSArray<id<NSAccessibilityRow>> *)accessibilitySelectedRows
{
NSArray<NSNumber *> *selectedRowIndexses = [self selectedAccessibleRows];
NSArray<NSNumber *> *selectedRowIndexses = [self getTableSelectedInfo:JAVA_AX_ROWS];
NSMutableArray *children = [NSMutableArray arrayWithCapacity:[selectedRowIndexses count]];
for (NSNumber *index in selectedRowIndexses) {
[children addObject:[[TableRowAccessibility alloc] initWithParent:self
@@ -202,7 +183,7 @@ - (id)accessibilityParent

- (nullable NSArray *)accessibilityColumns
{
int colCount = [self accessibleColCount];
int colCount = [self accessibilityColumnCount];
NSMutableArray *columns = [NSMutableArray arrayWithCapacity:colCount];
for (int i = 0; i < colCount; i++) {
[columns addObject:[[ColumnAccessibility alloc] initWithParent:self
@@ -217,7 +198,7 @@ - (nullable NSArray *)accessibilityColumns

- (nullable NSArray *)accessibilitySelectedColumns
{
NSArray<NSNumber *> *indexes = [self selectedAccessibleColumns];
NSArray<NSNumber *> *indexes = [self getTableSelectedInfo:JAVA_AX_COLS];
NSMutableArray *columns = [NSMutableArray arrayWithCapacity:[indexes count]];
for (NSNumber *i in indexes) {
[columns addObject:[[ColumnAccessibility alloc] initWithParent:self
@@ -230,16 +211,29 @@ - (nullable NSArray *)accessibilitySelectedColumns
return [NSArray arrayWithArray:columns];
}

/* Other optional NSAccessibilityTable Methods
- (nullable NSArray<id<NSAccessibilityRow>> *)accessibilityVisibleRows;
- (nullable NSArray *)accessibilityColumns;
- (nullable NSArray *)accessibilitySelectedColumns;
- (nullable NSArray *)accessibilityVisibleColumns;
- (NSInteger)accessibilityRowCount
{
return [[self getTableInfo:JAVA_AX_ROWS] integerValue];
}

- (nullable NSArray *)accessibilitySelectedCells;
- (nullable NSArray *)accessibilityVisibleCells;
- (nullable NSArray *)accessibilityRowHeaderUIElements;
- (nullable NSArray *)accessibilityColumnHeaderUIElements;
*/
- (NSInteger)accessibilityColumnCount
{
return [[self getTableInfo:JAVA_AX_COLS] integerValue];
}

- (nullable NSArray *)accessibilitySelectedCells;
{
NSArray *children = [super accessibilitySelectedChildren];
NSMutableArray *cells = [NSMutableArray arrayWithCapacity:[children count]];
for (CommonComponentAccessibility *child in children) {
[cells addObject:[[CellAccessibility alloc] initWithParent:self
withEnv:[ThreadUtilities getJNIEnv]
withAccessible:child->fAccessible
withIndex:child->fIndex
withView:fView
withJavaRole:child->fJavaRole]];
}
return [NSArray arrayWithArray:cells];
}

@end
@@ -52,11 +52,6 @@ - (NSAccessibilitySubrole)accessibilitySubrole
return NSAccessibilityTableRowSubrole;
}

- (BOOL)isAccessibilityEnabled
{
return YES;
}

- (NSArray *)accessibilityChildren
{
NSArray *children = [super accessibilityChildren];
@@ -73,9 +68,9 @@ - (NSArray *)accessibilityChildren
jsize arrayLen = (*env)->GetArrayLength(env, jchildrenAndRoles);
NSMutableArray *childrenCells = [NSMutableArray arrayWithCapacity:arrayLen/2];

NSUInteger childIndex = [self rowNumberInTable] * [(TableAccessibility *)parent accessibleColCount];
NSUInteger childIndex = [self rowNumberInTable] * [(TableAccessibility *)parent accessibilityColumnCount];
NSInteger i = childIndex * 2;
NSInteger n = ([self rowNumberInTable] + 1) * [(TableAccessibility *)parent accessibleColCount] * 2;
NSInteger n = ([self rowNumberInTable] + 1) * [(TableAccessibility *)parent accessibilityColumnCount] * 2;
for(i; i < n; i+=2)
{
jobject /* Accessible */ jchild = (*env)->GetObjectArrayElement(env, jchildrenAndRoles, i);
@@ -97,7 +92,7 @@ - (NSArray *)accessibilityChildren
withIndex:childIndex
withView:self->fView
withJavaRole:childJavaRole];
[childrenCells addObject:[child autorelease]];
[childrenCells addObject:[[child retain] autorelease]];

(*env)->DeleteLocalRef(env, jchild);
(*env)->DeleteLocalRef(env, jchildJavaRole);
@@ -113,7 +108,7 @@ - (NSArray *)accessibilityChildren

- (NSInteger)accessibilityIndex
{
return [[self accessibilityParent] accessibilityIndexOfChild:self];
return self->fIndex;
}

- (NSString *)accessibilityLabel