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

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

Issue 2016243002: Mac a11y: Add RoleDescription and Value attributes to accessibility information. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TODO for comparing against Cocoa. Created 4 years, 6 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 | « no previous file | ui/gfx/mac/coordinate_conversion.h » ('j') | ui/gfx/mac/coordinate_conversion.h » ('J')
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"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 }; 183 };
184 184
185 RoleMap subrole_map; 185 RoleMap subrole_map;
186 for (size_t i = 0; i < arraysize(subroles); ++i) 186 for (size_t i = 0; i < arraysize(subroles); ++i)
187 subrole_map[subroles[i].value] = subroles[i].nativeValue; 187 subrole_map[subroles[i].value] = subroles[i].nativeValue;
188 return subrole_map; 188 return subrole_map;
189 } 189 }
190 190
191 } // namespace 191 } // namespace
192 192
193 @interface AXPlatformNodeCocoa ()
194 // Helper function for string attributes that don't require extra processing.
195 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute;
196 @end
197
193 @implementation AXPlatformNodeCocoa 198 @implementation AXPlatformNodeCocoa
194 199
195 // A mapping of AX roles to native roles. 200 // A mapping of AX roles to native roles.
196 + (NSString*)nativeRoleFromAXRole:(ui::AXRole)role { 201 + (NSString*)nativeRoleFromAXRole:(ui::AXRole)role {
197 CR_DEFINE_STATIC_LOCAL(RoleMap, role_map, (BuildRoleMap())); 202 CR_DEFINE_STATIC_LOCAL(RoleMap, role_map, (BuildRoleMap()));
198 RoleMap::iterator it = role_map.find(role); 203 RoleMap::iterator it = role_map.find(role);
199 return it != role_map.end() ? it->second : NSAccessibilityUnknownRole; 204 return it != role_map.end() ? it->second : NSAccessibilityUnknownRole;
200 } 205 }
201 206
202 // A mapping of AX roles to native subroles. 207 // A mapping of AX roles to native subroles.
(...skipping 13 matching lines...) Expand all
216 - (void)detach { 221 - (void)detach {
217 node_ = nil; 222 node_ = nil;
218 } 223 }
219 224
220 - (NSRect)boundsInScreen { 225 - (NSRect)boundsInScreen {
221 if (!node_) 226 if (!node_)
222 return NSZeroRect; 227 return NSZeroRect;
223 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); 228 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen());
224 } 229 }
225 230
226 - (NSArray*)AXChildren { 231 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute {
227 if (!node_) 232 std::string attributeValue;
228 return nil; 233 if (node_->GetStringAttribute(attribute, &attributeValue))
229 int count = node_->GetChildCount(); 234 return base::SysUTF8ToNSString(attributeValue);
230 NSMutableArray* children = [NSMutableArray arrayWithCapacity:count];
231 for (int i = 0; i < count; ++i)
232 [children addObject:node_->ChildAtIndex(i)];
233 return NSAccessibilityUnignoredChildren(children);
234 }
235
236 - (id)AXParent {
237 if (!node_)
238 return nil;
239 return NSAccessibilityUnignoredAncestor(node_->GetParent());
240 }
241
242 - (NSValue*)AXPosition {
243 return [NSValue valueWithPoint:self.boundsInScreen.origin];
244 }
245
246 - (NSString*)AXRole {
247 if (!node_)
248 return nil;
249 return [[self class] nativeRoleFromAXRole:node_->GetData().role];
250 }
251
252 - (NSValue*)AXSize {
253 return [NSValue valueWithSize:self.boundsInScreen.size];
254 }
255
256 - (NSString*)AXTitle {
257 std::string value;
258 if (node_->GetStringAttribute(ui::AX_ATTR_NAME, &value))
259 return base::SysUTF8ToNSString(value);
260 return nil; 235 return nil;
261 } 236 }
262 237
263 // NSAccessibility informal protocol implementation. 238 // NSAccessibility informal protocol implementation.
264 239
265 - (BOOL)accessibilityIsIgnored { 240 - (BOOL)accessibilityIsIgnored {
266 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole]; 241 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole];
267 } 242 }
268 243
269 - (id)accessibilityHitTest:(NSPoint)point { 244 - (id)accessibilityHitTest:(NSPoint)point {
(...skipping 13 matching lines...) Expand all
283 return @[ 258 return @[
284 NSAccessibilityChildrenAttribute, 259 NSAccessibilityChildrenAttribute,
285 NSAccessibilityParentAttribute, 260 NSAccessibilityParentAttribute,
286 NSAccessibilityPositionAttribute, 261 NSAccessibilityPositionAttribute,
287 NSAccessibilityRoleAttribute, 262 NSAccessibilityRoleAttribute,
288 NSAccessibilitySizeAttribute, 263 NSAccessibilitySizeAttribute,
289 264
290 // Title is required for most elements. Cocoa asks for the value even if it 265 // Title is required for most elements. Cocoa asks for the value even if it
291 // is omitted here, but won't present it to accessibility APIs without this. 266 // is omitted here, but won't present it to accessibility APIs without this.
292 NSAccessibilityTitleAttribute, 267 NSAccessibilityTitleAttribute,
268
269 // Attributes which are not required, but are general to all roles.
270 NSAccessibilityRoleDescriptionAttribute,
271 NSAccessibilityValueAttribute,
tapted 2016/06/06 04:09:51 So I poked around a bit - I think doing this for R
Patti Lor 2016/06/10 01:36:10 Have added switch to add Value attributes on a bun
293 ]; 272 ];
294 // TODO(tapted): Add additional attributes based on role. 273 // TODO(tapted): Add additional attributes based on role.
295 } 274 }
296 275
297 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute { 276 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute {
298 return NO; 277 return NO;
299 } 278 }
300 279
301 - (id)accessibilityAttributeValue:(NSString*)attribute { 280 - (id)accessibilityAttributeValue:(NSString*)attribute {
302 SEL selector = NSSelectorFromString(attribute); 281 SEL selector = NSSelectorFromString(attribute);
303 if ([self respondsToSelector:selector]) 282 if ([self respondsToSelector:selector])
304 return [self performSelector:selector]; 283 return [self performSelector:selector];
305 return nil; 284 return nil;
306 } 285 }
307 286
287 // NSAccessibility attributes.
288
289 - (NSArray*)AXChildren {
290 if (!node_)
291 return nil;
292 int count = node_->GetChildCount();
293 NSMutableArray* children = [NSMutableArray arrayWithCapacity:count];
294 for (int i = 0; i < count; ++i)
295 [children addObject:node_->ChildAtIndex(i)];
296 return NSAccessibilityUnignoredChildren(children);
297 }
298
299 - (id)AXParent {
300 if (!node_)
301 return nil;
302 return NSAccessibilityUnignoredAncestor(node_->GetParent());
303 }
304
305 - (NSValue*)AXPosition {
306 return [NSValue valueWithPoint:self.boundsInScreen.origin];
307 }
308
309 - (NSString*)AXRole {
310 if (!node_)
311 return nil;
312 return [[self class] nativeRoleFromAXRole:node_->GetData().role];
313 }
314
315 - (NSValue*)AXSize {
316 return [NSValue valueWithSize:self.boundsInScreen.size];
317 }
318
319 - (NSString*)AXTitle {
320 return [self getStringAttribute:ui::AX_ATTR_NAME];
321 }
322
323 - (NSString*)AXRoleDescription {
324 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION];
tapted 2016/06/06 04:09:51 So if this returns nil, I think we should then try
Patti Lor 2016/06/10 01:36:09 Works with nil values! Done. Have also added the s
tapted 2016/06/10 03:17:17 What string does it return for nil? The API is NS
Patti Lor 2016/06/16 07:05:21 Having a nil role returns an empty NSString, so I'
325 }
326
327 - (NSString*)AXValue {
328 return [self getStringAttribute:ui::AX_ATTR_VALUE];
329 }
330
308 @end 331 @end
309 332
310 namespace ui { 333 namespace ui {
311 334
312 // static 335 // static
313 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { 336 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
314 AXPlatformNodeBase* node = new AXPlatformNodeMac(); 337 AXPlatformNodeBase* node = new AXPlatformNodeMac();
315 node->Init(delegate); 338 node->Init(delegate);
316 return node; 339 return node;
317 } 340 }
(...skipping 19 matching lines...) Expand all
337 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { 360 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) {
338 // TODO(dmazzoni): implement this. http://crbug.com/396137 361 // TODO(dmazzoni): implement this. http://crbug.com/396137
339 } 362 }
340 363
341 int AXPlatformNodeMac::GetIndexInParent() { 364 int AXPlatformNodeMac::GetIndexInParent() {
342 // TODO(dmazzoni): implement this. http://crbug.com/396137 365 // TODO(dmazzoni): implement this. http://crbug.com/396137
343 return -1; 366 return -1;
344 } 367 }
345 368
346 } // namespace ui 369 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/mac/coordinate_conversion.h » ('j') | ui/gfx/mac/coordinate_conversion.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698