Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "Accessible-inl.h" |
michael@0 | 7 | #include "HyperTextAccessible-inl.h" |
michael@0 | 8 | #include "TextLeafAccessible.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "nsCocoaUtils.h" |
michael@0 | 11 | #include "nsObjCExceptions.h" |
michael@0 | 12 | |
michael@0 | 13 | #import "mozTextAccessible.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::a11y; |
michael@0 | 16 | |
michael@0 | 17 | inline bool |
michael@0 | 18 | ToNSRange(id aValue, NSRange* aRange) |
michael@0 | 19 | { |
michael@0 | 20 | NS_PRECONDITION(aRange, "aRange is nil"); |
michael@0 | 21 | |
michael@0 | 22 | if ([aValue isKindOfClass:[NSValue class]] && |
michael@0 | 23 | strcmp([(NSValue*)aValue objCType], @encode(NSRange)) == 0) { |
michael@0 | 24 | *aRange = [aValue rangeValue]; |
michael@0 | 25 | return true; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | return false; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | inline NSString* |
michael@0 | 32 | ToNSString(id aValue) |
michael@0 | 33 | { |
michael@0 | 34 | if ([aValue isKindOfClass:[NSString class]]) { |
michael@0 | 35 | return aValue; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | return nil; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | @interface mozTextAccessible () |
michael@0 | 42 | - (NSString*)subrole; |
michael@0 | 43 | - (NSString*)selectedText; |
michael@0 | 44 | - (NSValue*)selectedTextRange; |
michael@0 | 45 | - (NSValue*)visibleCharacterRange; |
michael@0 | 46 | - (long)textLength; |
michael@0 | 47 | - (BOOL)isReadOnly; |
michael@0 | 48 | - (NSNumber*)caretLineNumber; |
michael@0 | 49 | - (void)setText:(NSString*)newText; |
michael@0 | 50 | - (NSString*)text; |
michael@0 | 51 | - (NSString*)stringFromRange:(NSRange*)range; |
michael@0 | 52 | @end |
michael@0 | 53 | |
michael@0 | 54 | @implementation mozTextAccessible |
michael@0 | 55 | |
michael@0 | 56 | - (id)initWithAccessible:(AccessibleWrap*)accessible |
michael@0 | 57 | { |
michael@0 | 58 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
michael@0 | 59 | |
michael@0 | 60 | if ((self = [super initWithAccessible:accessible])) { |
michael@0 | 61 | mGeckoTextAccessible = accessible->AsHyperText(); |
michael@0 | 62 | CallQueryInterface(accessible, &mGeckoEditableTextAccessible); |
michael@0 | 63 | } |
michael@0 | 64 | return self; |
michael@0 | 65 | |
michael@0 | 66 | NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | - (BOOL)accessibilityIsIgnored |
michael@0 | 70 | { |
michael@0 | 71 | return !mGeckoAccessible; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | - (NSArray*)accessibilityAttributeNames |
michael@0 | 75 | { |
michael@0 | 76 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
michael@0 | 77 | |
michael@0 | 78 | static NSMutableArray* supportedAttributes = nil; |
michael@0 | 79 | if (!supportedAttributes) { |
michael@0 | 80 | // text-specific attributes to supplement the standard one |
michael@0 | 81 | supportedAttributes = [[NSMutableArray alloc] initWithObjects: |
michael@0 | 82 | NSAccessibilitySelectedTextAttribute, // required |
michael@0 | 83 | NSAccessibilitySelectedTextRangeAttribute, // required |
michael@0 | 84 | NSAccessibilityNumberOfCharactersAttribute, // required |
michael@0 | 85 | NSAccessibilityVisibleCharacterRangeAttribute, // required |
michael@0 | 86 | NSAccessibilityInsertionPointLineNumberAttribute, |
michael@0 | 87 | @"AXRequired", |
michael@0 | 88 | @"AXInvalid", |
michael@0 | 89 | nil |
michael@0 | 90 | ]; |
michael@0 | 91 | [supportedAttributes addObjectsFromArray:[super accessibilityAttributeNames]]; |
michael@0 | 92 | } |
michael@0 | 93 | return supportedAttributes; |
michael@0 | 94 | |
michael@0 | 95 | NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | - (id)accessibilityAttributeValue:(NSString*)attribute |
michael@0 | 99 | { |
michael@0 | 100 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
michael@0 | 101 | |
michael@0 | 102 | if ([attribute isEqualToString:NSAccessibilityNumberOfCharactersAttribute]) |
michael@0 | 103 | return [NSNumber numberWithInt:[self textLength]]; |
michael@0 | 104 | |
michael@0 | 105 | if ([attribute isEqualToString:NSAccessibilityInsertionPointLineNumberAttribute]) |
michael@0 | 106 | return [self caretLineNumber]; |
michael@0 | 107 | |
michael@0 | 108 | if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) |
michael@0 | 109 | return [self selectedTextRange]; |
michael@0 | 110 | |
michael@0 | 111 | if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) |
michael@0 | 112 | return [self selectedText]; |
michael@0 | 113 | |
michael@0 | 114 | if ([attribute isEqualToString:NSAccessibilityTitleAttribute]) |
michael@0 | 115 | return @""; |
michael@0 | 116 | |
michael@0 | 117 | if ([attribute isEqualToString:NSAccessibilityValueAttribute]) { |
michael@0 | 118 | // Apple's SpeechSynthesisServer expects AXValue to return an AXStaticText |
michael@0 | 119 | // object's AXSelectedText attribute. See bug 674612 for details. |
michael@0 | 120 | // Also if there is no selected text, we return the full text. |
michael@0 | 121 | // See bug 369710 for details. |
michael@0 | 122 | if ([[self role] isEqualToString:NSAccessibilityStaticTextRole]) { |
michael@0 | 123 | NSString* selectedText = [self selectedText]; |
michael@0 | 124 | return (selectedText && [selectedText length]) ? selectedText : [self text]; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | return [self text]; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | if ([attribute isEqualToString:@"AXRequired"]) |
michael@0 | 131 | return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::REQUIRED)]; |
michael@0 | 132 | |
michael@0 | 133 | if ([attribute isEqualToString:@"AXInvalid"]) |
michael@0 | 134 | return [NSNumber numberWithBool:!!(mGeckoAccessible->State() & states::INVALID)]; |
michael@0 | 135 | |
michael@0 | 136 | if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) |
michael@0 | 137 | return [self visibleCharacterRange]; |
michael@0 | 138 | |
michael@0 | 139 | // let mozAccessible handle all other attributes |
michael@0 | 140 | return [super accessibilityAttributeValue:attribute]; |
michael@0 | 141 | |
michael@0 | 142 | NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | - (NSArray*)accessibilityParameterizedAttributeNames |
michael@0 | 146 | { |
michael@0 | 147 | static NSArray* supportedParametrizedAttributes = nil; |
michael@0 | 148 | // text specific parametrized attributes |
michael@0 | 149 | if (!supportedParametrizedAttributes) { |
michael@0 | 150 | supportedParametrizedAttributes = [[NSArray alloc] initWithObjects: |
michael@0 | 151 | NSAccessibilityStringForRangeParameterizedAttribute, |
michael@0 | 152 | NSAccessibilityLineForIndexParameterizedAttribute, |
michael@0 | 153 | NSAccessibilityRangeForLineParameterizedAttribute, |
michael@0 | 154 | NSAccessibilityAttributedStringForRangeParameterizedAttribute, |
michael@0 | 155 | NSAccessibilityBoundsForRangeParameterizedAttribute, |
michael@0 | 156 | #if DEBUG |
michael@0 | 157 | NSAccessibilityRangeForPositionParameterizedAttribute, |
michael@0 | 158 | NSAccessibilityRangeForIndexParameterizedAttribute, |
michael@0 | 159 | NSAccessibilityRTFForRangeParameterizedAttribute, |
michael@0 | 160 | NSAccessibilityStyleRangeForIndexParameterizedAttribute, |
michael@0 | 161 | #endif |
michael@0 | 162 | nil |
michael@0 | 163 | ]; |
michael@0 | 164 | } |
michael@0 | 165 | return supportedParametrizedAttributes; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | - (id)accessibilityAttributeValue:(NSString*)attribute forParameter:(id)parameter |
michael@0 | 169 | { |
michael@0 | 170 | if (!mGeckoTextAccessible) |
michael@0 | 171 | return nil; |
michael@0 | 172 | |
michael@0 | 173 | if ([attribute isEqualToString:NSAccessibilityStringForRangeParameterizedAttribute]) { |
michael@0 | 174 | NSRange range; |
michael@0 | 175 | if (!ToNSRange(parameter, &range)) { |
michael@0 | 176 | #if DEBUG |
michael@0 | 177 | NSLog(@"%@: range not set", attribute); |
michael@0 | 178 | #endif |
michael@0 | 179 | return @""; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | return [self stringFromRange:&range]; |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | if ([attribute isEqualToString:NSAccessibilityRangeForLineParameterizedAttribute]) { |
michael@0 | 186 | // XXX: actually get the integer value for the line # |
michael@0 | 187 | return [NSValue valueWithRange:NSMakeRange(0, [self textLength])]; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | if ([attribute isEqualToString:NSAccessibilityAttributedStringForRangeParameterizedAttribute]) { |
michael@0 | 191 | NSRange range; |
michael@0 | 192 | if (!ToNSRange(parameter, &range)) { |
michael@0 | 193 | #if DEBUG |
michael@0 | 194 | NSLog(@"%@: range not set", attribute); |
michael@0 | 195 | #endif |
michael@0 | 196 | return @""; |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | return [[[NSAttributedString alloc] initWithString:[self stringFromRange:&range]] autorelease]; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | if ([attribute isEqualToString:NSAccessibilityLineForIndexParameterizedAttribute]) { |
michael@0 | 203 | // XXX: actually return the line # |
michael@0 | 204 | return [NSNumber numberWithInt:0]; |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | if ([attribute isEqualToString:NSAccessibilityBoundsForRangeParameterizedAttribute]) { |
michael@0 | 208 | NSRange range; |
michael@0 | 209 | if (!ToNSRange(parameter, &range)) { |
michael@0 | 210 | #if DEBUG |
michael@0 | 211 | NSLog(@"%@:no range", attribute); |
michael@0 | 212 | #endif |
michael@0 | 213 | return nil; |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | int32_t start = range.location; |
michael@0 | 217 | int32_t end = start + range.length; |
michael@0 | 218 | nsIntRect bounds = mGeckoTextAccessible->TextBounds(start, end); |
michael@0 | 219 | |
michael@0 | 220 | return [NSValue valueWithRect:nsCocoaUtils::GeckoRectToCocoaRect(bounds)]; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | #if DEBUG |
michael@0 | 224 | NSLog(@"unhandled attribute:%@ forParameter:%@", attribute, parameter); |
michael@0 | 225 | #endif |
michael@0 | 226 | |
michael@0 | 227 | return nil; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute |
michael@0 | 231 | { |
michael@0 | 232 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
michael@0 | 233 | |
michael@0 | 234 | if ([attribute isEqualToString:NSAccessibilityValueAttribute]) |
michael@0 | 235 | return ![self isReadOnly]; |
michael@0 | 236 | |
michael@0 | 237 | if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute] || |
michael@0 | 238 | [attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute] || |
michael@0 | 239 | [attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) |
michael@0 | 240 | return YES; |
michael@0 | 241 | |
michael@0 | 242 | return [super accessibilityIsAttributeSettable:attribute]; |
michael@0 | 243 | |
michael@0 | 244 | NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO); |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | - (void)accessibilitySetValue:(id)value forAttribute:(NSString *)attribute |
michael@0 | 248 | { |
michael@0 | 249 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
michael@0 | 250 | |
michael@0 | 251 | if (!mGeckoTextAccessible) |
michael@0 | 252 | return; |
michael@0 | 253 | |
michael@0 | 254 | if ([attribute isEqualToString:NSAccessibilityValueAttribute]) { |
michael@0 | 255 | [self setText:ToNSString(value)]; |
michael@0 | 256 | |
michael@0 | 257 | return; |
michael@0 | 258 | } |
michael@0 | 259 | |
michael@0 | 260 | if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) { |
michael@0 | 261 | NSString* stringValue = ToNSString(value); |
michael@0 | 262 | if (!stringValue) |
michael@0 | 263 | return; |
michael@0 | 264 | |
michael@0 | 265 | int32_t start = 0, end = 0; |
michael@0 | 266 | mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end); |
michael@0 | 267 | mGeckoTextAccessible->DeleteText(start, end - start); |
michael@0 | 268 | |
michael@0 | 269 | nsString text; |
michael@0 | 270 | nsCocoaUtils::GetStringForNSString(stringValue, text); |
michael@0 | 271 | mGeckoTextAccessible->InsertText(text, start); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { |
michael@0 | 275 | NSRange range; |
michael@0 | 276 | if (!ToNSRange(value, &range)) |
michael@0 | 277 | return; |
michael@0 | 278 | |
michael@0 | 279 | mGeckoTextAccessible->SetSelectionBoundsAt(0, range.location, |
michael@0 | 280 | range.location + range.length); |
michael@0 | 281 | return; |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | if ([attribute isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) { |
michael@0 | 285 | NSRange range; |
michael@0 | 286 | if (!ToNSRange(value, &range)) |
michael@0 | 287 | return; |
michael@0 | 288 | |
michael@0 | 289 | mGeckoTextAccessible->ScrollSubstringTo(range.location, range.location + range.length, |
michael@0 | 290 | nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE); |
michael@0 | 291 | return; |
michael@0 | 292 | } |
michael@0 | 293 | |
michael@0 | 294 | [super accessibilitySetValue:value forAttribute:attribute]; |
michael@0 | 295 | |
michael@0 | 296 | NS_OBJC_END_TRY_ABORT_BLOCK; |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | - (NSString*)subrole |
michael@0 | 300 | { |
michael@0 | 301 | if(mRole == roles::PASSWORD_TEXT) |
michael@0 | 302 | return NSAccessibilitySecureTextFieldSubrole; |
michael@0 | 303 | |
michael@0 | 304 | return nil; |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | - (void)expire |
michael@0 | 308 | { |
michael@0 | 309 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
michael@0 | 310 | |
michael@0 | 311 | mGeckoTextAccessible = nullptr; |
michael@0 | 312 | NS_IF_RELEASE(mGeckoEditableTextAccessible); |
michael@0 | 313 | [super expire]; |
michael@0 | 314 | |
michael@0 | 315 | NS_OBJC_END_TRY_ABORT_BLOCK; |
michael@0 | 316 | } |
michael@0 | 317 | |
michael@0 | 318 | #pragma mark - |
michael@0 | 319 | |
michael@0 | 320 | - (BOOL)isReadOnly |
michael@0 | 321 | { |
michael@0 | 322 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
michael@0 | 323 | |
michael@0 | 324 | if ([[self role] isEqualToString:NSAccessibilityStaticTextRole]) |
michael@0 | 325 | return YES; |
michael@0 | 326 | |
michael@0 | 327 | if (mGeckoEditableTextAccessible) |
michael@0 | 328 | return (mGeckoAccessible->State() & states::READONLY) == 0; |
michael@0 | 329 | |
michael@0 | 330 | return NO; |
michael@0 | 331 | |
michael@0 | 332 | NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO); |
michael@0 | 333 | } |
michael@0 | 334 | |
michael@0 | 335 | - (NSNumber*)caretLineNumber |
michael@0 | 336 | { |
michael@0 | 337 | int32_t lineNumber = mGeckoTextAccessible ? |
michael@0 | 338 | mGeckoTextAccessible->CaretLineNumber() - 1 : -1; |
michael@0 | 339 | |
michael@0 | 340 | return (lineNumber >= 0) ? [NSNumber numberWithInt:lineNumber] : nil; |
michael@0 | 341 | } |
michael@0 | 342 | |
michael@0 | 343 | - (void)setText:(NSString*)aNewString |
michael@0 | 344 | { |
michael@0 | 345 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
michael@0 | 346 | |
michael@0 | 347 | if (mGeckoEditableTextAccessible) { |
michael@0 | 348 | nsString text; |
michael@0 | 349 | nsCocoaUtils::GetStringForNSString(aNewString, text); |
michael@0 | 350 | mGeckoEditableTextAccessible->SetTextContents(text); |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | NS_OBJC_END_TRY_ABORT_BLOCK; |
michael@0 | 354 | } |
michael@0 | 355 | |
michael@0 | 356 | - (NSString*)text |
michael@0 | 357 | { |
michael@0 | 358 | if (!mGeckoAccessible || !mGeckoTextAccessible) |
michael@0 | 359 | return nil; |
michael@0 | 360 | |
michael@0 | 361 | // A password text field returns an empty value |
michael@0 | 362 | if (mRole == roles::PASSWORD_TEXT) |
michael@0 | 363 | return @""; |
michael@0 | 364 | |
michael@0 | 365 | nsAutoString text; |
michael@0 | 366 | mGeckoTextAccessible->TextSubstring(0, |
michael@0 | 367 | nsIAccessibleText::TEXT_OFFSET_END_OF_TEXT, |
michael@0 | 368 | text); |
michael@0 | 369 | return nsCocoaUtils::ToNSString(text); |
michael@0 | 370 | } |
michael@0 | 371 | |
michael@0 | 372 | - (long)textLength |
michael@0 | 373 | { |
michael@0 | 374 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
michael@0 | 375 | |
michael@0 | 376 | if (!mGeckoAccessible || !mGeckoTextAccessible) |
michael@0 | 377 | return 0; |
michael@0 | 378 | |
michael@0 | 379 | return mGeckoTextAccessible ? mGeckoTextAccessible->CharacterCount() : 0; |
michael@0 | 380 | |
michael@0 | 381 | NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0); |
michael@0 | 382 | } |
michael@0 | 383 | |
michael@0 | 384 | - (long)selectedTextLength |
michael@0 | 385 | { |
michael@0 | 386 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
michael@0 | 387 | |
michael@0 | 388 | if (mGeckoTextAccessible) { |
michael@0 | 389 | int32_t start = 0, end = 0; |
michael@0 | 390 | mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end); |
michael@0 | 391 | return (end - start); |
michael@0 | 392 | } |
michael@0 | 393 | return 0; |
michael@0 | 394 | |
michael@0 | 395 | NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0); |
michael@0 | 396 | } |
michael@0 | 397 | |
michael@0 | 398 | - (NSString*)selectedText |
michael@0 | 399 | { |
michael@0 | 400 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
michael@0 | 401 | |
michael@0 | 402 | if (mGeckoTextAccessible) { |
michael@0 | 403 | int32_t start = 0, end = 0; |
michael@0 | 404 | mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end); |
michael@0 | 405 | if (start != end) { |
michael@0 | 406 | nsAutoString selText; |
michael@0 | 407 | mGeckoTextAccessible->TextSubstring(start, end, selText); |
michael@0 | 408 | return nsCocoaUtils::ToNSString(selText); |
michael@0 | 409 | } |
michael@0 | 410 | } |
michael@0 | 411 | return nil; |
michael@0 | 412 | |
michael@0 | 413 | NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | - (NSValue*)selectedTextRange |
michael@0 | 417 | { |
michael@0 | 418 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL; |
michael@0 | 419 | |
michael@0 | 420 | if (mGeckoTextAccessible) { |
michael@0 | 421 | int32_t start = 0; |
michael@0 | 422 | int32_t end = 0; |
michael@0 | 423 | int32_t count = mGeckoTextAccessible->SelectionCount(); |
michael@0 | 424 | |
michael@0 | 425 | if (count) { |
michael@0 | 426 | mGeckoTextAccessible->SelectionBoundsAt(0, &start, &end); |
michael@0 | 427 | return [NSValue valueWithRange:NSMakeRange(start, end - start)]; |
michael@0 | 428 | } |
michael@0 | 429 | |
michael@0 | 430 | start = mGeckoTextAccessible->CaretOffset(); |
michael@0 | 431 | return [NSValue valueWithRange:NSMakeRange(start != -1 ? start : 0, 0)]; |
michael@0 | 432 | } |
michael@0 | 433 | return [NSValue valueWithRange:NSMakeRange(0, 0)]; |
michael@0 | 434 | |
michael@0 | 435 | NS_OBJC_END_TRY_ABORT_BLOCK_NIL; |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | - (NSValue*)visibleCharacterRange |
michael@0 | 439 | { |
michael@0 | 440 | // XXX this won't work with Textarea and such as we actually don't give |
michael@0 | 441 | // the visible character range. |
michael@0 | 442 | return [NSValue valueWithRange: |
michael@0 | 443 | NSMakeRange(0, mGeckoTextAccessible ? |
michael@0 | 444 | mGeckoTextAccessible->CharacterCount() : 0)]; |
michael@0 | 445 | } |
michael@0 | 446 | |
michael@0 | 447 | - (void)valueDidChange |
michael@0 | 448 | { |
michael@0 | 449 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
michael@0 | 450 | |
michael@0 | 451 | NSAccessibilityPostNotification(GetObjectOrRepresentedView(self), |
michael@0 | 452 | NSAccessibilityValueChangedNotification); |
michael@0 | 453 | |
michael@0 | 454 | NS_OBJC_END_TRY_ABORT_BLOCK; |
michael@0 | 455 | } |
michael@0 | 456 | |
michael@0 | 457 | - (void)selectedTextDidChange |
michael@0 | 458 | { |
michael@0 | 459 | NSAccessibilityPostNotification(GetObjectOrRepresentedView(self), |
michael@0 | 460 | NSAccessibilitySelectedTextChangedNotification); |
michael@0 | 461 | } |
michael@0 | 462 | |
michael@0 | 463 | - (NSString*)stringFromRange:(NSRange*)range |
michael@0 | 464 | { |
michael@0 | 465 | NS_PRECONDITION(mGeckoTextAccessible && range, "no Gecko text accessible or range"); |
michael@0 | 466 | |
michael@0 | 467 | nsAutoString text; |
michael@0 | 468 | mGeckoTextAccessible->TextSubstring(range->location, |
michael@0 | 469 | range->location + range->length, text); |
michael@0 | 470 | return nsCocoaUtils::ToNSString(text); |
michael@0 | 471 | } |
michael@0 | 472 | |
michael@0 | 473 | @end |
michael@0 | 474 | |
michael@0 | 475 | @implementation mozTextLeafAccessible |
michael@0 | 476 | |
michael@0 | 477 | - (NSArray*)accessibilityAttributeNames |
michael@0 | 478 | { |
michael@0 | 479 | static NSMutableArray* supportedAttributes = nil; |
michael@0 | 480 | if (!supportedAttributes) { |
michael@0 | 481 | supportedAttributes = [[super accessibilityAttributeNames] mutableCopy]; |
michael@0 | 482 | [supportedAttributes removeObject:NSAccessibilityChildrenAttribute]; |
michael@0 | 483 | } |
michael@0 | 484 | |
michael@0 | 485 | return supportedAttributes; |
michael@0 | 486 | } |
michael@0 | 487 | |
michael@0 | 488 | - (id)accessibilityAttributeValue:(NSString*)attribute |
michael@0 | 489 | { |
michael@0 | 490 | if ([attribute isEqualToString:NSAccessibilityTitleAttribute]) |
michael@0 | 491 | return @""; |
michael@0 | 492 | |
michael@0 | 493 | if ([attribute isEqualToString:NSAccessibilityValueAttribute]) |
michael@0 | 494 | return [self text]; |
michael@0 | 495 | |
michael@0 | 496 | return [super accessibilityAttributeValue:attribute]; |
michael@0 | 497 | } |
michael@0 | 498 | |
michael@0 | 499 | - (NSString*)text |
michael@0 | 500 | { |
michael@0 | 501 | if (!mGeckoAccessible) |
michael@0 | 502 | return nil; |
michael@0 | 503 | |
michael@0 | 504 | return nsCocoaUtils::ToNSString(mGeckoAccessible->AsTextLeaf()->Text()); |
michael@0 | 505 | } |
michael@0 | 506 | |
michael@0 | 507 | - (long)textLength |
michael@0 | 508 | { |
michael@0 | 509 | if (!mGeckoAccessible) |
michael@0 | 510 | return 0; |
michael@0 | 511 | |
michael@0 | 512 | return mGeckoAccessible->AsTextLeaf()->Text().Length(); |
michael@0 | 513 | } |
michael@0 | 514 | |
michael@0 | 515 | @end |