8256108: Create implementation for NSAccessibilityElement protocol peer

Reviewed-by: serb
This commit is contained in:
Alexander Zuev 2020-11-20 04:10:09 +00:00
parent 68138893a5
commit 4c095252a5

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
@ -127,6 +127,23 @@ static NSObject *sAttributeNamesLOCK = nil;
@end
// In order to use a new NSAccessibility API and since our components
// are represented as a custom UI elements we need to implement a set
// of custom protocols. Definitions of these protocols will start here.
// This is a root interface in the NSAccessibility* protocols hierarchy
// and all the component-specific protocols should be derived from it.
// It is also a place for the functions that might be exposed by all the
// component accessibility peers.
// Please see https://developer.apple.com/documentation/appkit/nsaccessibilityprotocol
// for more details.
@interface CommonComponentAccessibility : JavaComponentAccessibility <NSAccessibilityElement> {
}
- (NSRect)accessibilityFrame;
- (nullable id)accessibilityParent;
@end
@implementation JavaComponentAccessibility
- (NSString *)description
@ -1917,6 +1934,32 @@ static BOOL ObjectEquals(JNIEnv *env, jobject a, jobject b, jobject component);
}
@end
@implementation CommonComponentAccessibility
// 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;
NSRect retval = NSMakeRect(point.x, point.y, size.width, size.height);
return retval;
}
- (nullable id)accessibilityParent
{
return [self accessibilityParentAttribute];
}
@end
/*
* Returns Object.equals for the two items
* This may use LWCToolkit.invokeAndWait(); don't call while holding fLock