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

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

Issue 2010493005: a11y/Mac: Add screenreader support for SubtleNotificationView announcements. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/views/subtle_notification_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #import "base/mac/sdk_forward_declarations.h"
11 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
12 #include "ui/accessibility/ax_node_data.h" 13 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/accessibility/platform/ax_platform_node_delegate.h" 15 #include "ui/accessibility/platform/ax_platform_node_delegate.h"
15 #import "ui/gfx/mac/coordinate_conversion.h" 16 #import "ui/gfx/mac/coordinate_conversion.h"
16 17
17 namespace { 18 namespace {
18 19
19 struct RoleMapEntry { 20 struct RoleMapEntry {
20 ui::AXRole value; 21 ui::AXRole value;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 }; 193 };
193 194
194 RoleMap subrole_map; 195 RoleMap subrole_map;
195 for (size_t i = 0; i < arraysize(subroles); ++i) 196 for (size_t i = 0; i < arraysize(subroles); ++i)
196 subrole_map[subroles[i].value] = subroles[i].nativeValue; 197 subrole_map[subroles[i].value] = subroles[i].nativeValue;
197 return subrole_map; 198 return subrole_map;
198 } 199 }
199 200
200 EventMap BuildEventMap() { 201 EventMap BuildEventMap() {
201 const EventMapEntry events[] = { 202 const EventMapEntry events[] = {
203 {ui::AX_EVENT_CHILDREN_CHANGED, NSAccessibilityLayoutChangedNotification},
202 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification}, 204 {ui::AX_EVENT_TEXT_CHANGED, NSAccessibilityTitleChangedNotification},
203 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification},
204 {ui::AX_EVENT_TEXT_SELECTION_CHANGED, 205 {ui::AX_EVENT_TEXT_SELECTION_CHANGED,
205 NSAccessibilitySelectedTextChangedNotification}, 206 NSAccessibilitySelectedTextChangedNotification},
207 {ui::AX_EVENT_VALUE_CHANGED, NSAccessibilityValueChangedNotification},
206 // TODO(patricialor): Add more events. 208 // TODO(patricialor): Add more events.
207 }; 209 };
208 210
209 EventMap event_map; 211 EventMap event_map;
210 for (size_t i = 0; i < arraysize(events); ++i) 212 for (size_t i = 0; i < arraysize(events); ++i)
211 event_map[events[i].value] = events[i].nativeValue; 213 event_map[events[i].value] = events[i].nativeValue;
212 return event_map; 214 return event_map;
213 } 215 }
214 216
215 void NotifyMacEvent(NSView* target, ui::AXEvent event_type) { 217 void NotifyMacEvent(NSView* target, ui::AXEvent event_type) {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]); 553 native_node_.reset([[AXPlatformNodeCocoa alloc] initWithNode:this]);
552 return native_node_.get(); 554 return native_node_.get();
553 } 555 }
554 556
555 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { 557 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) {
556 NSView* target = GetDelegate()->GetTargetForNativeAccessibilityEvent(); 558 NSView* target = GetDelegate()->GetTargetForNativeAccessibilityEvent();
557 559
558 // Add mappings between ui::AXEvent and NSAccessibility notifications using 560 // Add mappings between ui::AXEvent and NSAccessibility notifications using
559 // the EventMap above. This switch contains exceptions to those mappings. 561 // the EventMap above. This switch contains exceptions to those mappings.
560 switch (event_type) { 562 switch (event_type) {
563 case ui::AX_EVENT_ALERT: {
564 NSString* announcement = base::SysUTF8ToNSString(
565 GetData().GetStringAttribute(ui::AX_ATTR_NAME));
566 NSDictionary* notification_info = @{
567 NSAccessibilityAnnouncementKey : announcement,
568 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
569 };
570 NSAccessibilityPostNotificationWithUserInfo(
571 [NSApp mainWindow], NSAccessibilityAnnouncementRequestedNotification,
572 notification_info);
573 return;
574 }
561 case ui::AX_EVENT_TEXT_CHANGED: 575 case ui::AX_EVENT_TEXT_CHANGED:
562 // If the view is a user-editable textfield, this should change the value. 576 // If the view is a user-editable textfield, this should change the value.
563 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) { 577 if (GetData().role == ui::AX_ROLE_TEXT_FIELD) {
564 NotifyMacEvent(target, ui::AX_EVENT_VALUE_CHANGED); 578 NotifyMacEvent(target, ui::AX_EVENT_VALUE_CHANGED);
565 return; 579 return;
566 } 580 }
567 break; 581 break;
568 default: 582 default:
569 break; 583 break;
570 } 584 }
571 NotifyMacEvent(target, event_type); 585 NotifyMacEvent(target, event_type);
572 } 586 }
573 587
574 int AXPlatformNodeMac::GetIndexInParent() { 588 int AXPlatformNodeMac::GetIndexInParent() {
575 // TODO(dmazzoni): implement this. http://crbug.com/396137 589 // TODO(dmazzoni): implement this. http://crbug.com/396137
576 return -1; 590 return -1;
577 } 591 }
578 592
579 } // namespace ui 593 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/subtle_notification_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698