Skip to content

Commit 5dc5d94

Browse files
author
Alexander Zuev
committedJan 17, 2021
8256110: Create implementation for NSAccessibilityStepper protocol
Reviewed-by: pbansal, serb
1 parent 5f2e280 commit 5dc5d94

File tree

5 files changed

+116
-17
lines changed

5 files changed

+116
-17
lines changed
 

‎src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/ButtonAccessibility.m

+1-15
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
*/
2525

2626
#import "ButtonAccessibility.h"
27-
#import "JNIUtilities.h"
28-
#import "ThreadUtilities.h"
29-
30-
static jclass sjc_CAccessibility = NULL;
3127

3228
/*
3329
* Implementation of the accessibility peer for the pushbutton role
@@ -40,17 +36,7 @@ - (nullable NSString *)accessibilityLabel
4036

4137
- (BOOL)accessibilityPerformPress
4238
{
43-
AWT_ASSERT_APPKIT_THREAD;
44-
JNIEnv* env = [ThreadUtilities getJNIEnv];
45-
46-
GET_CACCESSIBILITY_CLASS_RETURN(FALSE);
47-
DECLARE_STATIC_METHOD_RETURN(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction",
48-
"(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V", FALSE);
49-
(*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction,
50-
[self axContextWithEnv:(env)], 0, fComponent);
51-
CHECK_EXCEPTION();
52-
53-
return TRUE;
39+
return [self performAccessibleAction:0];
5440
}
5541

5642
@end

‎src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
+ (JavaComponentAccessibility * _Nullable) getComponentAccessibility:(NSString * _Nonnull)role;
3737
- (NSRect)accessibilityFrame;
3838
- (nullable id)accessibilityParent;
39+
- (BOOL)performAccessibleAction:(int)index;
3940
@end
4041

4142
#endif

‎src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.m

+19-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ + (void) initializeRolesMap {
4646
/*
4747
* Here we should keep all the mapping between the accessibility roles and implementing classes
4848
*/
49-
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:3];
49+
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:4];
5050

5151
[rolesMap setObject:@"ButtonAccessibility" forKey:@"pushbutton"];
5252
[rolesMap setObject:@"ImageAccessibility" forKey:@"icon"];
5353
[rolesMap setObject:@"ImageAccessibility" forKey:@"desktopicon"];
54+
[rolesMap setObject:@"SpinboxAccessibility" forKey:@"spinbox"];
55+
5456
}
5557

5658
/*
@@ -60,7 +62,6 @@ + (void) initializeRolesMap {
6062
+ (JavaComponentAccessibility *) getComponentAccessibility:(NSString *)role
6163
{
6264
AWT_ASSERT_APPKIT_THREAD;
63-
6465
if (rolesMap == nil) {
6566
[self initializeRolesMap];
6667
}
@@ -97,4 +98,20 @@ - (nullable id)accessibilityParent
9798
return [self accessibilityParentAttribute];
9899
}
99100

101+
// AccessibleAction support
102+
- (BOOL)performAccessibleAction:(int)index
103+
{
104+
AWT_ASSERT_APPKIT_THREAD;
105+
JNIEnv* env = [ThreadUtilities getJNIEnv];
106+
107+
GET_CACCESSIBILITY_CLASS_RETURN(FALSE);
108+
DECLARE_STATIC_METHOD_RETURN(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction",
109+
"(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V", FALSE);
110+
(*env)->CallStaticVoidMethod(env, sjc_CAccessibility, jm_doAccessibleAction,
111+
[self axContextWithEnv:(env)], index, fComponent);
112+
CHECK_EXCEPTION();
113+
114+
return TRUE;
115+
}
116+
100117
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
#import "JavaComponentAccessibility.h"
27+
#import "CommonComponentAccessibility.h"
28+
29+
#import <AppKit/AppKit.h>
30+
31+
@interface SpinboxAccessibility : CommonComponentAccessibility <NSAccessibilityStepper> {
32+
33+
};
34+
35+
- (nullable NSString *)accessibilityLabel;
36+
- (nullable id)accessibilityValue;
37+
- (BOOL)accessibilityPerformDecrement;
38+
- (BOOL)accessibilityPerformIncrement;
39+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
#import "SpinboxAccessibility.h"
27+
28+
#define INCREMENT 0
29+
#define DECREMENT 1
30+
31+
/*
32+
* Implementation of the accessibility peer for the spinner role
33+
*/
34+
@implementation SpinboxAccessibility
35+
- (nullable NSString *)accessibilityLabel
36+
{
37+
return [self accessibilityTitleAttribute];
38+
}
39+
40+
- (nullable id)accessibilityValue
41+
{
42+
return [self accessibilityValueAttribute];
43+
}
44+
45+
- (BOOL)accessibilityPerformIncrement
46+
{
47+
return [self performAccessibleAction:INCREMENT];
48+
}
49+
50+
51+
- (BOOL)accessibilityPerformDecrement
52+
{
53+
return [self performAccessibleAction:DECREMENT];
54+
}
55+
56+
@end

0 commit comments

Comments
 (0)
Please sign in to comment.