Chromium Code Reviews| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 NSAccessibilityEnabledAttribute, | 348 NSAccessibilityEnabledAttribute, |
| 349 NSAccessibilityFocusedAttribute, | 349 NSAccessibilityFocusedAttribute, |
| 350 NSAccessibilityHelpAttribute, | 350 NSAccessibilityHelpAttribute, |
| 351 NSAccessibilityTopLevelUIElementAttribute, | 351 NSAccessibilityTopLevelUIElementAttribute, |
| 352 NSAccessibilityWindowAttribute, | 352 NSAccessibilityWindowAttribute, |
| 353 ]; | 353 ]; |
| 354 | 354 |
| 355 // Attributes required for user-editable controls. | 355 // Attributes required for user-editable controls. |
| 356 NSArray* const kValueAttributes = @[ NSAccessibilityValueAttribute ]; | 356 NSArray* const kValueAttributes = @[ NSAccessibilityValueAttribute ]; |
| 357 | 357 |
| 358 // Attributes required for textfields. | 358 // Attributes required for unprotected textfields. |
| 359 NSArray* const kTextfieldAttributes = @[ | 359 NSArray* const kUnprotectedTextfieldAttributes = @[ |
| 360 NSAccessibilityInsertionPointLineNumberAttribute, | 360 NSAccessibilityInsertionPointLineNumberAttribute, |
| 361 NSAccessibilityNumberOfCharactersAttribute, | 361 NSAccessibilityNumberOfCharactersAttribute, |
| 362 NSAccessibilityPlaceholderValueAttribute, | |
| 363 NSAccessibilitySelectedTextAttribute, | 362 NSAccessibilitySelectedTextAttribute, |
| 364 NSAccessibilitySelectedTextRangeAttribute, | 363 NSAccessibilitySelectedTextRangeAttribute, |
| 365 NSAccessibilityVisibleCharacterRangeAttribute, | 364 NSAccessibilityVisibleCharacterRangeAttribute, |
| 366 ]; | 365 ]; |
| 367 | 366 |
| 367 // Required for all textfields, including protected ones. | |
| 368 NSString* const kTextfieldAttributes = | |
| 369 NSAccessibilityPlaceholderValueAttribute; | |
| 370 | |
| 368 base::scoped_nsobject<NSMutableArray> axAttributes( | 371 base::scoped_nsobject<NSMutableArray> axAttributes( |
| 369 [[NSMutableArray alloc] init]); | 372 [[NSMutableArray alloc] init]); |
| 370 | 373 |
| 371 [axAttributes addObjectsFromArray:kAllRoleAttributes]; | 374 [axAttributes addObjectsFromArray:kAllRoleAttributes]; |
| 372 switch (node_->GetData().role) { | 375 switch (node_->GetData().role) { |
| 373 case ui::AX_ROLE_TEXT_FIELD: | 376 case ui::AX_ROLE_TEXT_FIELD: |
| 374 [axAttributes addObjectsFromArray:kTextfieldAttributes]; | 377 [axAttributes addObject:kTextfieldAttributes]; |
| 378 if (!ui::AXNodeData::IsFlagSet(node_->GetData().state, | |
| 379 ui::AX_STATE_PROTECTED)) { | |
| 380 [axAttributes addObjectsFromArray:kUnprotectedTextfieldAttributes]; | |
| 381 } | |
| 375 // Fallthrough. | 382 // Fallthrough. |
| 376 case ui::AX_ROLE_CHECK_BOX: | 383 case ui::AX_ROLE_CHECK_BOX: |
| 377 case ui::AX_ROLE_COMBO_BOX: | 384 case ui::AX_ROLE_COMBO_BOX: |
| 378 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: | 385 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: |
| 379 case ui::AX_ROLE_MENU_ITEM_RADIO: | 386 case ui::AX_ROLE_MENU_ITEM_RADIO: |
| 380 case ui::AX_ROLE_RADIO_BUTTON: | 387 case ui::AX_ROLE_RADIO_BUTTON: |
| 381 case ui::AX_ROLE_SEARCH_BOX: | 388 case ui::AX_ROLE_SEARCH_BOX: |
| 382 case ui::AX_ROLE_SLIDER: | 389 case ui::AX_ROLE_SLIDER: |
| 383 case ui::AX_ROLE_SLIDER_THUMB: | 390 case ui::AX_ROLE_SLIDER_THUMB: |
| 384 case ui::AX_ROLE_TOGGLE_BUTTON: | 391 case ui::AX_ROLE_TOGGLE_BUTTON: |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 return @(node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)); | 583 return @(node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)); |
| 577 } | 584 } |
| 578 | 585 |
| 579 - (NSString*)AXPlaceholderValue { | 586 - (NSString*)AXPlaceholderValue { |
| 580 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER]; | 587 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER]; |
| 581 } | 588 } |
| 582 | 589 |
| 583 // Text-specific attributes. | 590 // Text-specific attributes. |
| 584 | 591 |
| 585 - (NSString*)AXSelectedText { | 592 - (NSString*)AXSelectedText { |
| 593 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED)) | |
| 594 return nil; | |
|
tapted
2017/02/21 04:28:46
nit: blank line after
Patti Lor
2017/02/23 04:24:18
Done.
| |
| 586 NSRange selectedTextRange; | 595 NSRange selectedTextRange; |
| 587 [[self AXSelectedTextRange] getValue:&selectedTextRange]; | 596 [[self AXSelectedTextRange] getValue:&selectedTextRange]; |
| 588 return [[self AXValue] substringWithRange:selectedTextRange]; | 597 return [[self AXValue] substringWithRange:selectedTextRange]; |
| 589 } | 598 } |
| 590 | 599 |
| 591 - (NSValue*)AXSelectedTextRange { | 600 - (NSValue*)AXSelectedTextRange { |
| 601 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED)) | |
| 602 return nil; | |
|
tapted
2017/02/21 04:28:46
nit: blank line after (for the 3 below I wouldn't
Patti Lor
2017/02/23 04:24:18
Done.
| |
| 592 int textDir, start, end; | 603 int textDir, start, end; |
| 593 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir); | 604 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir); |
| 594 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); | 605 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); |
| 595 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); | 606 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); |
| 596 // NSRange cannot represent the direction the text was selected in, so make | 607 // NSRange cannot represent the direction the text was selected in, so make |
| 597 // sure the correct selection index is used when creating a new range, taking | 608 // sure the correct selection index is used when creating a new range, taking |
| 598 // into account the textfield text direction as well. | 609 // into account the textfield text direction as well. |
| 599 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) || | 610 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) || |
| 600 (textDir == ui::AX_TEXT_DIRECTION_BTT); | 611 (textDir == ui::AX_TEXT_DIRECTION_BTT); |
| 601 int beginSelectionIndex = (end > start && !isReversed) ? start : end; | 612 int beginSelectionIndex = (end > start && !isReversed) ? start : end; |
| 602 return [NSValue valueWithRange:{beginSelectionIndex, abs(end - start)}]; | 613 return [NSValue valueWithRange:{beginSelectionIndex, abs(end - start)}]; |
| 603 } | 614 } |
| 604 | 615 |
| 605 - (NSNumber*)AXNumberOfCharacters { | 616 - (NSNumber*)AXNumberOfCharacters { |
| 617 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED)) | |
| 618 return nil; | |
| 606 return @([[self AXValue] length]); | 619 return @([[self AXValue] length]); |
| 607 } | 620 } |
| 608 | 621 |
| 609 - (NSValue*)AXVisibleCharacterRange { | 622 - (NSValue*)AXVisibleCharacterRange { |
| 623 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED)) | |
| 624 return nil; | |
| 610 return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}]; | 625 return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}]; |
| 611 } | 626 } |
| 612 | 627 |
| 613 - (NSNumber*)AXInsertionPointLineNumber { | 628 - (NSNumber*)AXInsertionPointLineNumber { |
| 629 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED)) | |
| 630 return nil; | |
| 614 // Multiline is not supported on views. | 631 // Multiline is not supported on views. |
| 615 return @0; | 632 return @0; |
| 616 } | 633 } |
| 617 | 634 |
| 618 @end | 635 @end |
| 619 | 636 |
| 620 namespace ui { | 637 namespace ui { |
| 621 | 638 |
| 622 // static | 639 // static |
| 623 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { | 640 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 } | 678 } |
| 662 NotifyMacEvent(native_node_, event_type); | 679 NotifyMacEvent(native_node_, event_type); |
| 663 } | 680 } |
| 664 | 681 |
| 665 int AXPlatformNodeMac::GetIndexInParent() { | 682 int AXPlatformNodeMac::GetIndexInParent() { |
| 666 // TODO(dmazzoni): implement this. http://crbug.com/396137 | 683 // TODO(dmazzoni): implement this. http://crbug.com/396137 |
| 667 return -1; | 684 return -1; |
| 668 } | 685 } |
| 669 | 686 |
| 670 } // namespace ui | 687 } // namespace ui |
| OLD | NEW |