Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: ui/accessibility/platform/ax_platform_node_mac.mm

Issue 2706743002: MacViews/a11y: Disable most text-specific attributes for protected textfields. (Closed)
Patch Set: Fix string problems. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 13 matching lines...) Expand all
398 // Allow certain attributes to be written via an accessibility client. A 405 // Allow certain attributes to be written via an accessibility client. A
399 // writable attribute will only appear as such if the accessibility element 406 // writable attribute will only appear as such if the accessibility element
400 // has a value set for that attribute. 407 // has a value set for that attribute.
401 if ([attributeName 408 if ([attributeName
402 isEqualToString:NSAccessibilitySelectedChildrenAttribute] || 409 isEqualToString:NSAccessibilitySelectedChildrenAttribute] ||
403 [attributeName 410 [attributeName
404 isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) { 411 isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) {
405 return NO; 412 return NO;
406 } 413 }
407 414
408 // Since tabs use the Radio Button role on Mac, the standard way to set them 415 if ([attributeName isEqualToString:NSAccessibilityValueAttribute]) {
409 // is via the value attribute rather than the selected attribute. 416 // Since tabs use the Radio Button role on Mac, the standard way to set them
410 if ([attributeName isEqualToString:NSAccessibilityValueAttribute] && 417 // is via the value attribute rather than the selected attribute.
411 node_->GetData().role == ui::AX_ROLE_TAB) { 418 if (node_->GetData().role == ui::AX_ROLE_TAB)
412 return !node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED); 419 return !node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED);
420 // NSSecureTextField doesn't allow values to be edited (despite showing up
421 // as editable), match its behavior.
422 else if (node_->GetData().HasStateFlag(ui::AX_STATE_PROTECTED))
tapted 2017/02/23 06:20:34 nit: no else after return, also should this check
Patti Lor 2017/02/24 04:36:14 The else is a no-op, so I just left it out. Is it
423 return NO;
413 } 424 }
414 425
415 if ([attributeName isEqualToString:NSAccessibilityValueAttribute] || 426 if ([attributeName isEqualToString:NSAccessibilityValueAttribute] ||
416 [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute] || 427 [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute] ||
417 [attributeName 428 [attributeName
418 isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) { 429 isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
419 return !ui::AXNodeData::IsFlagSet(node_->GetData().state, 430 return !ui::AXNodeData::IsFlagSet(node_->GetData().state,
420 ui::AX_STATE_READ_ONLY); 431 ui::AX_STATE_READ_ONLY);
421 } 432 }
422 433
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 return @(node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)); 587 return @(node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED));
577 } 588 }
578 589
579 - (NSString*)AXPlaceholderValue { 590 - (NSString*)AXPlaceholderValue {
580 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER]; 591 return [self getStringAttribute:ui::AX_ATTR_PLACEHOLDER];
581 } 592 }
582 593
583 // Text-specific attributes. 594 // Text-specific attributes.
584 595
585 - (NSString*)AXSelectedText { 596 - (NSString*)AXSelectedText {
597 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
598 return nil;
599
586 NSRange selectedTextRange; 600 NSRange selectedTextRange;
587 [[self AXSelectedTextRange] getValue:&selectedTextRange]; 601 [[self AXSelectedTextRange] getValue:&selectedTextRange];
588 return [[self AXValue] substringWithRange:selectedTextRange]; 602 return [[self AXValue] substringWithRange:selectedTextRange];
589 } 603 }
590 604
591 - (NSValue*)AXSelectedTextRange { 605 - (NSValue*)AXSelectedTextRange {
606 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
607 return nil;
608
592 int textDir, start, end; 609 int textDir, start, end;
593 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir); 610 node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir);
594 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); 611 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start);
595 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); 612 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end);
596 // NSRange cannot represent the direction the text was selected in, so make 613 // 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 614 // sure the correct selection index is used when creating a new range, taking
598 // into account the textfield text direction as well. 615 // into account the textfield text direction as well.
599 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) || 616 bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) ||
600 (textDir == ui::AX_TEXT_DIRECTION_BTT); 617 (textDir == ui::AX_TEXT_DIRECTION_BTT);
601 int beginSelectionIndex = (end > start && !isReversed) ? start : end; 618 int beginSelectionIndex = (end > start && !isReversed) ? start : end;
602 return [NSValue valueWithRange:{beginSelectionIndex, abs(end - start)}]; 619 return [NSValue valueWithRange:{beginSelectionIndex, abs(end - start)}];
603 } 620 }
604 621
605 - (NSNumber*)AXNumberOfCharacters { 622 - (NSNumber*)AXNumberOfCharacters {
623 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
624 return nil;
606 return @([[self AXValue] length]); 625 return @([[self AXValue] length]);
607 } 626 }
608 627
609 - (NSValue*)AXVisibleCharacterRange { 628 - (NSValue*)AXVisibleCharacterRange {
629 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
630 return nil;
610 return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}]; 631 return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}];
611 } 632 }
612 633
613 - (NSNumber*)AXInsertionPointLineNumber { 634 - (NSNumber*)AXInsertionPointLineNumber {
635 if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
636 return nil;
614 // Multiline is not supported on views. 637 // Multiline is not supported on views.
615 return @0; 638 return @0;
616 } 639 }
617 640
618 @end 641 @end
619 642
620 namespace ui { 643 namespace ui {
621 644
622 // static 645 // static
623 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { 646 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } 684 }
662 NotifyMacEvent(native_node_, event_type); 685 NotifyMacEvent(native_node_, event_type);
663 } 686 }
664 687
665 int AXPlatformNodeMac::GetIndexInParent() { 688 int AXPlatformNodeMac::GetIndexInParent() {
666 // TODO(dmazzoni): implement this. http://crbug.com/396137 689 // TODO(dmazzoni): implement this. http://crbug.com/396137
667 return -1; 690 return -1;
668 } 691 }
669 692
670 } // namespace ui 693 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698