Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <execinfo.h> | 5 #include <execinfo.h> |
| 6 | 6 |
| 7 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 7 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 using content::BrowserAccessibility; | 26 using content::BrowserAccessibility; |
| 27 using content::BrowserAccessibilityManager; | 27 using content::BrowserAccessibilityManager; |
| 28 using content::BrowserAccessibilityManagerMac; | 28 using content::BrowserAccessibilityManagerMac; |
| 29 using content::ContentClient; | 29 using content::ContentClient; |
| 30 typedef AccessibilityNodeData::StringAttribute StringAttribute; | 30 typedef AccessibilityNodeData::StringAttribute StringAttribute; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Returns an autoreleased copy of the AccessibilityNodeData's attribute. | 34 // Returns an autoreleased copy of the AccessibilityNodeData's attribute. |
| 35 NSString* NSStringForStringAttribute( | 35 NSString* NSStringForStringAttribute( |
| 36 const std::map<StringAttribute, string16>& attributes, | 36 BrowserAccessibility* browserAccessibility, |
| 37 StringAttribute attribute) { | 37 StringAttribute attribute) { |
| 38 std::map<StringAttribute, string16>::const_iterator iter = | 38 std::string value; |
| 39 attributes.find(attribute); | 39 if (!browserAccessibility->GetStringAttribute(attribute, &value)) |
| 40 NSString* returnValue = @""; | 40 return @""; |
| 41 if (iter != attributes.end()) { | 41 return base::SysUTF8ToNSString(value); |
| 42 returnValue = base::SysUTF16ToNSString(iter->second); | |
| 43 } | |
| 44 return returnValue; | |
| 45 } | 42 } |
| 46 | 43 |
| 47 struct MapEntry { | 44 struct MapEntry { |
| 48 AccessibilityNodeData::Role webKitValue; | 45 AccessibilityNodeData::Role webKitValue; |
| 49 NSString* nativeValue; | 46 NSString* nativeValue; |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 typedef std::map<AccessibilityNodeData::Role, NSString*> RoleMap; | 49 typedef std::map<AccessibilityNodeData::Role, NSString*> RoleMap; |
| 53 | 50 |
| 54 // GetState checks the bitmask used in AccessibilityNodeData to check | 51 // GetState checks the bitmask used in AccessibilityNodeData to check |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 343 |
| 347 - (void)detach { | 344 - (void)detach { |
| 348 if (browserAccessibility_) { | 345 if (browserAccessibility_) { |
| 349 NSAccessibilityUnregisterUniqueIdForUIElement(self); | 346 NSAccessibilityUnregisterUniqueIdForUIElement(self); |
| 350 browserAccessibility_ = NULL; | 347 browserAccessibility_ = NULL; |
| 351 } | 348 } |
| 352 } | 349 } |
| 353 | 350 |
| 354 - (NSString*)accessKey { | 351 - (NSString*)accessKey { |
| 355 return NSStringForStringAttribute( | 352 return NSStringForStringAttribute( |
| 356 browserAccessibility_->string_attributes(), | 353 browserAccessibility_, AccessibilityNodeData::ATTR_ACCESS_KEY); |
| 357 AccessibilityNodeData::ATTR_ACCESS_KEY); | |
| 358 } | 354 } |
| 359 | 355 |
| 360 - (NSNumber*)ariaAtomic { | 356 - (NSNumber*)ariaAtomic { |
| 361 bool boolValue = false; | 357 bool boolValue = false; |
| 362 browserAccessibility_->GetBoolAttribute( | 358 browserAccessibility_->GetBoolAttribute( |
| 363 AccessibilityNodeData::ATTR_LIVE_ATOMIC, &boolValue); | 359 AccessibilityNodeData::ATTR_LIVE_ATOMIC, &boolValue); |
| 364 return [NSNumber numberWithBool:boolValue]; | 360 return [NSNumber numberWithBool:boolValue]; |
| 365 } | 361 } |
| 366 | 362 |
| 367 - (NSNumber*)ariaBusy { | 363 - (NSNumber*)ariaBusy { |
| 368 bool boolValue = false; | 364 bool boolValue = false; |
| 369 browserAccessibility_->GetBoolAttribute( | 365 browserAccessibility_->GetBoolAttribute( |
| 370 AccessibilityNodeData::ATTR_LIVE_BUSY, &boolValue); | 366 AccessibilityNodeData::ATTR_LIVE_BUSY, &boolValue); |
| 371 return [NSNumber numberWithBool:boolValue]; | 367 return [NSNumber numberWithBool:boolValue]; |
| 372 } | 368 } |
| 373 | 369 |
| 374 - (NSString*)ariaLive { | 370 - (NSString*)ariaLive { |
| 375 return NSStringForStringAttribute( | 371 return NSStringForStringAttribute( |
| 376 browserAccessibility_->string_attributes(), | 372 browserAccessibility_, AccessibilityNodeData::ATTR_LIVE_STATUS); |
| 377 AccessibilityNodeData::ATTR_LIVE_STATUS); | |
| 378 } | 373 } |
| 379 | 374 |
| 380 - (NSString*)ariaRelevant { | 375 - (NSString*)ariaRelevant { |
| 381 return NSStringForStringAttribute( | 376 return NSStringForStringAttribute( |
| 382 browserAccessibility_->string_attributes(), | 377 browserAccessibility_, AccessibilityNodeData::ATTR_LIVE_RELEVANT); |
| 383 AccessibilityNodeData::ATTR_LIVE_RELEVANT); | |
| 384 } | 378 } |
| 385 | 379 |
| 386 // Returns an array of BrowserAccessibilityCocoa objects, representing the | 380 // Returns an array of BrowserAccessibilityCocoa objects, representing the |
| 387 // accessibility children of this object. | 381 // accessibility children of this object. |
| 388 - (NSArray*)children { | 382 - (NSArray*)children { |
| 389 if (!children_) { | 383 if (!children_) { |
| 390 children_.reset([[NSMutableArray alloc] | 384 children_.reset([[NSMutableArray alloc] |
| 391 initWithCapacity:browserAccessibility_->child_count()] ); | 385 initWithCapacity:browserAccessibility_->child_count()] ); |
| 392 for (uint32 index = 0; | 386 for (uint32 index = 0; |
| 393 index < browserAccessibility_->child_count(); | 387 index < browserAccessibility_->child_count(); |
| 394 ++index) { | 388 ++index) { |
| 395 BrowserAccessibilityCocoa* child = | 389 BrowserAccessibilityCocoa* child = |
| 396 browserAccessibility_->GetChild(index)->ToBrowserAccessibilityCocoa(); | 390 browserAccessibility_->GetChild(index)->ToBrowserAccessibilityCocoa(); |
| 397 if ([child isIgnored]) | 391 if ([child isIgnored]) |
| 398 [children_ addObjectsFromArray:[child children]]; | 392 [children_ addObjectsFromArray:[child children]]; |
| 399 else | 393 else |
| 400 [children_ addObject:child]; | 394 [children_ addObject:child]; |
| 401 } | 395 } |
| 402 | 396 |
| 403 // Also, add indirect children (if any). | 397 // Also, add indirect children (if any). |
| 404 for (uint32 i = 0; | 398 const std::vector<int32>& indirectChildIds = |
| 405 i < browserAccessibility_->indirect_child_ids().size(); | 399 browserAccessibility_->GetIntListAttribute( |
| 406 ++i) { | 400 AccessibilityNodeData::ATTR_INDIRECT_CHILD_IDS); |
| 407 int32 child_id = browserAccessibility_->indirect_child_ids()[i]; | 401 for (uint32 i = 0; i < indirectChildIds.size(); ++i) { |
| 402 int32 child_id = indirectChildIds[i]; | |
| 408 BrowserAccessibility* child = | 403 BrowserAccessibility* child = |
| 409 browserAccessibility_->manager()->GetFromRendererID(child_id); | 404 browserAccessibility_->manager()->GetFromRendererID(child_id); |
| 410 | 405 |
| 411 // This only became necessary as a result of crbug.com/93095. It should be | 406 // This only became necessary as a result of crbug.com/93095. It should be |
| 412 // a DCHECK in the future. | 407 // a DCHECK in the future. |
| 413 if (child) { | 408 if (child) { |
| 414 BrowserAccessibilityCocoa* child_cocoa = | 409 BrowserAccessibilityCocoa* child_cocoa = |
| 415 child->ToBrowserAccessibilityCocoa(); | 410 child->ToBrowserAccessibilityCocoa(); |
| 416 [children_ addObject:child_cocoa]; | 411 [children_ addObject:child_cocoa]; |
| 417 } | 412 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 430 } | 425 } |
| 431 | 426 |
| 432 - (NSArray*)columnHeaders { | 427 - (NSArray*)columnHeaders { |
| 433 if ([self internalRole] != AccessibilityNodeData::ROLE_TABLE && | 428 if ([self internalRole] != AccessibilityNodeData::ROLE_TABLE && |
| 434 [self internalRole] != AccessibilityNodeData::ROLE_GRID) { | 429 [self internalRole] != AccessibilityNodeData::ROLE_GRID) { |
| 435 return nil; | 430 return nil; |
| 436 } | 431 } |
| 437 | 432 |
| 438 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 433 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 439 const std::vector<int32>& uniqueCellIds = | 434 const std::vector<int32>& uniqueCellIds = |
| 440 browserAccessibility_->unique_cell_ids(); | 435 browserAccessibility_->GetIntListAttribute( |
| 436 AccessibilityNodeData::ATTR_UNIQUE_CELL_IDS); | |
| 441 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { | 437 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { |
| 442 int id = uniqueCellIds[i]; | 438 int id = uniqueCellIds[i]; |
| 443 BrowserAccessibility* cell = | 439 BrowserAccessibility* cell = |
| 444 browserAccessibility_->manager()->GetFromRendererID(id); | 440 browserAccessibility_->manager()->GetFromRendererID(id); |
| 445 if (cell && cell->role() == AccessibilityNodeData::ROLE_COLUMN_HEADER) | 441 if (cell && cell->role() == AccessibilityNodeData::ROLE_COLUMN_HEADER) |
| 446 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; | 442 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; |
| 447 } | 443 } |
| 448 return ret; | 444 return ret; |
| 449 } | 445 } |
| 450 | 446 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 466 - (NSArray*)columns { | 462 - (NSArray*)columns { |
| 467 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 463 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 468 for (BrowserAccessibilityCocoa* child in [self children]) { | 464 for (BrowserAccessibilityCocoa* child in [self children]) { |
| 469 if ([[child role] isEqualToString:NSAccessibilityColumnRole]) | 465 if ([[child role] isEqualToString:NSAccessibilityColumnRole]) |
| 470 [ret addObject:child]; | 466 [ret addObject:child]; |
| 471 } | 467 } |
| 472 return ret; | 468 return ret; |
| 473 } | 469 } |
| 474 | 470 |
| 475 - (NSString*)description { | 471 - (NSString*)description { |
| 476 const std::map<StringAttribute, string16>& attributes = | 472 std::string value; |
|
aboxhall
2013/07/31 18:34:47
I'm finding the name of this variable a little con
| |
| 477 browserAccessibility_->string_attributes(); | 473 if (browserAccessibility_->GetStringAttribute( |
| 478 std::map<StringAttribute, string16>::const_iterator iter = | 474 AccessibilityNodeData::ATTR_DESCRIPTION, &value)) { |
| 479 attributes.find(AccessibilityNodeData::ATTR_DESCRIPTION); | 475 return base::SysUTF8ToNSString(value); |
| 480 if (iter != attributes.end()) | 476 } |
| 481 return base::SysUTF16ToNSString(iter->second); | |
| 482 | 477 |
| 483 // If the role is anything other than an image, or if there's | 478 // If the role is anything other than an image, or if there's |
| 484 // a title or title UI element, just return an empty string. | 479 // a title or title UI element, just return an empty string. |
| 485 if (![[self role] isEqualToString:NSAccessibilityImageRole]) | 480 if (![[self role] isEqualToString:NSAccessibilityImageRole]) |
| 486 return @""; | 481 return @""; |
| 487 if (!browserAccessibility_->name().empty()) | 482 if (browserAccessibility_->GetStringAttribute( |
|
aboxhall
2013/07/31 18:34:47
Should this be negated, or the value of value (arg
dmazzoni
2013/08/06 17:36:34
I replaced this with HasStringAttribute to be more
| |
| 483 AccessibilityNodeData::ATTR_NAME, &value)) { | |
| 488 return @""; | 484 return @""; |
| 485 } | |
| 489 if ([self titleUIElement]) | 486 if ([self titleUIElement]) |
| 490 return @""; | 487 return @""; |
| 491 | 488 |
| 492 // The remaining case is an image where there's no other title. | 489 // The remaining case is an image where there's no other title. |
| 493 // Return the base part of the filename as the description. | 490 // Return the base part of the filename as the description. |
| 494 iter = attributes.find(AccessibilityNodeData::ATTR_URL); | 491 if (browserAccessibility_->GetStringAttribute( |
| 495 if (iter != attributes.end()) { | 492 AccessibilityNodeData::ATTR_URL, &value)) { |
| 496 string16 filename = iter->second; | |
| 497 // Given a url like http://foo.com/bar/baz.png, just return the | 493 // Given a url like http://foo.com/bar/baz.png, just return the |
| 498 // base name, e.g., "baz.png". | 494 // base name, e.g., "baz.png". |
| 499 size_t leftIndex = filename.size(); | 495 size_t leftIndex = value.size(); |
|
aboxhall
2013/07/31 18:34:47
I realise this is effectively unchanged in this ch
dmazzoni
2013/08/06 17:36:34
Done.
| |
| 500 while (leftIndex > 0 && filename[leftIndex - 1] != '/') | 496 while (leftIndex > 0 && value[leftIndex - 1] != '/') |
| 501 leftIndex--; | 497 leftIndex--; |
| 502 string16 basename = filename.substr(leftIndex); | 498 std::string basename = value.substr(leftIndex); |
| 503 | 499 return base::SysUTF8ToNSString(basename); |
| 504 return base::SysUTF16ToNSString(basename); | |
| 505 } | 500 } |
| 506 | 501 |
| 507 return @""; | 502 return @""; |
| 508 } | 503 } |
| 509 | 504 |
| 510 - (NSNumber*)disclosing { | 505 - (NSNumber*)disclosing { |
| 511 if ([self internalRole] == AccessibilityNodeData::ROLE_TREE_ITEM) { | 506 if ([self internalRole] == AccessibilityNodeData::ROLE_TREE_ITEM) { |
| 512 return [NSNumber numberWithBool: | 507 return [NSNumber numberWithBool: |
| 513 GetState(browserAccessibility_, AccessibilityNodeData::STATE_EXPANDED)]; | 508 GetState(browserAccessibility_, AccessibilityNodeData::STATE_EXPANDED)]; |
| 514 } else { | 509 } else { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 BrowserAccessibility* headerObject = | 569 BrowserAccessibility* headerObject = |
| 575 browserAccessibility_->manager()->GetFromRendererID(headerElementId); | 570 browserAccessibility_->manager()->GetFromRendererID(headerElementId); |
| 576 if (headerObject) | 571 if (headerObject) |
| 577 return headerObject->ToBrowserAccessibilityCocoa(); | 572 return headerObject->ToBrowserAccessibilityCocoa(); |
| 578 } | 573 } |
| 579 return nil; | 574 return nil; |
| 580 } | 575 } |
| 581 | 576 |
| 582 - (NSString*)help { | 577 - (NSString*)help { |
| 583 return NSStringForStringAttribute( | 578 return NSStringForStringAttribute( |
| 584 browserAccessibility_->string_attributes(), | 579 browserAccessibility_, AccessibilityNodeData::ATTR_HELP); |
| 585 AccessibilityNodeData::ATTR_HELP); | |
| 586 } | 580 } |
| 587 | 581 |
| 588 - (NSNumber*)index { | 582 - (NSNumber*)index { |
| 589 if ([self internalRole] == AccessibilityNodeData::ROLE_COLUMN) { | 583 if ([self internalRole] == AccessibilityNodeData::ROLE_COLUMN) { |
| 590 int columnIndex; | 584 int columnIndex; |
| 591 if (browserAccessibility_->GetIntAttribute( | 585 if (browserAccessibility_->GetIntAttribute( |
| 592 AccessibilityNodeData::ATTR_TABLE_COLUMN_INDEX, &columnIndex)) { | 586 AccessibilityNodeData::ATTR_TABLE_COLUMN_INDEX, &columnIndex)) { |
| 593 return [NSNumber numberWithInt:columnIndex]; | 587 return [NSNumber numberWithInt:columnIndex]; |
| 594 } | 588 } |
| 595 } else if ([self internalRole] == AccessibilityNodeData::ROLE_ROW) { | 589 } else if ([self internalRole] == AccessibilityNodeData::ROLE_ROW) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 IDS_AX_ROLE_LINK)); | 715 IDS_AX_ROLE_LINK)); |
| 722 } | 716 } |
| 723 | 717 |
| 724 if ([role isEqualToString:@"AXHeading"]) { | 718 if ([role isEqualToString:@"AXHeading"]) { |
| 725 return base::SysUTF16ToNSString(content_client->GetLocalizedString( | 719 return base::SysUTF16ToNSString(content_client->GetLocalizedString( |
| 726 IDS_AX_ROLE_HEADING)); | 720 IDS_AX_ROLE_HEADING)); |
| 727 } | 721 } |
| 728 | 722 |
| 729 if ([role isEqualToString:NSAccessibilityGroupRole] || | 723 if ([role isEqualToString:NSAccessibilityGroupRole] || |
| 730 [role isEqualToString:NSAccessibilityRadioButtonRole]) { | 724 [role isEqualToString:NSAccessibilityRadioButtonRole]) { |
| 731 const std::vector<std::pair<string16, string16> >& htmlAttributes = | 725 std::string role; |
| 732 browserAccessibility_->html_attributes(); | 726 browserAccessibility_->GetHtmlAttribute("role", &role); |
| 733 AccessibilityNodeData::Role browserAccessibilityRole = [self internalRole]; | 727 AccessibilityNodeData::Role browserAccessibilityRole = [self internalRole]; |
| 734 if ((browserAccessibilityRole != AccessibilityNodeData::ROLE_GROUP && | 728 if ((browserAccessibilityRole != AccessibilityNodeData::ROLE_GROUP && |
| 735 browserAccessibilityRole != AccessibilityNodeData::ROLE_LIST_ITEM) || | 729 browserAccessibilityRole != AccessibilityNodeData::ROLE_LIST_ITEM) || |
| 736 browserAccessibilityRole == AccessibilityNodeData::ROLE_TAB) { | 730 browserAccessibilityRole == AccessibilityNodeData::ROLE_TAB) { |
| 737 for (size_t i = 0; i < htmlAttributes.size(); ++i) { | 731 // TODO(dtseng): This is not localized; see crbug/84814. |
| 738 const std::pair<string16, string16>& htmlAttribute = htmlAttributes[i]; | 732 return base::SysUTF8ToNSString(role); |
| 739 if (htmlAttribute.first == ASCIIToUTF16("role")) { | |
| 740 // TODO(dtseng): This is not localized; see crbug/84814. | |
| 741 return base::SysUTF16ToNSString(htmlAttribute.second); | |
| 742 } | |
| 743 } | |
| 744 } | 733 } |
| 745 } | 734 } |
| 746 | 735 |
| 747 switch([self internalRole]) { | 736 switch([self internalRole]) { |
| 748 case AccessibilityNodeData::ROLE_FOOTER: | 737 case AccessibilityNodeData::ROLE_FOOTER: |
| 749 return base::SysUTF16ToNSString(content_client->GetLocalizedString( | 738 return base::SysUTF16ToNSString(content_client->GetLocalizedString( |
| 750 IDS_AX_ROLE_FOOTER)); | 739 IDS_AX_ROLE_FOOTER)); |
| 751 case AccessibilityNodeData::ROLE_SPIN_BUTTON: | 740 case AccessibilityNodeData::ROLE_SPIN_BUTTON: |
| 752 // This control is similar to what VoiceOver calls a "stepper". | 741 // This control is similar to what VoiceOver calls a "stepper". |
| 753 return base::SysUTF16ToNSString(content_client->GetLocalizedString( | 742 return base::SysUTF16ToNSString(content_client->GetLocalizedString( |
| 754 IDS_AX_ROLE_STEPPER)); | 743 IDS_AX_ROLE_STEPPER)); |
| 755 default: | 744 default: |
| 756 break; | 745 break; |
| 757 } | 746 } |
| 758 | 747 |
| 759 return NSAccessibilityRoleDescription(role, nil); | 748 return NSAccessibilityRoleDescription(role, nil); |
| 760 } | 749 } |
| 761 | 750 |
| 762 - (NSArray*)rowHeaders { | 751 - (NSArray*)rowHeaders { |
| 763 if ([self internalRole] != AccessibilityNodeData::ROLE_TABLE && | 752 if ([self internalRole] != AccessibilityNodeData::ROLE_TABLE && |
| 764 [self internalRole] != AccessibilityNodeData::ROLE_GRID) { | 753 [self internalRole] != AccessibilityNodeData::ROLE_GRID) { |
| 765 return nil; | 754 return nil; |
| 766 } | 755 } |
| 767 | 756 |
| 768 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 757 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 769 const std::vector<int32>& uniqueCellIds = | 758 const std::vector<int32>& uniqueCellIds = |
| 770 browserAccessibility_->unique_cell_ids(); | 759 browserAccessibility_->GetIntListAttribute( |
| 760 AccessibilityNodeData::ATTR_UNIQUE_CELL_IDS); | |
| 771 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { | 761 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { |
| 772 int id = uniqueCellIds[i]; | 762 int id = uniqueCellIds[i]; |
| 773 BrowserAccessibility* cell = | 763 BrowserAccessibility* cell = |
| 774 browserAccessibility_->manager()->GetFromRendererID(id); | 764 browserAccessibility_->manager()->GetFromRendererID(id); |
| 775 if (cell && cell->role() == AccessibilityNodeData::ROLE_ROW_HEADER) | 765 if (cell && cell->role() == AccessibilityNodeData::ROLE_ROW_HEADER) |
| 776 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; | 766 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; |
| 777 } | 767 } |
| 778 return ret; | 768 return ret; |
| 779 } | 769 } |
| 780 | 770 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 797 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 787 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 798 | 788 |
| 799 if ([self internalRole] == AccessibilityNodeData::ROLE_TABLE|| | 789 if ([self internalRole] == AccessibilityNodeData::ROLE_TABLE|| |
| 800 [self internalRole] == AccessibilityNodeData::ROLE_GRID) { | 790 [self internalRole] == AccessibilityNodeData::ROLE_GRID) { |
| 801 for (BrowserAccessibilityCocoa* child in [self children]) { | 791 for (BrowserAccessibilityCocoa* child in [self children]) { |
| 802 if ([[child role] isEqualToString:NSAccessibilityRowRole]) | 792 if ([[child role] isEqualToString:NSAccessibilityRowRole]) |
| 803 [ret addObject:child]; | 793 [ret addObject:child]; |
| 804 } | 794 } |
| 805 } else if ([self internalRole] == AccessibilityNodeData::ROLE_COLUMN) { | 795 } else if ([self internalRole] == AccessibilityNodeData::ROLE_COLUMN) { |
| 806 const std::vector<int32>& indirectChildIds = | 796 const std::vector<int32>& indirectChildIds = |
| 807 browserAccessibility_->indirect_child_ids(); | 797 browserAccessibility_->GetIntListAttribute( |
| 798 AccessibilityNodeData::ATTR_INDIRECT_CHILD_IDS); | |
| 808 for (uint32 i = 0; i < indirectChildIds.size(); ++i) { | 799 for (uint32 i = 0; i < indirectChildIds.size(); ++i) { |
| 809 int id = indirectChildIds[i]; | 800 int id = indirectChildIds[i]; |
| 810 BrowserAccessibility* rowElement = | 801 BrowserAccessibility* rowElement = |
| 811 browserAccessibility_->manager()->GetFromRendererID(id); | 802 browserAccessibility_->manager()->GetFromRendererID(id); |
| 812 if (rowElement) | 803 if (rowElement) |
| 813 [ret addObject:rowElement->ToBrowserAccessibilityCocoa()]; | 804 [ret addObject:rowElement->ToBrowserAccessibilityCocoa()]; |
| 814 } | 805 } |
| 815 } | 806 } |
| 816 | 807 |
| 817 return ret; | 808 return ret; |
| 818 } | 809 } |
| 819 | 810 |
| 820 // Returns the size of this object. | 811 // Returns the size of this object. |
| 821 - (NSValue*)size { | 812 - (NSValue*)size { |
| 822 gfx::Rect bounds = browserAccessibility_->GetLocalBoundsRect(); | 813 gfx::Rect bounds = browserAccessibility_->GetLocalBoundsRect(); |
| 823 return [NSValue valueWithSize:NSMakeSize(bounds.width(), bounds.height())]; | 814 return [NSValue valueWithSize:NSMakeSize(bounds.width(), bounds.height())]; |
| 824 } | 815 } |
| 825 | 816 |
| 826 // Returns a subrole based upon the role. | 817 // Returns a subrole based upon the role. |
| 827 - (NSString*) subrole { | 818 - (NSString*) subrole { |
| 828 AccessibilityNodeData::Role browserAccessibilityRole = [self internalRole]; | 819 AccessibilityNodeData::Role browserAccessibilityRole = [self internalRole]; |
| 829 if (browserAccessibilityRole == AccessibilityNodeData::ROLE_TEXT_FIELD && | 820 if (browserAccessibilityRole == AccessibilityNodeData::ROLE_TEXT_FIELD && |
| 830 GetState(browserAccessibility_, AccessibilityNodeData::STATE_PROTECTED)) { | 821 GetState(browserAccessibility_, AccessibilityNodeData::STATE_PROTECTED)) { |
| 831 return @"AXSecureTextField"; | 822 return @"AXSecureTextField"; |
| 832 } | 823 } |
| 833 | 824 |
| 834 NSString* htmlTag = NSStringForStringAttribute( | 825 NSString* htmlTag = NSStringForStringAttribute( |
| 835 browserAccessibility_->string_attributes(), | 826 browserAccessibility_, AccessibilityNodeData::ATTR_HTML_TAG); |
| 836 AccessibilityNodeData::ATTR_HTML_TAG); | |
| 837 | 827 |
| 838 if (browserAccessibilityRole == AccessibilityNodeData::ROLE_LIST) { | 828 if (browserAccessibilityRole == AccessibilityNodeData::ROLE_LIST) { |
| 839 if ([htmlTag isEqualToString:@"ul"] || | 829 if ([htmlTag isEqualToString:@"ul"] || |
| 840 [htmlTag isEqualToString:@"ol"]) { | 830 [htmlTag isEqualToString:@"ol"]) { |
| 841 return @"AXContentList"; | 831 return @"AXContentList"; |
| 842 } else if ([htmlTag isEqualToString:@"dl"]) { | 832 } else if ([htmlTag isEqualToString:@"dl"]) { |
| 843 return @"AXDescriptionList"; | 833 return @"AXDescriptionList"; |
| 844 } | 834 } |
| 845 } | 835 } |
| 846 | 836 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 857 for (uint i=0; i < [[self children] count]; ++i) { | 847 for (uint i=0; i < [[self children] count]; ++i) { |
| 858 NSArray* tabChildren = [[[self children] objectAtIndex:i] tabs]; | 848 NSArray* tabChildren = [[[self children] objectAtIndex:i] tabs]; |
| 859 if ([tabChildren count] > 0) | 849 if ([tabChildren count] > 0) |
| 860 [tabSubtree addObjectsFromArray:tabChildren]; | 850 [tabSubtree addObjectsFromArray:tabChildren]; |
| 861 } | 851 } |
| 862 | 852 |
| 863 return tabSubtree; | 853 return tabSubtree; |
| 864 } | 854 } |
| 865 | 855 |
| 866 - (NSString*)title { | 856 - (NSString*)title { |
| 867 return base::SysUTF16ToNSString(browserAccessibility_->name()); | 857 return NSStringForStringAttribute( |
| 858 browserAccessibility_, AccessibilityNodeData::ATTR_NAME); | |
| 868 } | 859 } |
| 869 | 860 |
| 870 - (id)titleUIElement { | 861 - (id)titleUIElement { |
| 871 int titleElementId; | 862 int titleElementId; |
| 872 if (browserAccessibility_->GetIntAttribute( | 863 if (browserAccessibility_->GetIntAttribute( |
| 873 AccessibilityNodeData::ATTR_TITLE_UI_ELEMENT, &titleElementId)) { | 864 AccessibilityNodeData::ATTR_TITLE_UI_ELEMENT, &titleElementId)) { |
| 874 BrowserAccessibility* titleElement = | 865 BrowserAccessibility* titleElement = |
| 875 browserAccessibility_->manager()->GetFromRendererID(titleElementId); | 866 browserAccessibility_->manager()->GetFromRendererID(titleElementId); |
| 876 if (titleElement) | 867 if (titleElement) |
| 877 return titleElement->ToBrowserAccessibilityCocoa(); | 868 return titleElement->ToBrowserAccessibilityCocoa(); |
| 878 } | 869 } |
| 879 return nil; | 870 return nil; |
| 880 } | 871 } |
| 881 | 872 |
| 882 - (NSString*)url { | 873 - (NSString*)url { |
| 883 StringAttribute urlAttribute = | 874 StringAttribute urlAttribute = |
| 884 [[self role] isEqualToString:@"AXWebArea"] ? | 875 [[self role] isEqualToString:@"AXWebArea"] ? |
| 885 AccessibilityNodeData::ATTR_DOC_URL : | 876 AccessibilityNodeData::ATTR_DOC_URL : |
| 886 AccessibilityNodeData::ATTR_URL; | 877 AccessibilityNodeData::ATTR_URL; |
| 887 return NSStringForStringAttribute( | 878 return NSStringForStringAttribute(browserAccessibility_, urlAttribute); |
| 888 browserAccessibility_->string_attributes(), | |
| 889 urlAttribute); | |
| 890 } | 879 } |
| 891 | 880 |
| 892 - (id)value { | 881 - (id)value { |
| 893 // WebCore uses an attachmentView to get the below behavior. | 882 // WebCore uses an attachmentView to get the below behavior. |
| 894 // We do not have any native views backing this object, so need | 883 // We do not have any native views backing this object, so need |
| 895 // to approximate Cocoa ax behavior best as we can. | 884 // to approximate Cocoa ax behavior best as we can. |
| 896 NSString* role = [self role]; | 885 NSString* role = [self role]; |
| 897 if ([role isEqualToString:@"AXHeading"]) { | 886 if ([role isEqualToString:@"AXHeading"]) { |
| 898 int level; | 887 int level; |
| 899 if (browserAccessibility_->GetIntAttribute( | 888 if (browserAccessibility_->GetIntAttribute( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 933 AccessibilityNodeData::ATTR_COLOR_VALUE_RED, &r); | 922 AccessibilityNodeData::ATTR_COLOR_VALUE_RED, &r); |
| 934 browserAccessibility_->GetIntAttribute( | 923 browserAccessibility_->GetIntAttribute( |
| 935 AccessibilityNodeData::ATTR_COLOR_VALUE_GREEN, &g); | 924 AccessibilityNodeData::ATTR_COLOR_VALUE_GREEN, &g); |
| 936 browserAccessibility_->GetIntAttribute( | 925 browserAccessibility_->GetIntAttribute( |
| 937 AccessibilityNodeData::ATTR_COLOR_VALUE_BLUE, &b); | 926 AccessibilityNodeData::ATTR_COLOR_VALUE_BLUE, &b); |
| 938 // This string matches the one returned by a native Mac color well. | 927 // This string matches the one returned by a native Mac color well. |
| 939 return [NSString stringWithFormat:@"rgb %7.5f %7.5f %7.5f 1", | 928 return [NSString stringWithFormat:@"rgb %7.5f %7.5f %7.5f 1", |
| 940 r / 255., g / 255., b / 255.]; | 929 r / 255., g / 255., b / 255.]; |
| 941 } | 930 } |
| 942 | 931 |
| 943 return base::SysUTF16ToNSString(browserAccessibility_->value()); | 932 return NSStringForStringAttribute( |
| 933 browserAccessibility_, AccessibilityNodeData::ATTR_VALUE); | |
| 944 } | 934 } |
| 945 | 935 |
| 946 - (NSString*)valueDescription { | 936 - (NSString*)valueDescription { |
| 947 if (!browserAccessibility_->value().empty()) | 937 return NSStringForStringAttribute( |
| 948 return base::SysUTF16ToNSString(browserAccessibility_->value()); | 938 browserAccessibility_, AccessibilityNodeData::ATTR_VALUE); |
| 949 else | |
| 950 return nil; | |
| 951 } | 939 } |
| 952 | 940 |
| 953 - (NSValue*)visibleCharacterRange { | 941 - (NSValue*)visibleCharacterRange { |
| 954 return [NSValue valueWithRange: | 942 return [NSValue valueWithRange: |
| 955 NSMakeRange(0, browserAccessibility_->value().length())]; | 943 NSMakeRange(0, browserAccessibility_->value().length())]; |
| 956 } | 944 } |
| 957 | 945 |
| 958 - (NSArray*)visibleCells { | 946 - (NSArray*)visibleCells { |
| 959 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 947 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 960 const std::vector<int32>& uniqueCellIds = | 948 const std::vector<int32>& uniqueCellIds = |
| 961 browserAccessibility_->unique_cell_ids(); | 949 browserAccessibility_->GetIntListAttribute( |
| 950 AccessibilityNodeData::ATTR_UNIQUE_CELL_IDS); | |
| 962 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { | 951 for (size_t i = 0; i < uniqueCellIds.size(); ++i) { |
| 963 int id = uniqueCellIds[i]; | 952 int id = uniqueCellIds[i]; |
| 964 BrowserAccessibility* cell = | 953 BrowserAccessibility* cell = |
| 965 browserAccessibility_->manager()->GetFromRendererID(id); | 954 browserAccessibility_->manager()->GetFromRendererID(id); |
| 966 if (cell) | 955 if (cell) |
| 967 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; | 956 [ret addObject:cell->ToBrowserAccessibilityCocoa()]; |
| 968 } | 957 } |
| 969 return ret; | 958 return ret; |
| 970 } | 959 } |
| 971 | 960 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 if (browserAccessibility_->GetIntAttribute( | 995 if (browserAccessibility_->GetIntAttribute( |
| 1007 AccessibilityNodeData::ATTR_TEXT_SEL_START, &selStart) && | 996 AccessibilityNodeData::ATTR_TEXT_SEL_START, &selStart) && |
| 1008 browserAccessibility_-> | 997 browserAccessibility_-> |
| 1009 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &selEnd)) { | 998 GetIntAttribute(AccessibilityNodeData::ATTR_TEXT_SEL_END, &selEnd)) { |
| 1010 if (selStart > selEnd) | 999 if (selStart > selEnd) |
| 1011 std::swap(selStart, selEnd); | 1000 std::swap(selStart, selEnd); |
| 1012 int selLength = selEnd - selStart; | 1001 int selLength = selEnd - selStart; |
| 1013 if ([attribute isEqualToString: | 1002 if ([attribute isEqualToString: |
| 1014 NSAccessibilityInsertionPointLineNumberAttribute]) { | 1003 NSAccessibilityInsertionPointLineNumberAttribute]) { |
| 1015 const std::vector<int32>& line_breaks = | 1004 const std::vector<int32>& line_breaks = |
| 1016 browserAccessibility_->line_breaks(); | 1005 browserAccessibility_->GetIntListAttribute( |
| 1006 AccessibilityNodeData::ATTR_LINE_BREAKS); | |
| 1017 for (int i = 0; i < static_cast<int>(line_breaks.size()); ++i) { | 1007 for (int i = 0; i < static_cast<int>(line_breaks.size()); ++i) { |
| 1018 if (line_breaks[i] > selStart) | 1008 if (line_breaks[i] > selStart) |
| 1019 return [NSNumber numberWithInt:i]; | 1009 return [NSNumber numberWithInt:i]; |
| 1020 } | 1010 } |
| 1021 return [NSNumber numberWithInt:static_cast<int>(line_breaks.size())]; | 1011 return [NSNumber numberWithInt:static_cast<int>(line_breaks.size())]; |
| 1022 } | 1012 } |
| 1023 if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) { | 1013 if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) { |
| 1024 return base::SysUTF16ToNSString(browserAccessibility_->value().substr( | 1014 std::string value; |
| 1025 selStart, selLength)); | 1015 browserAccessibility_->GetStringAttribute( |
| 1016 AccessibilityNodeData::ATTR_VALUE, &value); | |
| 1017 return base::SysUTF8ToNSString(value.substr(selStart, selLength)); | |
| 1026 } | 1018 } |
| 1027 if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { | 1019 if ([attribute isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { |
| 1028 return [NSValue valueWithRange:NSMakeRange(selStart, selLength)]; | 1020 return [NSValue valueWithRange:NSMakeRange(selStart, selLength)]; |
| 1029 } | 1021 } |
| 1030 } | 1022 } |
| 1031 return nil; | 1023 return nil; |
| 1032 } | 1024 } |
| 1033 | 1025 |
| 1034 // Returns the accessibility value for the given attribute and parameter. If the | 1026 // Returns the accessibility value for the given attribute and parameter. If the |
| 1035 // value isn't supported this will return nil. | 1027 // value isn't supported this will return nil. |
| 1036 - (id)accessibilityAttributeValue:(NSString*)attribute | 1028 - (id)accessibilityAttributeValue:(NSString*)attribute |
| 1037 forParameter:(id)parameter { | 1029 forParameter:(id)parameter { |
| 1038 if (!browserAccessibility_) | 1030 if (!browserAccessibility_) |
| 1039 return nil; | 1031 return nil; |
| 1040 | 1032 |
| 1041 const std::vector<int32>& line_breaks = browserAccessibility_->line_breaks(); | 1033 const std::vector<int32>& line_breaks = |
| 1034 browserAccessibility_->GetIntListAttribute( | |
| 1035 AccessibilityNodeData::ATTR_LINE_BREAKS); | |
| 1042 int len = static_cast<int>(browserAccessibility_->value().size()); | 1036 int len = static_cast<int>(browserAccessibility_->value().size()); |
| 1043 | 1037 |
| 1044 if ([attribute isEqualToString: | 1038 if ([attribute isEqualToString: |
| 1045 NSAccessibilityStringForRangeParameterizedAttribute]) { | 1039 NSAccessibilityStringForRangeParameterizedAttribute]) { |
| 1046 NSRange range = [(NSValue*)parameter rangeValue]; | 1040 NSRange range = [(NSValue*)parameter rangeValue]; |
| 1047 return base::SysUTF16ToNSString( | 1041 std::string value; |
| 1048 browserAccessibility_->value().substr(range.location, range.length)); | 1042 browserAccessibility_->GetStringAttribute( |
| 1043 AccessibilityNodeData::ATTR_VALUE, &value); | |
| 1044 return base::SysUTF8ToNSString(value.substr(range.location, range.length)); | |
| 1049 } | 1045 } |
| 1050 | 1046 |
| 1051 if ([attribute isEqualToString: | 1047 if ([attribute isEqualToString: |
| 1052 NSAccessibilityLineForIndexParameterizedAttribute]) { | 1048 NSAccessibilityLineForIndexParameterizedAttribute]) { |
| 1053 int index = [(NSNumber*)parameter intValue]; | 1049 int index = [(NSNumber*)parameter intValue]; |
| 1054 for (int i = 0; i < static_cast<int>(line_breaks.size()); ++i) { | 1050 for (int i = 0; i < static_cast<int>(line_breaks.size()); ++i) { |
| 1055 if (line_breaks[i] > index) | 1051 if (line_breaks[i] > index) |
| 1056 return [NSNumber numberWithInt:i]; | 1052 return [NSNumber numberWithInt:i]; |
| 1057 } | 1053 } |
| 1058 return [NSNumber numberWithInt:static_cast<int>(line_breaks.size())]; | 1054 return [NSNumber numberWithInt:static_cast<int>(line_breaks.size())]; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 return [super hash]; | 1492 return [super hash]; |
| 1497 return browserAccessibility_->renderer_id(); | 1493 return browserAccessibility_->renderer_id(); |
| 1498 } | 1494 } |
| 1499 | 1495 |
| 1500 - (BOOL)accessibilityShouldUseUniqueId { | 1496 - (BOOL)accessibilityShouldUseUniqueId { |
| 1501 return YES; | 1497 return YES; |
| 1502 } | 1498 } |
| 1503 | 1499 |
| 1504 @end | 1500 @end |
| 1505 | 1501 |
| OLD | NEW |