1/* 2 * Copyright (c) 2011, 2016, 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 "JavaAccessibilityAction.h" 27#import "JavaAccessibilityUtilities.h" 28 29#import "ThreadUtilities.h" 30 31 32@implementation JavaAxAction 33 34- (id)initWithEnv:(JNIEnv *)env withAccessibleAction:(jobject)accessibleAction withIndex:(jint)index withComponent:(jobject)component 35{ 36 self = [super init]; 37 if (self) { 38 fAccessibleAction = JNFNewWeakGlobalRef(env, accessibleAction); 39 fIndex = index; 40 fComponent = JNFNewWeakGlobalRef(env, component); 41 } 42 return self; 43} 44 45- (void)dealloc 46{ 47 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 48 49 JNFDeleteWeakGlobalRef(env, fAccessibleAction); 50 fAccessibleAction = NULL; 51 52 JNFDeleteWeakGlobalRef(env, fComponent); 53 fComponent = NULL; 54 55 [super dealloc]; 56} 57 58 59- (NSString *)getDescription 60{ 61 static JNF_STATIC_MEMBER_CACHE(jm_getAccessibleActionDescription, sjc_CAccessibility, "getAccessibleActionDescription", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)Ljava/lang/String;"); 62 63 JNIEnv* env = [ThreadUtilities getJNIEnv]; 64 65 jobject fCompLocal = (*env)->NewLocalRef(env, fComponent); 66 if ((*env)->IsSameObject(env, fCompLocal, NULL)) { 67 return nil; 68 } 69 NSString *str = nil; 70 jstring jstr = JNFCallStaticObjectMethod( env, 71 jm_getAccessibleActionDescription, 72 fAccessibleAction, 73 fIndex, 74 fCompLocal ); 75 if (jstr != NULL) { 76 str = JNFJavaToNSString(env, jstr); // AWT_THREADING Safe (AWTRunLoopMode) 77 (*env)->DeleteLocalRef(env, jstr); 78 } 79 (*env)->DeleteLocalRef(env, fCompLocal); 80 return str; 81} 82 83- (void)perform 84{ 85 static JNF_STATIC_MEMBER_CACHE(jm_doAccessibleAction, sjc_CAccessibility, "doAccessibleAction", "(Ljavax/accessibility/AccessibleAction;ILjava/awt/Component;)V"); 86 87 JNIEnv* env = [ThreadUtilities getJNIEnv]; 88 89 JNFCallStaticVoidMethod(env, jm_doAccessibleAction, fAccessibleAction, fIndex, fComponent); // AWT_THREADING Safe (AWTRunLoopMode) 90} 91 92@end 93 94 95@implementation TabGroupAction 96 97- (id)initWithEnv:(JNIEnv *)env withTabGroup:(jobject)tabGroup withIndex:(jint)index withComponent:(jobject)component 98{ 99 self = [super init]; 100 if (self) { 101 fTabGroup = JNFNewWeakGlobalRef(env, tabGroup); 102 fIndex = index; 103 fComponent = JNFNewWeakGlobalRef(env, component); 104 } 105 return self; 106} 107 108- (void)dealloc 109{ 110 JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; 111 112 JNFDeleteWeakGlobalRef(env, fTabGroup); 113 fTabGroup = NULL; 114 115 JNFDeleteWeakGlobalRef(env, fComponent); 116 fComponent = NULL; 117 118 [super dealloc]; 119} 120 121- (NSString *)getDescription 122{ 123 return @"click"; 124} 125 126- (void)perform 127{ 128 JNIEnv* env = [ThreadUtilities getJNIEnv]; 129 130 setAxContextSelection(env, fTabGroup, fIndex, fComponent); 131} 132 133@end 134