-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8256109: Create implementation for NSAccessibilityButton protocol #1549
Changes from 15 commits
9165a35
13ff8dd
3768434
1542576
16e32da
25022d2
e0a801c
07f2093
0a321da
e547a1a
0c2927a
d9d6f75
1a31c1b
38d54d0
22fe753
0b20893
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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 | ||
{ | ||
if (rolesMap == nil) { | ||
[self initializeRolesMap]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that this will be called on the different threads? Or it is always appkit(probably AWT_ASSERT_APPKIT_THREAD could be useful)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this method is being called from AppKit thread only but giving that it is static and public adding an assertion would be indeed wise. Fixed. |
||
} | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no header guard here. Is it left intentionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since the CommonComponentAccessibility being imported from the base class sometimes it causes compilation glitches - guess ObjC is not a big fan of forward-declaration. Adding header guard helps. And since i'm not planning to include sub-component header files in the base classes the ifdef guard is not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The headers in the obj-c usually do not have guards because they are included via "#import"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. But in this case that was not enough - that still caused weird compilation glitches like full compilation works but incremental calculation gives compilation error about usage of non-initialized variables. Guards helped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed where the guards have helped, there are no guards in this file.
Same question about why did you add guards to the "CommonComponentAccessibility.h"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added guards into CommonComponentAccessibility.h because without them importing them into JavaComponentAccessibility from which CommonComponentAccessibility is inherited creates intermittent build failures. I used ifdef guards and the problem was gone so i kept them. I do not include any of the implementing classes headers down the inheritance three so i decided not to add guards there.