< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/JavaTextAccessibility.m

Print this page
rev 54086 : 8240487: Cleanup whitespace in .cc, .hh, .m, and .mm files


 106 }
 107 
 108 - (NSString *)accessibilityValueAttribute
 109 {
 110     JNIEnv *env = [ThreadUtilities getJNIEnv];
 111     if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) {
 112         // if it's static text, the AppKit AXValue is the java accessibleName
 113         jobject axName = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 114         if (axName != NULL) {
 115             NSString* str = JNFJavaToNSString(env, axName);
 116             (*env)->DeleteLocalRef(env, axName);
 117             return str;
 118         }
 119         // value is still nil if no accessibleName for static text. Below, try to get the accessibleText.
 120     }
 121 
 122     // cmcnote: inefficient to make three distinct JNI calls. Coalesce. radr://3951923
 123     jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 124     if (axText == NULL) return nil;
 125     (*env)->DeleteLocalRef(env, axText);
 126     
 127     jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 128     if (axEditableText == NULL) return nil;
 129 
 130     static JNF_STATIC_MEMBER_CACHE(jm_getTextRange, sjc_CAccessibleText, "getTextRange", "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;");
 131     jobject jrange = JNFCallStaticObjectMethod(env, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent);
 132     NSString *string = JNFJavaToNSString(env, jrange); // AWT_THREADING Safe (AWTRunLoop)
 133 
 134     (*env)->DeleteLocalRef(env, jrange);
 135     (*env)->DeleteLocalRef(env, axEditableText);
 136     
 137     if (string == nil) string = @"";
 138     return string;
 139 }
 140 
 141 - (BOOL)accessibilityIsValueAttributeSettable
 142 {
 143     // if text is enabled and editable, it's settable (according to NSCellTextAttributesAccessibility)
 144     BOOL isEnabled = [(NSNumber *)[self accessibilityEnabledAttribute] boolValue];
 145     if (!isEnabled) return NO;
 146 
 147     JNIEnv* env = [ThreadUtilities getJNIEnv];
 148     jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 149     if (axEditableText == NULL) return NO;
 150     (*env)->DeleteLocalRef(env, axEditableText);
 151     return YES;
 152 }
 153 
 154 - (void)accessibilitySetValueAttribute:(id)value
 155 {
 156 // cmcnote: should set the accessibleEditableText to the stringValue of value - AccessibleEditableText.setTextContents(String s)


 288 - (NSValue *)accessibilityBoundsForRangeAttributeForParameter:(id)parameter
 289 {
 290 #ifdef JAVA_AX_DEBUG_PARMS
 291     if (!([parameter isKindOfClass:[NSValue class]] && strcmp([(NSValue *)parameter objCType], @encode(NSRange)) == 0)) {
 292         JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityBoundsForRangeParameterizedAttribute, parameter);
 293         return nil;
 294     }
 295 #endif
 296 
 297     NSRange range = [(NSValue *)parameter rangeValue];
 298 
 299     JNIEnv *env = [ThreadUtilities getJNIEnv];
 300     static JNF_STATIC_MEMBER_CACHE(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D");
 301     jdoubleArray axBounds = (jdoubleArray)JNFCallStaticObjectMethod(env, jm_getBoundsForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop)
 302     if (axBounds == NULL) return nil;
 303 
 304     // We cheat because we know that the array is 4 elements long (x, y, width, height)
 305     jdouble *values = (*env)->GetDoubleArrayElements(env, axBounds, 0);
 306     if (values == NULL) {
 307         // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
 308         NSLog(@"%s failed calling GetDoubleArrayElements", __FUNCTION__); 
 309         return nil;
 310     };
 311     NSRect bounds;
 312     bounds.origin.x = values[0];
 313     bounds.origin.y = [[[[self view] window] screen] frame].size.height - values[1] - values[3]; //values[1] is y-coord from top-left of screen. Flip. Account for the height (values[3]) when flipping
 314     bounds.size.width = values[2];
 315     bounds.size.height = values[3];
 316     NSValue *result = [NSValue valueWithRect:bounds];
 317     (*env)->ReleaseDoubleArrayElements(env, axBounds, values, 0);
 318     return result;
 319 }
 320 
 321 - (NSNumber *)accessibilityLineForIndexAttributeForParameter:(id)parameter
 322 {
 323     NSNumber *line = (NSNumber *) parameter;
 324     if (line == nil) return nil;
 325 
 326     JNIEnv *env = [ThreadUtilities getJNIEnv];
 327     static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I");
 328     jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForIndex, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop)


 410 //
 411 - (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter
 412 {
 413 #ifdef JAVA_AX_DEBUG_PARMS
 414     if (![parameter isKindOfClass:[NSNumber class]]) {
 415         JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityRangeForIndexParameterizedAttribute, parameter);
 416         return nil;
 417     }
 418 #endif
 419 
 420     NSUInteger index = [(NSNumber *)parameter unsignedIntegerValue];
 421 
 422     JNIEnv *env = [ThreadUtilities getJNIEnv];
 423     static JNF_STATIC_MEMBER_CACHE(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I");
 424     jintArray axTextRange = (jintArray)JNFCallStaticObjectMethod(env, jm_getRangeForIndex, fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop)
 425     if (axTextRange == NULL) return nil;
 426 
 427     return javaIntArrayToNSRangeValue(env, axTextRange);
 428 }
 429 
 430 /* 
 431  * - (NSDictionary *)getActions:(JNIEnv *)env { ... }
 432  *
 433  * In the future, possibly add support: Editable text has AXShowMenu.
 434  * Textfields have AXConfirm.
 435  *
 436  * Note: JLabels (static text) in JLists have a press/click selection action
 437  *   which is currently handled in superclass JavaComponentAccessibility.
 438  *   If function is added here be sure to use [super getActions:env] for JLabels.
 439  */
 440 
 441 @end


 106 }
 107 
 108 - (NSString *)accessibilityValueAttribute
 109 {
 110     JNIEnv *env = [ThreadUtilities getJNIEnv];
 111     if ([[self accessibilityRoleAttribute] isEqualToString:NSAccessibilityStaticTextRole]) {
 112         // if it's static text, the AppKit AXValue is the java accessibleName
 113         jobject axName = JNFCallStaticObjectMethod(env, sjm_getAccessibleName, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 114         if (axName != NULL) {
 115             NSString* str = JNFJavaToNSString(env, axName);
 116             (*env)->DeleteLocalRef(env, axName);
 117             return str;
 118         }
 119         // value is still nil if no accessibleName for static text. Below, try to get the accessibleText.
 120     }
 121 
 122     // cmcnote: inefficient to make three distinct JNI calls. Coalesce. radr://3951923
 123     jobject axText = JNFCallStaticObjectMethod(env, sjm_getAccessibleText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 124     if (axText == NULL) return nil;
 125     (*env)->DeleteLocalRef(env, axText);
 126 
 127     jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 128     if (axEditableText == NULL) return nil;
 129 
 130     static JNF_STATIC_MEMBER_CACHE(jm_getTextRange, sjc_CAccessibleText, "getTextRange", "(Ljavax/accessibility/AccessibleEditableText;IILjava/awt/Component;)Ljava/lang/String;");
 131     jobject jrange = JNFCallStaticObjectMethod(env, jm_getTextRange, axEditableText, 0, getAxTextCharCount(env, axEditableText, fComponent), fComponent);
 132     NSString *string = JNFJavaToNSString(env, jrange); // AWT_THREADING Safe (AWTRunLoop)
 133 
 134     (*env)->DeleteLocalRef(env, jrange);
 135     (*env)->DeleteLocalRef(env, axEditableText);
 136 
 137     if (string == nil) string = @"";
 138     return string;
 139 }
 140 
 141 - (BOOL)accessibilityIsValueAttributeSettable
 142 {
 143     // if text is enabled and editable, it's settable (according to NSCellTextAttributesAccessibility)
 144     BOOL isEnabled = [(NSNumber *)[self accessibilityEnabledAttribute] boolValue];
 145     if (!isEnabled) return NO;
 146 
 147     JNIEnv* env = [ThreadUtilities getJNIEnv];
 148     jobject axEditableText = JNFCallStaticObjectMethod(env, sjm_getAccessibleEditableText, fAccessible, fComponent); // AWT_THREADING Safe (AWTRunLoop)
 149     if (axEditableText == NULL) return NO;
 150     (*env)->DeleteLocalRef(env, axEditableText);
 151     return YES;
 152 }
 153 
 154 - (void)accessibilitySetValueAttribute:(id)value
 155 {
 156 // cmcnote: should set the accessibleEditableText to the stringValue of value - AccessibleEditableText.setTextContents(String s)


 288 - (NSValue *)accessibilityBoundsForRangeAttributeForParameter:(id)parameter
 289 {
 290 #ifdef JAVA_AX_DEBUG_PARMS
 291     if (!([parameter isKindOfClass:[NSValue class]] && strcmp([(NSValue *)parameter objCType], @encode(NSRange)) == 0)) {
 292         JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityBoundsForRangeParameterizedAttribute, parameter);
 293         return nil;
 294     }
 295 #endif
 296 
 297     NSRange range = [(NSValue *)parameter rangeValue];
 298 
 299     JNIEnv *env = [ThreadUtilities getJNIEnv];
 300     static JNF_STATIC_MEMBER_CACHE(jm_getBoundsForRange, sjc_CAccessibleText, "getBoundsForRange", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;II)[D");
 301     jdoubleArray axBounds = (jdoubleArray)JNFCallStaticObjectMethod(env, jm_getBoundsForRange, fAccessible, fComponent, range.location, range.length); // AWT_THREADING Safe (AWTRunLoop)
 302     if (axBounds == NULL) return nil;
 303 
 304     // We cheat because we know that the array is 4 elements long (x, y, width, height)
 305     jdouble *values = (*env)->GetDoubleArrayElements(env, axBounds, 0);
 306     if (values == NULL) {
 307         // Note: Java will not be on the stack here so a java exception can't happen and no need to call ExceptionCheck.
 308         NSLog(@"%s failed calling GetDoubleArrayElements", __FUNCTION__);
 309         return nil;
 310     };
 311     NSRect bounds;
 312     bounds.origin.x = values[0];
 313     bounds.origin.y = [[[[self view] window] screen] frame].size.height - values[1] - values[3]; //values[1] is y-coord from top-left of screen. Flip. Account for the height (values[3]) when flipping
 314     bounds.size.width = values[2];
 315     bounds.size.height = values[3];
 316     NSValue *result = [NSValue valueWithRect:bounds];
 317     (*env)->ReleaseDoubleArrayElements(env, axBounds, values, 0);
 318     return result;
 319 }
 320 
 321 - (NSNumber *)accessibilityLineForIndexAttributeForParameter:(id)parameter
 322 {
 323     NSNumber *line = (NSNumber *) parameter;
 324     if (line == nil) return nil;
 325 
 326     JNIEnv *env = [ThreadUtilities getJNIEnv];
 327     static JNF_STATIC_MEMBER_CACHE(jm_getLineNumberForIndex, sjc_CAccessibleText, "getLineNumberForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)I");
 328     jint row = JNFCallStaticIntMethod(env, jm_getLineNumberForIndex, fAccessible, fComponent, [line intValue]); // AWT_THREADING Safe (AWTRunLoop)


 410 //
 411 - (NSValue *)accessibilityRangeForIndexAttributeForParameter:(id)parameter
 412 {
 413 #ifdef JAVA_AX_DEBUG_PARMS
 414     if (![parameter isKindOfClass:[NSNumber class]]) {
 415         JavaAccessibilityRaiseIllegalParameterTypeException(__FUNCTION__, self, NSAccessibilityRangeForIndexParameterizedAttribute, parameter);
 416         return nil;
 417     }
 418 #endif
 419 
 420     NSUInteger index = [(NSNumber *)parameter unsignedIntegerValue];
 421 
 422     JNIEnv *env = [ThreadUtilities getJNIEnv];
 423     static JNF_STATIC_MEMBER_CACHE(jm_getRangeForIndex, sjc_CAccessibleText, "getRangeForIndex", "(Ljavax/accessibility/Accessible;Ljava/awt/Component;I)[I");
 424     jintArray axTextRange = (jintArray)JNFCallStaticObjectMethod(env, jm_getRangeForIndex, fAccessible, fComponent, index); // AWT_THREADING Safe (AWTRunLoop)
 425     if (axTextRange == NULL) return nil;
 426 
 427     return javaIntArrayToNSRangeValue(env, axTextRange);
 428 }
 429 
 430 /*
 431  * - (NSDictionary *)getActions:(JNIEnv *)env { ... }
 432  *
 433  * In the future, possibly add support: Editable text has AXShowMenu.
 434  * Textfields have AXConfirm.
 435  *
 436  * Note: JLabels (static text) in JLists have a press/click selection action
 437  *   which is currently handled in superclass JavaComponentAccessibility.
 438  *   If function is added here be sure to use [super getActions:env] for JLabels.
 439  */
 440 
 441 @end
< prev index next >