Skip to content

Commit

Permalink
Moved the new components implementations to the separate files.
Browse files Browse the repository at this point in the history
Changed the iitialization procedure to a class function with
dictionary of role to class name relation.

This pr is still intermittent since it uses the old style
JNF java call syntacsis. Once fix for JDK-8257853 is integrated
the calls needs to be converted to the new style but that is a minor
change.
  • Loading branch information
azuev-java committed Dec 16, 2020
1 parent 25022d2 commit 07f2093
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 87 deletions.
Expand Up @@ -30,6 +30,7 @@
// <http://archives.java.sun.com/archives/java-access.html> (Sun's mailing list for Java accessibility)

#import "JavaComponentAccessibility.h"
#import "a11y/CommonComponentAccessibility.h"

#import "sun_lwawt_macosx_CAccessibility.h"

Expand Down Expand Up @@ -127,33 +128,6 @@ - (NSArray *)accessibilityRowsAttribute;
- (NSArray *)accessibilityColumnsAttribute;
@end


// In order to use a new NSAccessibility API and since our components
// are represented as a custom UI elements we need to implement a set
// of custom protocols. Definitions of these protocols will start here.

// This is a root interface in the NSAccessibility* protocols hierarchy
// and all the component-specific protocols should be derived from it.
// It is also a place for the functions that might be exposed by all the
// component accessibility peers.
// Please see https://developer.apple.com/documentation/appkit/nsaccessibilityprotocol
// for more details.
@interface CommonComponentAccessibility : JavaComponentAccessibility <NSAccessibilityElement> {

}
- (NSRect)accessibilityFrame;
- (nullable id)accessibilityParent;
@end

// Declaration of a NSAccessibilityButton protocol implementation for a puchbutton
// accessibility role
@interface ButtonAccessibility : CommonComponentAccessibility <NSAccessibilityButton> {

}
- (nullable NSString *)accessibilityLabel;
- (BOOL)accessibilityPerformPress;
@end

@implementation JavaComponentAccessibility

- (NSString *)description
Expand Down Expand Up @@ -410,20 +384,23 @@ + (JavaComponentAccessibility *) createWithParent:(JavaComponentAccessibility *)

// otherwise, create a new instance
JavaComponentAccessibility *newChild = nil;
if ([javaRole isEqualToString:@"pagetablist"]) {
newChild = [TabGroupAccessibility alloc];
} else if ([javaRole isEqualToString:@"table"]) {
newChild = [TableAccessibility alloc];
} else if ([javaRole isEqualToString:@"scrollpane"]) {
newChild = [ScrollAreaAccessibility alloc];
} else if ([javaRole isEqualToString:@"pushbutton"]) {
newChild = [ButtonAccessibility alloc];
} else {
NSString *nsRole = [sRoles objectForKey:javaRole];
if ([nsRole isEqualToString:NSAccessibilityStaticTextRole] || [nsRole isEqualToString:NSAccessibilityTextAreaRole] || [nsRole isEqualToString:NSAccessibilityTextFieldRole]) {
newChild = [JavaTextAccessibility alloc];
newChild = [CommonComponentAccessibility getComponentAccessibility:javaRole];
if (newChild == nil) {
if ([javaRole isEqualToString:@"pagetablist"]) {
newChild = [TabGroupAccessibility alloc];
} else if ([javaRole isEqualToString:@"table"]) {
newChild = [TableAccessibility alloc];
} else if ([javaRole isEqualToString:@"scrollpane"]) {
newChild = [ScrollAreaAccessibility alloc];
} else {
newChild = [JavaComponentAccessibility alloc];
NSString *nsRole = [sRoles objectForKey:javaRole];
if ([nsRole isEqualToString:NSAccessibilityStaticTextRole]
|| [nsRole isEqualToString:NSAccessibilityTextAreaRole]
|| [nsRole isEqualToString:NSAccessibilityTextFieldRole]) {
newChild = [JavaTextAccessibility alloc];
} else {
newChild = [JavaComponentAccessibility alloc];
}
}
}

Expand Down Expand Up @@ -1946,53 +1923,6 @@ - (id)accessibilityColumnCountAttribute {
}
@end

@implementation CommonComponentAccessibility
// NSAccessibilityElement protocol implementation
- (NSRect)accessibilityFrame
{
JNIEnv* env = [ThreadUtilities getJNIEnv];
jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent,
fAccessible, fComponent);

NSSize size = getAxComponentSize(env, axComponent, fComponent);
NSPoint point = getAxComponentLocationOnScreen(env, axComponent, fComponent);
(*env)->DeleteLocalRef(env, axComponent);
point.y += size.height;

point.y = [[[[self view] window] screen] frame].size.height - point.y;

NSRect retval = NSMakeRect(point.x, point.y, size.width, size.height);
return retval;
}

- (nullable id)accessibilityParent
{
return [self accessibilityParentAttribute];
}

@end


/*
* Implementation of the NSAccessibilityButton protocol
*/
@implementation ButtonAccessibility
- (nullable NSString *)accessibilityLabel
{
return [self accessibilityTitleAttribute];
}

- (BOOL)accessibilityPerformPress
{
AWT_ASSERT_APPKIT_THREAD;

JNIEnv* env = [ThreadUtilities getJNIEnv];
JNFCallStaticVoidMethod(env, jm_doAccessibleAction, [self axContextWithEnv:(env)], 0, fComponent);
return TRUE;
}

@end

/*
* Returns Object.equals for the two items
* This may use LWCToolkit.invokeAndWait(); don't call while holding fLock
Expand Down
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2020, 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 ButtonAccessibility : CommonComponentAccessibility <NSAccessibilityButton> {

};
- (nullable NSString *)accessibilityLabel;
- (BOOL)accessibilityPerformPress;
@end
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020, 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.
*/

#include "ButtonAccessibility.h"
#import "ThreadUtilities.h"

static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility,"doAccessibleAction","(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V");

/*
* Implementation of the accessibility peer for the pushbutton role
*/
@implementation ButtonAccessibility
- (nullable NSString *)accessibilityLabel
{
return [self accessibilityTitleAttribute];
}

- (BOOL)accessibilityPerformPress
{
AWT_ASSERT_APPKIT_THREAD;

JNIEnv* env = [ThreadUtilities getJNIEnv];
JNFCallStaticVoidMethod(env, jm_doAccessibleAction, [self axContextWithEnv:(env)], 0, fComponent);
return TRUE;
}

@end
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2020, 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.
*/

#ifndef JAVA_COMPONENT_ACCESSIBILITY
#define JAVA_COMPONENT_ACCESSIBILITY

#import "JavaComponentAccessibility.h"
#import "JavaAccessibilityUtilities.h"

@interface CommonComponentAccessibility : JavaComponentAccessibility <NSAccessibilityElement> {

}
+ (void) initializeRolesMap;
+ (JavaComponentAccessibility * _Nullable) getComponentAccessibility:(NSString * _Nonnull)role;
- (NSRect)accessibilityFrame;
- (nullable id)accessibilityParent;
@end

#endif
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2020, 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 "CommonComponentAccessibility.h"
#import "ThreadUtilities.h"

static JNF_STATIC_MEMBER_CACHE(sjm_getAccessibleComponent, sjc_CAccessibility, "getAccessibleComponent", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;");
static NSMutableDictionary * _Nullable rolesMap;

/*
* Common ancestor for all the accessibility peers that implements the new method-based accessibility API
*/
@implementation CommonComponentAccessibility

+ (void) initializeRolesMap {
/*
* Here we should keep all the mapping between the accessibility roles and implementing classes
*/
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:1];

[rolesMap setObject:@"ButtonAccessibility" forKey:@"pushbutton"];
}

/*
* If new implementation of the accessible component peer for the given role exists
* return the allocated class otherwise return nil to let old implementation being initialized
*/
+ (JavaComponentAccessibility *) getComponentAccessibility:(NSString *)role
{
if (rolesMap == nil) {
[self initializeRolesMap];
}

NSString *className = [rolesMap objectForKey:role];
if (className != nil) {
return [NSClassFromString(className) alloc];
}
return nil;
}

// NSAccessibilityElement protocol implementation
- (NSRect)accessibilityFrame
{
JNIEnv* env = [ThreadUtilities getJNIEnv];
jobject axComponent = JNFCallStaticObjectMethod(env, sjm_getAccessibleComponent,
fAccessible, fComponent);

NSSize size = getAxComponentSize(env, axComponent, fComponent);
NSPoint point = getAxComponentLocationOnScreen(env, axComponent, fComponent);
(*env)->DeleteLocalRef(env, axComponent);
point.y += size.height;

point.y = [[[[self view] window] screen] frame].size.height - point.y;

return NSMakeRect(point.x, point.y, size.width, size.height);
}

- (nullable id)accessibilityParent
{
return [self accessibilityParentAttribute];
}

@end

0 comments on commit 07f2093

Please sign in to comment.