Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved the new components implementations to the separate files.
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
1 parent
25022d2
commit 07f2093
Showing
5 changed files
with
228 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ButtonAccessibility.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
49 changes: 49 additions & 0 deletions
49
src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ButtonAccessibility.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
41 changes: 41 additions & 0 deletions
41
src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
85 changes: 85 additions & 0 deletions
85
src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |