8256109: Create implementation for NSAccessibilityButton protocol
Reviewed-by: prr, serb
This commit is contained in:
parent
5513f9893b
commit
ae9187d757
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 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
|
||||
@ -30,7 +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"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
@ -145,24 +145,6 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
- (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
|
||||
|
||||
@implementation JavaComponentAccessibility
|
||||
|
||||
- (NSString *)description
|
||||
@ -438,18 +420,23 @@ static NSObject *sAttributeNamesLOCK = nil;
|
||||
|
||||
// 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 {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2043,32 +2030,6 @@ static BOOL ObjectEquals(JNIEnv *env, jobject a, jobject b, jobject component);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation CommonComponentAccessibility
|
||||
// NSAccessibilityElement protocol implementation
|
||||
- (NSRect)accessibilityFrame
|
||||
{
|
||||
JNIEnv* env = [ThreadUtilities getJNIEnv];
|
||||
GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(NSZeroRect);
|
||||
jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility, sjm_getAccessibleComponent, fAccessible, fComponent);
|
||||
CHECK_EXCEPTION();
|
||||
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
|
||||
|
||||
/*
|
||||
* Returns Object.equals for the two items
|
||||
* This may use LWCToolkit.invokeAndWait(); don't call while holding fLock
|
||||
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 ButtonAccessibility : CommonComponentAccessibility <NSAccessibilityButton> {
|
||||
|
||||
};
|
||||
- (nullable NSString *)accessibilityLabel;
|
||||
- (BOOL)accessibilityPerformPress;
|
||||
@end
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 "ButtonAccessibility.h"
|
||||
#import "JNIUtilities.h"
|
||||
#import "ThreadUtilities.h"
|
||||
|
||||
static jclass sjc_CAccessibility = NULL;
|
||||
|
||||
/*
|
||||
* 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];
|
||||
|
||||
GET_CACCESSIBILITY_CLASS_RETURN(FALSE);
|
||||
DECLARE_STATIC_METHOD_RETURN(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction",
|
||||
"(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V", FALSE);
|
||||
(*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction,
|
||||
[self axContextWithEnv:(env)], 0, fComponent);
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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,98 @@
|
||||
/*
|
||||
* 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 "CommonComponentAccessibility.h"
|
||||
#import "JNIUtilities.h"
|
||||
#import "ThreadUtilities.h"
|
||||
|
||||
static jclass sjc_CAccessibility = NULL;
|
||||
static jmethodID sjm_getAccessibleComponent = NULL;
|
||||
|
||||
#define GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(ret) \
|
||||
GET_CACCESSIBILITY_CLASS_RETURN(ret); \
|
||||
GET_STATIC_METHOD_RETURN(sjm_getAccessibleComponent, sjc_CAccessibility, "getAccessibleComponent", \
|
||||
"(Ljavax/accessibility/Accessible;Ljava/awt/Component;)Ljavax/accessibility/AccessibleComponent;", ret);
|
||||
|
||||
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
|
||||
{
|
||||
AWT_ASSERT_APPKIT_THREAD;
|
||||
|
||||
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];
|
||||
GET_ACCESSIBLECOMPONENT_STATIC_METHOD_RETURN(NSZeroRect);
|
||||
jobject axComponent = (*env)->CallStaticObjectMethod(env, sjc_CAccessibility,
|
||||
sjm_getAccessibleComponent,
|
||||
fAccessible, fComponent);
|
||||
CHECK_EXCEPTION();
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user