Skip to content

Commit 05548ac

Browse files
Alexander Zuevkevinrushforth
authored andcommitted
8301312: Create implementation of NSAccessibilityButton protocol
Reviewed-by: kcr, arapte
1 parent 10f41b7 commit 05548ac

File tree

7 files changed

+380
-49
lines changed

7 files changed

+380
-49
lines changed

buildSrc/mac.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ MAC.glass.javahInclude = [
184184
"com/sun/glass/events/**",
185185
"com/sun/glass/ui/*",
186186
"com/sun/glass/ui/mac/*"]
187-
MAC.glass.nativeSource = file("${project("graphics").projectDir}/src/main/native-glass/mac")
187+
MAC.glass.nativeSource = [file("${project("graphics").projectDir}/src/main/native-glass/mac"),
188+
file("${project("graphics").projectDir}/src/main/native-glass/mac/a11y")]
188189
MAC.glass.compiler = compiler
189190
MAC.glass.ccFlags = [ccFlags,
190191
"-DMACOS_MIN_VERSION_MAJOR=$macOSMinVersionMajor",

modules/javafx.graphics/src/main/java/com/sun/glass/ui/mac/MacAccessible.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -643,11 +643,14 @@ private static enum MacText {
643643
/* The native peer associated with the instance */
644644
private long peer;
645645

646-
/* Creates a GlassAccessible linked to the caller (GlobalRef) */
647-
private native long _createGlassAccessible();
646+
/* Creates a native accessible peer linked to the caller (GlobalRef) */
647+
private native long _createAccessiblePeer(String forRole);
648648

649-
/* Releases the GlassAccessible and deletes the GlobalRef */
650-
private native void _destroyGlassAccessible(long accessible);
649+
/* Releases the native accessible peer and deletes the GlobalRef */
650+
private native void _destroyAccessiblePeer(long accessible);
651+
652+
/* Notify accessible peer about hierarchy change to invalidate parent */
653+
private native void _invalidateParent(long accessible);
651654

652655
private static native String getString(long nsString);
653656
private static native boolean isEqualToString(long nsString1, long nsString);
@@ -665,10 +668,6 @@ private static enum MacText {
665668
private static final int kAXMenuItemModifierNoCommand = (1 << 3);
666669

667670
MacAccessible() {
668-
this.peer = _createGlassAccessible();
669-
if (this.peer == 0L) {
670-
throw new RuntimeException("could not create platform accessible");
671-
}
672671
}
673672

674673
@Override
@@ -677,7 +676,7 @@ public void dispose() {
677676
if (getView() == null) {
678677
NSAccessibilityPostNotification(peer, MacNotification.NSAccessibilityUIElementDestroyedNotification.ptr);
679678
}
680-
_destroyGlassAccessible(peer);
679+
_destroyAccessiblePeer(peer);
681680
peer = 0L;
682681
}
683682
super.dispose();
@@ -803,20 +802,32 @@ public void sendNotification(AccessibleAttribute notification) {
803802
}
804803
break;
805804
case PARENT:
805+
if (peer != 0L) {
806+
_invalidateParent(peer);
807+
}
806808
ignoreInnerText = null;
807809
break;
808810
default:
809811
macNotification = MacNotification.NSAccessibilityValueChangedNotification;
810812
}
811813
if (macNotification != null) {
812814
View view = getView();
813-
long id = view != null ? view.getNativeView() : peer;
815+
long id = view != null ? view.getNativeView() : getNativeAccessible();
814816
NSAccessibilityPostNotification(id, macNotification.ptr);
815817
}
816818
}
817819

818820
@Override
819821
protected long getNativeAccessible() {
822+
if (this.peer == 0L) {
823+
AccessibleRole role = (AccessibleRole) getAttribute(ROLE);
824+
if (role == null) role = AccessibleRole.NODE;
825+
this.peer = _createAccessiblePeer(role.toString());
826+
if (this.peer == 0L) {
827+
throw new RuntimeException("could not create platform accessible");
828+
}
829+
}
830+
820831
return peer;
821832
}
822833

modules/javafx.graphics/src/main/native-glass/mac/GlassAccessible.m

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -520,31 +520,6 @@ id variantToID(JNIEnv *env, jobject variant) {
520520
jVariantToID = NULL;
521521
}
522522

523-
/*
524-
* Class: com_sun_glass_ui_mac_MacAccessible
525-
* Method: _createGlassAccessible
526-
* Signature: ()J
527-
*/
528-
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacAccessible__1createGlassAccessible
529-
(JNIEnv *env, jobject jAccessible)
530-
{
531-
GlassAccessible* accessible = NULL;
532-
accessible = [[GlassAccessible alloc] initWithEnv: env accessible: jAccessible];
533-
return ptr_to_jlong(accessible);
534-
}
535-
536-
/*
537-
* Class: com_sun_glass_ui_mac_MacAccessible
538-
* Method: _destroyGlassAccessible
539-
* Signature: (J)V
540-
*/
541-
JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacAccessible__1destroyGlassAccessible
542-
(JNIEnv *env, jobject jAccessible, jlong macAccessible)
543-
{
544-
GlassAccessible* accessible = (GlassAccessible*)jlong_to_ptr(macAccessible);
545-
[accessible release];
546-
}
547-
548523
/*
549524
* Class: com_sun_glass_ui_mac_MacAccessible
550525
* Method: idToMacVariant
@@ -652,18 +627,6 @@ id variantToID(JNIEnv *env, jobject variant) {
652627
return jVariant;
653628
}
654629

655-
/*
656-
* Class: com_sun_glass_ui_mac_MacAccessible
657-
* Method: NSAccessibilityUnignoredAncestor
658-
* Signature: (J)J
659-
*/
660-
JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacAccessible_NSAccessibilityUnignoredAncestor
661-
(JNIEnv *env, jclass jClass, jlong macAccessible)
662-
{
663-
GlassAccessible* accessible = (GlassAccessible*)jlong_to_ptr(macAccessible);
664-
return ptr_to_jlong(NSAccessibilityUnignoredAncestor(accessible));
665-
}
666-
667630
/*
668631
* Class: com_sun_glass_ui_mac_MacAccessible
669632
* Method: NSAccessibilityUnignoredChildren
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2023, 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 <Cocoa/Cocoa.h>
27+
#import <jni.h>
28+
29+
@interface AccessibleBase : NSAccessibilityElement {
30+
@private
31+
jobject jAccessible;
32+
id parent;
33+
}
34+
- (id)initWithEnv:(JNIEnv*)env accessible:(jobject)jAccessible;
35+
- (jobject)getJAccessible;
36+
- (NSRect)accessibilityFrame;
37+
- (id)accessibilityParent;
38+
- (BOOL)isAccessibilityElement;
39+
- (BOOL)performAccessibleAction:(jlong)actionId;
40+
+ (void) initializeRolesMap;
41+
@end
42+
43+
jmethodID jAccessibilityAttributeNames;

0 commit comments

Comments
 (0)