Skip to content

Commit

Permalink
8343133: Create implementation of NSAccessibilityStepper protocol
Browse files Browse the repository at this point in the history
Initial implementation with a lot of debugging output
  • Loading branch information
azuev-java committed Jan 6, 2025
1 parent bee1277 commit 0a6a0c5
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ protected long getNativeAccessible() {
if (this.peer == 0L) {
AccessibleRole role = (AccessibleRole) getAttribute(ROLE);
if (role == null) role = AccessibleRole.NODE;
// System.out.println("Creating peer for " + role.toString());
this.peer = _createAccessiblePeer(role.toString());
if (this.peer == 0L) {
throw new RuntimeException("could not create platform accessible");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ - (id)initWithEnv:(JNIEnv*)env accessible:(jobject)acc
if (self != nil) {
self->jAccessible = (*env)->NewGlobalRef(env, acc);
}
NSLog(@"Initializing with role %@", [self accessibilityAttributeValueImpl:@"AXRole"]);
if ([@"AXStaticText" isEqualToString:[self accessibilityAttributeValueImpl:@"AXRole"]]) {
NSLog(@"%@", NSThread.callStackSymbols);
}
return self;
}

Expand Down Expand Up @@ -69,6 +73,11 @@ - (NSArray *)accessibilityAttributeNames
}

- (id)accessibilityAttributeValue:(NSString *)attribute
{
return [self accessibilityAttributeValueImpl:attribute];
}

- (id)accessibilityAttributeValueImpl:(NSString *)attribute
{
jobject jresult = NULL;
GET_MAIN_JENV;
Expand Down Expand Up @@ -204,6 +213,7 @@ - (id)accessibilityHitTest:(NSPoint)point
if (env == NULL) return NULL;
result = (id)(*env)->CallLongMethod(env, self->jAccessible, jAccessibilityHitTest, point.x, point.y);
GLASS_CHECK_EXCEPTION(env);
NSLog(@"accessibilityHitTest(%@) returns %@", [NSValue valueWithPoint:point], result);
return result;
}

Expand All @@ -222,6 +232,15 @@ - (BOOL)accessibilityNotifiesWhenDestroyed
return YES;
}

- (NSString *)roleAndValue
{
NSString *retVal = [NSString stringWithFormat:@"Old Role: %@ Value:%@",
[self accessibilityAttributeValueImpl:@"AXRole"],
[self accessibilityAttributeValueImpl:@"AXValue"]];
return retVal;
}


@end

NSArray* jArrayToNSArray(JNIEnv *env, jarray srcArray, jMapper mapper) {
Expand Down Expand Up @@ -686,6 +705,7 @@ id variantToID(JNIEnv *env, jobject variant) {
JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacAccessible_NSAccessibilityPostNotification
(JNIEnv *env, jclass jClass, jlong element, jlong notification)
{
NSLog(@"Posting notification on %@ about %@", (id)jlong_to_ptr(element), (NSString*)jlong_to_ptr(notification));
NSAccessibilityPostNotification((id)jlong_to_ptr(element), (NSString*)jlong_to_ptr(notification));
}

Expand Down Expand Up @@ -724,6 +744,7 @@ id variantToID(JNIEnv *env, jobject variant) {
JNIEXPORT jobject JNICALL Java_com_sun_glass_ui_mac_MacAccessible_GlassAccessibleToMacAccessible
(JNIEnv *env, jclass jClass, jlong glassAccessible)
{
NSLog(@"GlassAccessibleToMacAccessible for %@", (id)jlong_to_ptr(glassAccessible));
GlassAccessible* accessible = (GlassAccessible*)jlong_to_ptr(glassAccessible);
return accessible ? [accessible getJAccessible] : NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@
#import <Cocoa/Cocoa.h>
#import <jni.h>

#define EmptyRange NSMakeRange(0, 0);

@interface AccessibleBase : NSAccessibilityElement {
@private
jobject jAccessible;
id parent;
id jRole;
}
- (id)initWithEnv:(JNIEnv*)env accessible:(jobject)jAccessible;
- (jobject)getJAccessible;
- (NSString *)getJavaRole;
- (NSRect)accessibilityFrame;
- (id)accessibilityParent;
- (NSArray *)accessibilityChildren;
- (BOOL)isAccessibilityElement;
- (BOOL)performAccessibleAction:(NSString*)actionId;
+ (void) initializeRolesMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (void) initializeRolesMap {
* All JavaFX roles and corresponding available properties are defined in
* enum javafx.scene.AccessibleRole
*/
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:9];
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:11];

[rolesMap setObject:@"JFXButtonAccessibility" forKey:@"BUTTON"];
[rolesMap setObject:@"JFXButtonAccessibility" forKey:@"DECREMENT_BUTTON"];
Expand All @@ -53,7 +53,8 @@ + (void) initializeRolesMap {
[rolesMap setObject:@"JFXCheckboxAccessibility" forKey:@"CHECK_BOX"];
[rolesMap setObject:@"JFXCheckboxAccessibility" forKey:@"TOGGLE_BUTTON"];
[rolesMap setObject:@"JFXStaticTextAccessibility" forKey:@"TEXT"];

[rolesMap setObject:@"JFXNavigableTextAccessibility" forKey:@"TEXT_FIELD"];
[rolesMap setObject:@"JFXNavigableTextAccessibility" forKey:@"TEXT_AREA"];
}

+ (Class) getComponentAccessibilityClass:(NSString *)role
Expand All @@ -62,6 +63,8 @@ + (Class) getComponentAccessibilityClass:(NSString *)role
[self initializeRolesMap];
}

NSLog(@"Role requested: %@", role);

NSString *className = [rolesMap objectForKey:role];
if (className != nil) {
return NSClassFromString(className);
Expand Down Expand Up @@ -95,6 +98,16 @@ - (jobject)getJAccessible
return self->jAccessible;
}

- (NSString *)getJavaRole
{
return self->jRole;
}

- (void)setJavaRole:(NSString *)newRole
{
self->jRole = [newRole copy];
}

- (id)accessibilityValue
{
jobject jresult = NULL;
Expand Down Expand Up @@ -129,6 +142,27 @@ - (id)accessibilityParent
return parent;
}

- (NSArray *)accessibilityChildren
{
NSLog(@"%@ requesting children list", [self accessibilityRole]);
jobject jresult = NULL;
GET_MAIN_JENV;
if (env == NULL) return NULL;
jresult = (jobject)(*env)->CallLongMethod(env, self->jAccessible, jAccessibilityAttributeValue,
(jlong) @"AXChildren");
GLASS_CHECK_EXCEPTION(env);
NSArray * result = variantToID(env, jresult);
for (int i = 0; i < [result count]; i++) {
if ([result[i] respondsToSelector:@selector(roleAndValue)]) {
NSLog(@"child[%d] = %@", i, [result[i] roleAndValue]);
} else {
NSLog(@"child[%d] = %@", i, result[i]);
}
}

return result;
}

// Actions support
- (BOOL)performAccessibleAction:(NSString *)action
{
Expand Down Expand Up @@ -192,6 +226,29 @@ - (void)setAccessibilityFocused:(BOOL)value
GLASS_CHECK_EXCEPTION(env);
}

- (id)accessibilityHitTest:(NSPoint)point
{
id result = NULL;
GET_MAIN_JENV;
if (env == NULL) return NULL;
result = (id)(*env)->CallLongMethod(env, self->jAccessible, jAccessibilityHitTest, point.x, point.y);
GLASS_CHECK_EXCEPTION(env);
NSLog(@"NEW!!! accessibilityHitTest(%@) returns %@", [NSValue valueWithPoint:point], result);
return result;
}

/*
* Debug related methods
*/

- (NSString *)roleAndValue
{
NSString *retVal = [NSString stringWithFormat:@"New Role: %@ Value:%@",
[self accessibilityRole],
[self accessibilityValue]];
return retVal;
}

@end

/*
Expand All @@ -206,6 +263,9 @@ - (void)setAccessibilityFocused:(BOOL)value
Class classType = [AccessibleBase getComponentAccessibilityClass:roleName];
NSObject* accessible = NULL;
accessible = [[classType alloc] initWithEnv: env accessible: jAccessible];
if ([accessible isKindOfClass:[AccessibleBase class]]) {
[(AccessibleBase *)accessible setJavaRole:roleName];
}
return ptr_to_jlong(accessible);
}

Expand Down Expand Up @@ -248,3 +308,6 @@ - (void)setAccessibilityFocused:(BOOL)value
[((AccessibleBase*) accessible) clearParent];
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, 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 "AccessibleBase.h"
#import <AppKit/NSAccessibility.h>
//#import "JFXStaticTextAccessibility.h"

@interface JFXNavigableTextAccessibility : AccessibleBase<NSAccessibilityNavigableStaticText> {

};
- (NSAccessibilityRole)accessibilityRole;
- (NSAccessibilitySubrole)accessibilitySubrole;
- (BOOL)isAccessibilityEnabled;
- (NSArray *)accessibilitySharedFocusElements;
- (BOOL)isAccessibilityEdited;
- (NSArray *)accessibilityChildren;
- (NSString *)accessibilityValue;
- (NSRange)accessibilitySelectedTextRange;
//- (NSString *)accessibilitySelectedText;
- (NSRange)accessibilityVisibleCharacterRange;
- (NSAttributedString *) accessibilityAttributedStringForRange:(NSRange)range;
- (NSInteger)accessibilityNumberOfCharacters;
@end
Loading

0 comments on commit 0a6a0c5

Please sign in to comment.