| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 5 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // specified in accessibilityIsAttributeSettable. | 420 // specified in accessibilityIsAttributeSettable. |
| 421 } | 421 } |
| 422 | 422 |
| 423 - (id)accessibilityAttributeValue:(NSString*)attribute { | 423 - (id)accessibilityAttributeValue:(NSString*)attribute { |
| 424 SEL selector = NSSelectorFromString(attribute); | 424 SEL selector = NSSelectorFromString(attribute); |
| 425 if ([self respondsToSelector:selector]) | 425 if ([self respondsToSelector:selector]) |
| 426 return [self performSelector:selector]; | 426 return [self performSelector:selector]; |
| 427 return nil; | 427 return nil; |
| 428 } | 428 } |
| 429 | 429 |
| 430 // NSAccessibility attributes. | 430 // NSAccessibility attributes. Order them according to |
| 431 | 431 // NSAccessibilityConstants.h, or see https://crbug.com/678898. |
| 432 - (NSArray*)AXChildren { | |
| 433 if (!node_) | |
| 434 return nil; | |
| 435 int count = node_->GetChildCount(); | |
| 436 NSMutableArray* children = [NSMutableArray arrayWithCapacity:count]; | |
| 437 for (int i = 0; i < count; ++i) | |
| 438 [children addObject:node_->ChildAtIndex(i)]; | |
| 439 return NSAccessibilityUnignoredChildren(children); | |
| 440 } | |
| 441 | |
| 442 - (id)AXParent { | |
| 443 if (!node_) | |
| 444 return nil; | |
| 445 return NSAccessibilityUnignoredAncestor(node_->GetParent()); | |
| 446 } | |
| 447 | |
| 448 - (NSValue*)AXPosition { | |
| 449 return [NSValue valueWithPoint:self.boundsInScreen.origin]; | |
| 450 } | |
| 451 | 432 |
| 452 - (NSString*)AXRole { | 433 - (NSString*)AXRole { |
| 453 if (!node_) | 434 if (!node_) |
| 454 return nil; | 435 return nil; |
| 455 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; | 436 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
| 456 } | 437 } |
| 457 | 438 |
| 439 - (NSString*)AXRoleDescription { |
| 440 return NSAccessibilityRoleDescription([self AXRole], [self AXSubrole]); |
| 441 } |
| 442 |
| 458 - (NSString*)AXSubrole { | 443 - (NSString*)AXSubrole { |
| 459 ui::AXRole role = node_->GetData().role; | 444 ui::AXRole role = node_->GetData().role; |
| 460 switch (role) { | 445 switch (role) { |
| 461 case ui::AX_ROLE_TEXT_FIELD: | 446 case ui::AX_ROLE_TEXT_FIELD: |
| 462 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, | 447 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, |
| 463 ui::AX_STATE_PROTECTED)) | 448 ui::AX_STATE_PROTECTED)) |
| 464 return NSAccessibilitySecureTextFieldSubrole; | 449 return NSAccessibilitySecureTextFieldSubrole; |
| 465 break; | 450 break; |
| 466 default: | 451 default: |
| 467 break; | 452 break; |
| 468 } | 453 } |
| 469 return [AXPlatformNodeCocoa nativeSubroleFromAXRole:role]; | 454 return [AXPlatformNodeCocoa nativeSubroleFromAXRole:role]; |
| 470 } | 455 } |
| 471 | 456 |
| 472 - (NSString*)AXRoleDescription { | 457 - (NSString*)AXHelp { |
| 473 return NSAccessibilityRoleDescription([self AXRole], [self AXSubrole]); | 458 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; |
| 474 } | |
| 475 | |
| 476 - (NSValue*)AXSize { | |
| 477 return [NSValue valueWithSize:self.boundsInScreen.size]; | |
| 478 } | |
| 479 | |
| 480 - (NSString*)AXTitle { | |
| 481 return [self getStringAttribute:ui::AX_ATTR_NAME]; | |
| 482 } | 459 } |
| 483 | 460 |
| 484 - (NSString*)AXValue { | 461 - (NSString*)AXValue { |
| 485 return [self getStringAttribute:ui::AX_ATTR_VALUE]; | 462 return [self getStringAttribute:ui::AX_ATTR_VALUE]; |
| 486 } | 463 } |
| 487 | 464 |
| 488 - (NSValue*)AXEnabled { | 465 - (NSNumber*)AXEnabled { |
| 489 return [NSNumber | 466 return [NSNumber |
| 490 numberWithBool:!ui::AXNodeData::IsFlagSet(node_->GetData().state, | 467 numberWithBool:!ui::AXNodeData::IsFlagSet(node_->GetData().state, |
| 491 ui::AX_STATE_DISABLED)]; | 468 ui::AX_STATE_DISABLED)]; |
| 492 } | 469 } |
| 493 | 470 |
| 494 - (NSValue*)AXFocused { | 471 - (NSNumber*)AXFocused { |
| 495 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, | 472 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, |
| 496 ui::AX_STATE_FOCUSABLE)) | 473 ui::AX_STATE_FOCUSABLE)) |
| 497 return [NSNumber numberWithBool:(node_->GetDelegate()->GetFocus() == | 474 return [NSNumber numberWithBool:(node_->GetDelegate()->GetFocus() == |
| 498 node_->GetNativeViewAccessible())]; | 475 node_->GetNativeViewAccessible())]; |
| 499 return [NSNumber numberWithBool:NO]; | 476 return [NSNumber numberWithBool:NO]; |
| 500 } | 477 } |
| 501 | 478 |
| 502 - (NSString*)AXHelp { | 479 - (id)AXParent { |
| 503 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; | 480 if (!node_) |
| 481 return nil; |
| 482 return NSAccessibilityUnignoredAncestor(node_->GetParent()); |
| 504 } | 483 } |
| 505 | 484 |
| 506 - (NSWindow*)AXTopLevelUIElement { | 485 - (NSArray*)AXChildren { |
| 486 if (!node_) |
| 487 return nil; |
| 488 int count = node_->GetChildCount(); |
| 489 NSMutableArray* children = [NSMutableArray arrayWithCapacity:count]; |
| 490 for (int i = 0; i < count; ++i) |
| 491 [children addObject:node_->ChildAtIndex(i)]; |
| 492 return NSAccessibilityUnignoredChildren(children); |
| 493 } |
| 494 |
| 495 - (id)AXWindow { |
| 496 return node_->GetDelegate()->GetTopLevelWidget(); |
| 497 } |
| 498 |
| 499 - (id)AXTopLevelUIElement { |
| 507 return [self AXWindow]; | 500 return [self AXWindow]; |
| 508 } | 501 } |
| 509 | 502 |
| 510 - (NSWindow*)AXWindow { | 503 - (NSValue*)AXPosition { |
| 511 return node_->GetDelegate()->GetTopLevelWidget(); | 504 return [NSValue valueWithPoint:self.boundsInScreen.origin]; |
| 512 } | 505 } |
| 513 | 506 |
| 514 // Textfield-specific NSAccessibility attributes. | 507 - (NSValue*)AXSize { |
| 515 | 508 return [NSValue valueWithSize:self.boundsInScreen.size]; |
| 516 - (NSNumber*)AXInsertionPointLineNumber { | |
| 517 // Multiline is not supported on views. | |
| 518 return [NSNumber numberWithInteger:0]; | |
| 519 } | 509 } |
| 520 | 510 |
| 521 - (NSNumber*)AXNumberOfCharacters { | 511 - (NSString*)AXTitle { |
| 522 return [NSNumber numberWithInteger:[[self AXValue] length]]; | 512 return [self getStringAttribute:ui::AX_ATTR_NAME]; |
| 523 } | 513 } |
| 524 | 514 |
| 515 // Misc attributes. |
| 516 |
| 525 - (NSString*)AXPlaceholderValue { | 517 - (NSString*)AXPlaceholderValue { |
| 526 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER]; | 518 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER]; |
| 527 } | 519 } |
| 528 | 520 |
| 521 // Text-specific attributes. |
| 522 |
| 529 - (NSString*)AXSelectedText { | 523 - (NSString*)AXSelectedText { |
| 530 NSRange selectedTextRange; | 524 NSRange selectedTextRange; |
| 531 [[self AXSelectedTextRange] getValue:&selectedTextRange]; | 525 [[self AXSelectedTextRange] getValue:&selectedTextRange]; |
| 532 return [[self AXValue] substringWithRange:selectedTextRange]; | 526 return [[self AXValue] substringWithRange:selectedTextRange]; |
| 533 } | 527 } |
| 534 | 528 |
| 535 - (NSValue*)AXSelectedTextRange { | 529 - (NSValue*)AXSelectedTextRange { |
| 536 int textDir, start, end; | 530 int textDir, start, end; |
| 537 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir); | 531 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir); |
| 538 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); | 532 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); |
| 539 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); | 533 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); |
| 540 // NSRange cannot represent the direction the text was selected in, so make | 534 // NSRange cannot represent the direction the text was selected in, so make |
| 541 // sure the correct selection index is used when creating a new range, taking | 535 // sure the correct selection index is used when creating a new range, taking |
| 542 // into account the textfield text direction as well. | 536 // into account the textfield text direction as well. |
| 543 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) || | 537 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) || |
| 544 (textDir == ui::AX_TEXT_DIRECTION_BTT); | 538 (textDir == ui::AX_TEXT_DIRECTION_BTT); |
| 545 int beginSelectionIndex = (end > start && !isReversed) ? start : end; | 539 int beginSelectionIndex = (end > start && !isReversed) ? start : end; |
| 546 return [NSValue | 540 return [NSValue |
| 547 valueWithRange:NSMakeRange(beginSelectionIndex, abs(end - start))]; | 541 valueWithRange:NSMakeRange(beginSelectionIndex, abs(end - start))]; |
| 548 } | 542 } |
| 549 | 543 |
| 544 - (NSNumber*)AXNumberOfCharacters { |
| 545 return [NSNumber numberWithInteger:[[self AXValue] length]]; |
| 546 } |
| 547 |
| 550 - (NSValue*)AXVisibleCharacterRange { | 548 - (NSValue*)AXVisibleCharacterRange { |
| 551 return [NSValue | 549 return [NSValue |
| 552 valueWithRange:NSMakeRange(0, [[self AXNumberOfCharacters] intValue])]; | 550 valueWithRange:NSMakeRange(0, [[self AXNumberOfCharacters] intValue])]; |
| 553 } | 551 } |
| 554 | 552 |
| 553 - (NSNumber*)AXInsertionPointLineNumber { |
| 554 // Multiline is not supported on views. |
| 555 return [NSNumber numberWithInteger:0]; |
| 556 } |
| 557 |
| 555 @end | 558 @end |
| 556 | 559 |
| 557 namespace ui { | 560 namespace ui { |
| 558 | 561 |
| 559 // static | 562 // static |
| 560 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { | 563 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
| 561 AXPlatformNodeBase* node = new AXPlatformNodeMac(); | 564 AXPlatformNodeBase* node = new AXPlatformNodeMac(); |
| 562 node->Init(delegate); | 565 node->Init(delegate); |
| 563 return node; | 566 return node; |
| 564 } | 567 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 601 } |
| 599 NotifyMacEvent(native_node_, event_type); | 602 NotifyMacEvent(native_node_, event_type); |
| 600 } | 603 } |
| 601 | 604 |
| 602 int AXPlatformNodeMac::GetIndexInParent() { | 605 int AXPlatformNodeMac::GetIndexInParent() { |
| 603 // TODO(dmazzoni): implement this. http://crbug.com/396137 | 606 // TODO(dmazzoni): implement this. http://crbug.com/396137 |
| 604 return -1; | 607 return -1; |
| 605 } | 608 } |
| 606 | 609 |
| 607 } // namespace ui | 610 } // namespace ui |
| OLD | NEW |