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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 case ui::AX_ROLE_TOGGLE_BUTTON: | 405 case ui::AX_ROLE_TOGGLE_BUTTON: |
406 [axAttributes addObjectsFromArray:kValueAttributes]; | 406 [axAttributes addObjectsFromArray:kValueAttributes]; |
407 break; | 407 break; |
408 // TODO(tapted): Add additional attributes based on role. | 408 // TODO(tapted): Add additional attributes based on role. |
409 default: | 409 default: |
410 break; | 410 break; |
411 } | 411 } |
412 return axAttributes.autorelease(); | 412 return axAttributes.autorelease(); |
413 } | 413 } |
414 | 414 |
415 - (NSArray*)accessibilityParameterizedAttributeNames { | |
416 if (!node_) | |
417 return nil; | |
418 | |
419 static NSArray* const kEditableTextAttributes = [@[ | |
420 NSAccessibilityLineForIndexParameterizedAttribute, | |
421 NSAccessibilityRangeForLineParameterizedAttribute, | |
422 NSAccessibilityStringForRangeParameterizedAttribute, | |
423 NSAccessibilityRangeForPositionParameterizedAttribute, | |
424 NSAccessibilityRangeForIndexParameterizedAttribute, | |
425 NSAccessibilityBoundsForRangeParameterizedAttribute, | |
426 NSAccessibilityRTFForRangeParameterizedAttribute, | |
427 NSAccessibilityStyleRangeForIndexParameterizedAttribute, | |
428 NSAccessibilityAttributedStringForRangeParameterizedAttribute, | |
429 ] retain]; | |
430 | |
431 switch (node_->GetData().role) { | |
432 case ui::AX_ROLE_TEXT_FIELD: | |
433 case ui::AX_ROLE_STATIC_TEXT: | |
434 return kEditableTextAttributes; | |
dmazzoni
2017/06/26 16:50:05
If we're exposing these for STATIC_TEXT, maybe a b
tapted
2017/06/27 00:56:24
Good point! Done.
| |
435 default: | |
436 break; | |
437 } | |
438 return nil; | |
439 } | |
440 | |
415 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName { | 441 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName { |
416 if (node_->GetData().HasState(ui::AX_STATE_DISABLED)) | 442 if (node_->GetData().HasState(ui::AX_STATE_DISABLED)) |
417 return NO; | 443 return NO; |
418 | 444 |
419 // Allow certain attributes to be written via an accessibility client. A | 445 // Allow certain attributes to be written via an accessibility client. A |
420 // writable attribute will only appear as such if the accessibility element | 446 // writable attribute will only appear as such if the accessibility element |
421 // has a value set for that attribute. | 447 // has a value set for that attribute. |
422 if ([attributeName | 448 if ([attributeName |
423 isEqualToString:NSAccessibilitySelectedChildrenAttribute] || | 449 isEqualToString:NSAccessibilitySelectedChildrenAttribute] || |
424 [attributeName | 450 [attributeName |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 // specified in accessibilityIsAttributeSettable. | 513 // specified in accessibilityIsAttributeSettable. |
488 } | 514 } |
489 | 515 |
490 - (id)accessibilityAttributeValue:(NSString*)attribute { | 516 - (id)accessibilityAttributeValue:(NSString*)attribute { |
491 SEL selector = NSSelectorFromString(attribute); | 517 SEL selector = NSSelectorFromString(attribute); |
492 if ([self respondsToSelector:selector]) | 518 if ([self respondsToSelector:selector]) |
493 return [self performSelector:selector]; | 519 return [self performSelector:selector]; |
494 return nil; | 520 return nil; |
495 } | 521 } |
496 | 522 |
523 - (id)accessibilityAttributeValue:(NSString*)attribute | |
524 forParameter:(id)parameter { | |
525 SEL selector = NSSelectorFromString([attribute stringByAppendingString:@":"]); | |
526 if ([self respondsToSelector:selector]) | |
527 return [self performSelector:selector withObject:parameter]; | |
528 return nil; | |
529 } | |
530 | |
497 // NSAccessibility attributes. Order them according to | 531 // NSAccessibility attributes. Order them according to |
498 // NSAccessibilityConstants.h, or see https://crbug.com/678898. | 532 // NSAccessibilityConstants.h, or see https://crbug.com/678898. |
499 | 533 |
500 - (NSString*)AXRole { | 534 - (NSString*)AXRole { |
501 if (!node_) | 535 if (!node_) |
502 return nil; | 536 return nil; |
503 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; | 537 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
504 } | 538 } |
505 | 539 |
506 - (NSString*)AXRoleDescription { | 540 - (NSString*)AXRoleDescription { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 | 660 |
627 - (NSValue*)AXVisibleCharacterRange { | 661 - (NSValue*)AXVisibleCharacterRange { |
628 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; | 662 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; |
629 } | 663 } |
630 | 664 |
631 - (NSNumber*)AXInsertionPointLineNumber { | 665 - (NSNumber*)AXInsertionPointLineNumber { |
632 // Multiline is not supported on views. | 666 // Multiline is not supported on views. |
633 return @0; | 667 return @0; |
634 } | 668 } |
635 | 669 |
670 // Parameterized text-specific attributes. | |
671 | |
672 - (id)AXLineForIndex:(id)parameter { | |
673 DCHECK([parameter isKindOfClass:[NSNumber class]]); | |
674 // Multiline is not supported on views. | |
675 return @0; | |
tapted
2017/06/26 09:18:51
This matches what's currently done for AXInsertion
| |
676 } | |
677 | |
678 - (id)AXRangeForLine:(id)parameter { | |
679 DCHECK([parameter isKindOfClass:[NSNumber class]]); | |
680 DCHECK_EQ(0, [parameter intValue]); | |
681 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; | |
682 } | |
683 | |
684 - (id)AXStringForRange:(id)parameter { | |
685 DCHECK([parameter isKindOfClass:[NSValue class]]); | |
686 return [[self getAXValueAsString] substringWithRange:[parameter rangeValue]]; | |
687 } | |
688 | |
689 - (id)AXRangeForPosition:(id)parameter { | |
690 DCHECK([parameter isKindOfClass:[NSValue class]]); | |
691 // TODO(tapted): Hit-test [parameter pointValue] and return an NSRange. | |
692 NOTIMPLEMENTED(); | |
693 return nil; | |
694 } | |
695 | |
696 - (id)AXRangeForIndex:(id)parameter { | |
697 DCHECK([parameter isKindOfClass:[NSNumber class]]); | |
698 NOTIMPLEMENTED(); | |
699 return nil; | |
700 } | |
701 | |
702 - (id)AXBoundsForRange:(id)parameter { | |
703 DCHECK([parameter isKindOfClass:[NSValue class]]); | |
704 // TODO(tapted): Provide an accessor on AXPlatformNodeDelegate to obtain this | |
705 // from ui::TextInputClient::GetCompositionCharacterBounds(). | |
706 NOTIMPLEMENTED(); | |
tapted
2017/06/26 09:18:51
This is the only one I've been able to hit with ba
| |
707 return nil; | |
708 } | |
709 | |
710 - (id)AXRTFForRange:(id)parameter { | |
711 DCHECK([parameter isKindOfClass:[NSValue class]]); | |
712 NOTIMPLEMENTED(); | |
713 return nil; | |
714 } | |
715 | |
716 - (id)AXStyleRangeForIndex:(id)parameter { | |
717 DCHECK([parameter isKindOfClass:[NSNumber class]]); | |
718 NOTIMPLEMENTED(); | |
719 return nil; | |
720 } | |
721 | |
722 - (id)AXAttributedStringForRange:(id)parameter { | |
723 DCHECK([parameter isKindOfClass:[NSValue class]]); | |
724 base::scoped_nsobject<NSAttributedString> attributedString( | |
725 [[NSAttributedString alloc] | |
726 initWithString:[self AXStringForRange:parameter]]); | |
727 // TODO(tapted): views::WordLookupClient has a way to obtain the actual | |
728 // decorations, and BridgedContentView has a conversion function that creates | |
729 // an NSAttributedString. Refactor things so they can be used here. | |
730 return attributedString.autorelease(); | |
731 } | |
732 | |
636 @end | 733 @end |
637 | 734 |
638 namespace ui { | 735 namespace ui { |
639 | 736 |
640 // static | 737 // static |
641 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { | 738 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
642 AXPlatformNodeBase* node = new AXPlatformNodeMac(); | 739 AXPlatformNodeBase* node = new AXPlatformNodeMac(); |
643 node->Init(delegate); | 740 node->Init(delegate); |
644 return node; | 741 return node; |
645 } | 742 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 } | 784 } |
688 NotifyMacEvent(native_node_, event_type); | 785 NotifyMacEvent(native_node_, event_type); |
689 } | 786 } |
690 | 787 |
691 int AXPlatformNodeMac::GetIndexInParent() { | 788 int AXPlatformNodeMac::GetIndexInParent() { |
692 // TODO(dmazzoni): implement this. http://crbug.com/396137 | 789 // TODO(dmazzoni): implement this. http://crbug.com/396137 |
693 return -1; | 790 return -1; |
694 } | 791 } |
695 | 792 |
696 } // namespace ui | 793 } // namespace ui |
OLD | NEW |