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

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: 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 | 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"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 - (void)detach { 216 - (void)detach {
217 node_ = nil; 217 node_ = nil;
218 } 218 }
219 219
220 - (NSRect)boundsInScreen { 220 - (NSRect)boundsInScreen {
221 if (!node_) 221 if (!node_)
222 return NSZeroRect; 222 return NSZeroRect;
223 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); 223 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen());
224 } 224 }
225 225
226 - (NSArray*)AXChildren {
227 if (!node_)
228 return nil;
229 int count = node_->GetChildCount();
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;
261 }
262
263 // NSAccessibility informal protocol implementation. 226 // NSAccessibility informal protocol implementation.
264 227
265 - (BOOL)accessibilityIsIgnored { 228 - (BOOL)accessibilityIsIgnored {
266 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole]; 229 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole];
267 } 230 }
268 231
269 - (id)accessibilityHitTest:(NSPoint)point { 232 - (id)accessibilityHitTest:(NSPoint)point {
270 for (AXPlatformNodeCocoa* child in [self AXChildren]) { 233 for (AXPlatformNodeCocoa* child in [self AXChildren]) {
271 if (NSPointInRect(point, child.boundsInScreen)) 234 if (NSPointInRect(point, child.boundsInScreen))
272 return [child accessibilityHitTest:point]; 235 return [child accessibilityHitTest:point];
(...skipping 10 matching lines...) Expand all
283 return @[ 246 return @[
284 NSAccessibilityChildrenAttribute, 247 NSAccessibilityChildrenAttribute,
285 NSAccessibilityParentAttribute, 248 NSAccessibilityParentAttribute,
286 NSAccessibilityPositionAttribute, 249 NSAccessibilityPositionAttribute,
287 NSAccessibilityRoleAttribute, 250 NSAccessibilityRoleAttribute,
288 NSAccessibilitySizeAttribute, 251 NSAccessibilitySizeAttribute,
289 252
290 // Title is required for most elements. Cocoa asks for the value even if it 253 // 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. 254 // is omitted here, but won't present it to accessibility APIs without this.
292 NSAccessibilityTitleAttribute, 255 NSAccessibilityTitleAttribute,
256
257 // Attributes which are not required, but are general to all roles.
258 NSAccessibilityRoleDescriptionAttribute,
259 NSAccessibilityValueAttribute,
293 ]; 260 ];
294 // TODO(tapted): Add additional attributes based on role. 261 // TODO(tapted): Add additional attributes based on role.
295 } 262 }
296 263
297 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute { 264 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute {
298 return NO; 265 return NO;
299 } 266 }
300 267
301 - (id)accessibilityAttributeValue:(NSString*)attribute { 268 - (id)accessibilityAttributeValue:(NSString*)attribute {
302 SEL selector = NSSelectorFromString(attribute); 269 SEL selector = NSSelectorFromString(attribute);
303 if ([self respondsToSelector:selector]) 270 if ([self respondsToSelector:selector])
304 return [self performSelector:selector]; 271 return [self performSelector:selector];
305 return nil; 272 return nil;
306 } 273 }
307 274
275 // NSAccessibility attributes.
276
277 // Helper function for string attributes that don't require extra processing.
278 - (NSString*)retrieveAXStringAttribute:(ui::AXStringAttribute)attribute {
tapted 2016/05/30 11:30:21 Since this essentially wraps node_->GetStringAttri
Patti Lor 2016/06/03 04:51:03 Done.
279 std::string attributeValue;
280 if (node_->GetStringAttribute(attribute, &attributeValue))
281 return base::SysUTF8ToNSString(attributeValue);
282 return nil;
283 }
284
285 - (NSArray*)AXChildren {
286 if (!node_)
287 return nil;
288 int count = node_->GetChildCount();
289 NSMutableArray* children = [NSMutableArray arrayWithCapacity:count];
290 for (int i = 0; i < count; ++i)
291 [children addObject:node_->ChildAtIndex(i)];
292 return NSAccessibilityUnignoredChildren(children);
293 }
294
295 - (id)AXParent {
296 if (!node_)
297 return nil;
298 return NSAccessibilityUnignoredAncestor(node_->GetParent());
299 }
300
301 - (NSValue*)AXPosition {
302 return [NSValue valueWithPoint:self.boundsInScreen.origin];
303 }
304
305 - (NSString*)AXRole {
306 if (!node_)
307 return nil;
308 return [[self class] nativeRoleFromAXRole:node_->GetData().role];
309 }
310
311 - (NSValue*)AXSize {
312 return [NSValue valueWithSize:self.boundsInScreen.size];
313 }
314
315 - (NSString*)AXTitle {
316 return [self retrieveAXStringAttribute:ui::AX_ATTR_NAME];
317 }
318
319 - (NSString*)AXRoleDescription {
320 return [self retrieveAXStringAttribute:ui::AX_ATTR_DESCRIPTION];
321 }
322
323 - (NSString*)AXValue {
324 return [self retrieveAXStringAttribute:ui::AX_ATTR_VALUE];
325 }
326
308 @end 327 @end
309 328
310 namespace ui { 329 namespace ui {
311 330
312 // static 331 // static
313 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { 332 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) {
314 AXPlatformNodeBase* node = new AXPlatformNodeMac(); 333 AXPlatformNodeBase* node = new AXPlatformNodeMac();
315 node->Init(delegate); 334 node->Init(delegate);
316 return node; 335 return node;
317 } 336 }
(...skipping 19 matching lines...) Expand all
337 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) { 356 void AXPlatformNodeMac::NotifyAccessibilityEvent(ui::AXEvent event_type) {
338 // TODO(dmazzoni): implement this. http://crbug.com/396137 357 // TODO(dmazzoni): implement this. http://crbug.com/396137
339 } 358 }
340 359
341 int AXPlatformNodeMac::GetIndexInParent() { 360 int AXPlatformNodeMac::GetIndexInParent() {
342 // TODO(dmazzoni): implement this. http://crbug.com/396137 361 // TODO(dmazzoni): implement this. http://crbug.com/396137
343 return -1; 362 return -1;
344 } 363 }
345 364
346 } // namespace ui 365 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698