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" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
12 #include "ui/accessibility/ax_action_data.h" | 13 #include "ui/accessibility/ax_action_data.h" |
13 #include "ui/accessibility/ax_node_data.h" | 14 #include "ui/accessibility/ax_node_data.h" |
| 15 #include "ui/accessibility/ax_node_position.h" |
| 16 #include "ui/accessibility/ax_range.h" |
14 #include "ui/accessibility/ax_role_properties.h" | 17 #include "ui/accessibility/ax_role_properties.h" |
15 #include "ui/accessibility/platform/ax_platform_node.h" | 18 #include "ui/accessibility/platform/ax_platform_node.h" |
16 #include "ui/accessibility/platform/ax_platform_node_delegate.h" | 19 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
| 20 #import "ui/accessibility/platform/text_marker_helper_mac.h" |
17 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
18 #import "ui/gfx/mac/coordinate_conversion.h" | 22 #import "ui/gfx/mac/coordinate_conversion.h" |
19 #include "ui/strings/grit/ui_strings.h" | 23 #include "ui/strings/grit/ui_strings.h" |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 struct RoleMapEntry { | 27 struct RoleMapEntry { |
24 ui::AXRole value; | 28 ui::AXRole value; |
25 NSString* nativeValue; | 29 NSString* nativeValue; |
26 }; | 30 }; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // TODO(patricialor): Add more events. | 218 // TODO(patricialor): Add more events. |
215 }; | 219 }; |
216 | 220 |
217 EventMap event_map; | 221 EventMap event_map; |
218 for (size_t i = 0; i < arraysize(events); ++i) | 222 for (size_t i = 0; i < arraysize(events); ++i) |
219 event_map[events[i].value] = events[i].nativeValue; | 223 event_map[events[i].value] = events[i].nativeValue; |
220 return event_map; | 224 return event_map; |
221 } | 225 } |
222 | 226 |
223 void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { | 227 void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| 228 NSLog(@"Notify: %@, %@", target, |
| 229 [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); |
224 NSAccessibilityPostNotification( | 230 NSAccessibilityPostNotification( |
225 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); | 231 target, [AXPlatformNodeCocoa nativeNotificationFromAXEvent:event_type]); |
226 } | 232 } |
227 | 233 |
228 } // namespace | 234 } // namespace |
229 | 235 |
| 236 namespace ui { |
| 237 namespace { |
| 238 |
| 239 using AXNodePositionInstance = AXNodePosition::AXPositionInstance; |
| 240 using AXNodeRange = AXRange<AXNodePositionInstance::element_type>; |
| 241 |
| 242 class NodePositionFactory : public ui::PositionFactory { |
| 243 public: |
| 244 explicit NodePositionFactory(AXPlatformNodeCocoa* node) : node_(node) {} |
| 245 |
| 246 ui::AXPositionPointer GetRoot() const override; |
| 247 ui::AXRangePointer GetSelection() const override; |
| 248 ui::AXPositionPointer GetFromData( |
| 249 const ui::AXPositionData& data) const override; |
| 250 id GetAccessibilityObject(const ui::AXPositionData& data) const override; |
| 251 |
| 252 private: |
| 253 AXPlatformNodeCocoa* node_; // Weak. Transitively owns |this|. |
| 254 |
| 255 DISALLOW_COPY_AND_ASSIGN(NodePositionFactory); |
| 256 }; |
| 257 |
| 258 AXNodeRange CreateRangeFromTextMarkerRange(id marker_range) { |
| 259 ui::AXPositionData start, end; |
| 260 if (![TextMarkerHelperMac getRangeDataFromMarkerRange:marker_range |
| 261 start:&start |
| 262 end:&end]) { |
| 263 return AXNodeRange(); |
| 264 } |
| 265 |
| 266 return AXNodeRange(AXNodePosition::CreateFromData(start), |
| 267 AXNodePosition::CreateFromData(end)); |
| 268 } |
| 269 |
| 270 NSString* GetTextForTextMarkerRange(id marker_range) { |
| 271 AXNodeRange range = CreateRangeFromTextMarkerRange(marker_range); |
| 272 if (range.IsNull()) |
| 273 return nil; |
| 274 return base::SysUTF16ToNSString(range.GetText()); |
| 275 } |
| 276 |
| 277 } // namespace |
| 278 } // namespace ui |
| 279 |
230 @interface AXPlatformNodeCocoa () | 280 @interface AXPlatformNodeCocoa () |
231 // Helper function for string attributes that don't require extra processing. | 281 // Helper function for string attributes that don't require extra processing. |
232 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; | 282 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; |
233 // Returns AXValue, or nil if AXValue isn't an NSString. | 283 // Returns AXValue, or nil if AXValue isn't an NSString. |
234 - (NSString*)getAXValueAsString; | 284 - (NSString*)getAXValueAsString; |
| 285 // Lazily creates a TextMarkerHelper and returns it. |
| 286 - (TextMarkerHelperMac*)textMarkerHelper; |
235 @end | 287 @end |
236 | 288 |
237 @implementation AXPlatformNodeCocoa { | 289 @implementation AXPlatformNodeCocoa { |
238 ui::AXPlatformNodeBase* node_; // Weak. Retains us. | 290 ui::AXPlatformNodeBase* node_; // Weak. Retains us. |
| 291 base::scoped_nsobject<TextMarkerHelperMac> textMarkerHelper_; |
239 } | 292 } |
240 | 293 |
241 @synthesize node = node_; | 294 @synthesize node = node_; |
242 | 295 |
243 // A mapping of AX roles to native roles. | 296 // A mapping of AX roles to native roles. |
244 + (NSString*)nativeRoleFromAXRole:(ui::AXRole)role { | 297 + (NSString*)nativeRoleFromAXRole:(ui::AXRole)role { |
245 CR_DEFINE_STATIC_LOCAL(RoleMap, role_map, (BuildRoleMap())); | 298 CR_DEFINE_STATIC_LOCAL(RoleMap, role_map, (BuildRoleMap())); |
246 RoleMap::iterator it = role_map.find(role); | 299 RoleMap::iterator it = role_map.find(role); |
247 return it != role_map.end() ? it->second : NSAccessibilityUnknownRole; | 300 return it != role_map.end() ? it->second : NSAccessibilityUnknownRole; |
248 } | 301 } |
(...skipping 18 matching lines...) Expand all Loading... |
267 } | 320 } |
268 return self; | 321 return self; |
269 } | 322 } |
270 | 323 |
271 - (void)detach { | 324 - (void)detach { |
272 if (!node_) | 325 if (!node_) |
273 return; | 326 return; |
274 NSAccessibilityPostNotification( | 327 NSAccessibilityPostNotification( |
275 self, NSAccessibilityUIElementDestroyedNotification); | 328 self, NSAccessibilityUIElementDestroyedNotification); |
276 node_ = nil; | 329 node_ = nil; |
| 330 |
| 331 // Nothing retains |textMarkerHelper_|, so this should always dealloc. |
| 332 textMarkerHelper_.reset(); |
277 } | 333 } |
278 | 334 |
279 - (NSRect)boundsInScreen { | 335 - (NSRect)boundsInScreen { |
280 if (!node_) | 336 if (!node_) |
281 return NSZeroRect; | 337 return NSZeroRect; |
282 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); | 338 return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); |
283 } | 339 } |
284 | 340 |
285 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { | 341 - (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { |
286 std::string attributeValue; | 342 std::string attributeValue; |
287 if (node_->GetStringAttribute(attribute, &attributeValue)) | 343 if (node_->GetStringAttribute(attribute, &attributeValue)) |
288 return base::SysUTF8ToNSString(attributeValue); | 344 return base::SysUTF8ToNSString(attributeValue); |
289 return nil; | 345 return nil; |
290 } | 346 } |
291 | 347 |
292 - (NSString*)getAXValueAsString { | 348 - (NSString*)getAXValueAsString { |
293 id value = [self AXValue]; | 349 id value = [self AXValue]; |
294 return [value isKindOfClass:[NSString class]] ? value : nil; | 350 return [value isKindOfClass:[NSString class]] ? value : nil; |
295 } | 351 } |
296 | 352 |
| 353 - (TextMarkerHelperMac*)textMarkerHelper { |
| 354 if (!textMarkerHelper_ && node_) { |
| 355 DLOG(INFO) << "bail"; |
| 356 return nil; |
| 357 textMarkerHelper_.reset([[TextMarkerHelperMac alloc] |
| 358 initWithFactory:base::MakeUnique<ui::NodePositionFactory>(self)]); |
| 359 } |
| 360 return textMarkerHelper_; |
| 361 } |
| 362 |
297 // NSAccessibility informal protocol implementation. | 363 // NSAccessibility informal protocol implementation. |
298 | 364 |
299 - (BOOL)accessibilityIsIgnored { | 365 - (BOOL)accessibilityIsIgnored { |
300 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole] || | 366 return [[self AXRole] isEqualToString:NSAccessibilityUnknownRole] || |
301 node_->GetData().HasState(ui::AX_STATE_INVISIBLE); | 367 node_->GetData().HasState(ui::AX_STATE_INVISIBLE); |
302 } | 368 } |
303 | 369 |
304 - (id)accessibilityHitTest:(NSPoint)point { | 370 - (id)accessibilityHitTest:(NSPoint)point { |
305 for (AXPlatformNodeCocoa* child in [self AXChildren]) { | 371 for (AXPlatformNodeCocoa* child in [self AXChildren]) { |
306 if (![child accessibilityIsIgnored] && | 372 if (![child accessibilityIsIgnored] && |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 [[NSMutableArray alloc] init]); | 452 [[NSMutableArray alloc] init]); |
387 | 453 |
388 [axAttributes addObjectsFromArray:kAllRoleAttributes]; | 454 [axAttributes addObjectsFromArray:kAllRoleAttributes]; |
389 | 455 |
390 switch (node_->GetData().role) { | 456 switch (node_->GetData().role) { |
391 case ui::AX_ROLE_TEXT_FIELD: | 457 case ui::AX_ROLE_TEXT_FIELD: |
392 case ui::AX_ROLE_STATIC_TEXT: | 458 case ui::AX_ROLE_STATIC_TEXT: |
393 [axAttributes addObject:kTextAttributes]; | 459 [axAttributes addObject:kTextAttributes]; |
394 if (!node_->GetData().HasState(ui::AX_STATE_PROTECTED)) | 460 if (!node_->GetData().HasState(ui::AX_STATE_PROTECTED)) |
395 [axAttributes addObjectsFromArray:kUnprotectedTextAttributes]; | 461 [axAttributes addObjectsFromArray:kUnprotectedTextAttributes]; |
| 462 [axAttributes |
| 463 addObjectsFromArray:[TextMarkerHelperMac getSupportedAttributes]]; |
396 // Fallthrough. | 464 // Fallthrough. |
397 case ui::AX_ROLE_CHECK_BOX: | 465 case ui::AX_ROLE_CHECK_BOX: |
398 case ui::AX_ROLE_COMBO_BOX: | 466 case ui::AX_ROLE_COMBO_BOX: |
399 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: | 467 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: |
400 case ui::AX_ROLE_MENU_ITEM_RADIO: | 468 case ui::AX_ROLE_MENU_ITEM_RADIO: |
401 case ui::AX_ROLE_RADIO_BUTTON: | 469 case ui::AX_ROLE_RADIO_BUTTON: |
402 case ui::AX_ROLE_SEARCH_BOX: | 470 case ui::AX_ROLE_SEARCH_BOX: |
403 case ui::AX_ROLE_SLIDER: | 471 case ui::AX_ROLE_SLIDER: |
404 case ui::AX_ROLE_SLIDER_THUMB: | 472 case ui::AX_ROLE_SLIDER_THUMB: |
405 case ui::AX_ROLE_TOGGLE_BUTTON: | 473 case ui::AX_ROLE_TOGGLE_BUTTON: |
406 [axAttributes addObjectsFromArray:kValueAttributes]; | 474 [axAttributes addObjectsFromArray:kValueAttributes]; |
407 break; | 475 break; |
408 // TODO(tapted): Add additional attributes based on role. | 476 // TODO(tapted): Add additional attributes based on role. |
409 default: | 477 default: |
410 break; | 478 break; |
411 } | 479 } |
| 480 if (node_->GetData().role == ui::AX_ROLE_TEXT_FIELD) { |
| 481 NSLog(@"%@ reports %@", [self AXValue], axAttributes.get()); |
| 482 } |
412 return axAttributes.autorelease(); | 483 return axAttributes.autorelease(); |
413 } | 484 } |
414 | 485 |
| 486 - (NSArray*)accessibilityParameterizedAttributeNames { |
| 487 static NSArray* const kEditableTextAttributes = [@[ |
| 488 NSAccessibilityLineForIndexParameterizedAttribute, |
| 489 NSAccessibilityRangeForLineParameterizedAttribute, |
| 490 NSAccessibilityStringForRangeParameterizedAttribute, |
| 491 NSAccessibilityRangeForPositionParameterizedAttribute, |
| 492 NSAccessibilityRangeForIndexParameterizedAttribute, |
| 493 NSAccessibilityBoundsForRangeParameterizedAttribute, |
| 494 NSAccessibilityRTFForRangeParameterizedAttribute, |
| 495 NSAccessibilityAttributedStringForRangeParameterizedAttribute, |
| 496 NSAccessibilityStyleRangeForIndexParameterizedAttribute, |
| 497 ] retain]; |
| 498 |
| 499 base::scoped_nsobject<NSMutableArray> axAttributes( |
| 500 [[NSMutableArray alloc] init]); |
| 501 [axAttributes addObjectsFromArray:kEditableTextAttributes]; |
| 502 [axAttributes |
| 503 addObjectsFromArray:[TextMarkerHelperMac |
| 504 getSupportedParameterizedAttributesExtended:YES]]; |
| 505 NSLog(@"PARAM!: %@ reports %@", [self AXValue], axAttributes.get()); |
| 506 return axAttributes.autorelease(); |
| 507 } |
| 508 |
415 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName { | 509 - (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName { |
416 if (node_->GetData().HasState(ui::AX_STATE_DISABLED)) | 510 if (node_->GetData().HasState(ui::AX_STATE_DISABLED)) |
417 return NO; | 511 return NO; |
418 | 512 |
419 // Allow certain attributes to be written via an accessibility client. A | 513 // Allow certain attributes to be written via an accessibility client. A |
420 // writable attribute will only appear as such if the accessibility element | 514 // writable attribute will only appear as such if the accessibility element |
421 // has a value set for that attribute. | 515 // has a value set for that attribute. |
422 if ([attributeName | 516 if ([attributeName |
423 isEqualToString:NSAccessibilitySelectedChildrenAttribute] || | 517 isEqualToString:NSAccessibilitySelectedChildrenAttribute] || |
424 [attributeName | 518 [attributeName |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 576 |
483 if (data.action != ui::AX_ACTION_NONE) | 577 if (data.action != ui::AX_ACTION_NONE) |
484 node_->GetDelegate()->AccessibilityPerformAction(data); | 578 node_->GetDelegate()->AccessibilityPerformAction(data); |
485 | 579 |
486 // TODO(patricialor): Plumb through all the other writable attributes as | 580 // TODO(patricialor): Plumb through all the other writable attributes as |
487 // specified in accessibilityIsAttributeSettable. | 581 // specified in accessibilityIsAttributeSettable. |
488 } | 582 } |
489 | 583 |
490 - (id)accessibilityAttributeValue:(NSString*)attribute { | 584 - (id)accessibilityAttributeValue:(NSString*)attribute { |
491 SEL selector = NSSelectorFromString(attribute); | 585 SEL selector = NSSelectorFromString(attribute); |
492 if ([self respondsToSelector:selector]) | 586 if ([TextMarkerHelperMac instancesRespondToSelector:selector]) { |
493 return [self performSelector:selector]; | 587 DCHECK(![self respondsToSelector:selector]); |
| 588 NSLog(@"supported: %@", attribute); |
| 589 return [[self textMarkerHelper] performSelector:selector]; |
| 590 } |
| 591 if ([self respondsToSelector:selector]) { |
| 592 id result = [self performSelector:selector]; |
| 593 if (![attribute isEqualToString:@"AXRole"]) { |
| 594 NSLog(@"Trying: %@ (%@) -> %@", attribute, [self AXValue], result); |
| 595 } |
| 596 return result; |
| 597 } |
| 598 NSLog(@"UNsupported: %@", attribute); |
494 return nil; | 599 return nil; |
495 } | 600 } |
496 | 601 |
| 602 - (id)accessibilityAttributeValue:(NSString*)attribute |
| 603 forParameter:(id)parameter { |
| 604 SEL selector = NSSelectorFromString([attribute stringByAppendingString:@":"]); |
| 605 DCHECK(selector); |
| 606 NSLog(@"Trying: %@ for %@", attribute, parameter); |
| 607 if ([TextMarkerHelperMac instancesRespondToSelector:selector]) { |
| 608 DCHECK(![self respondsToSelector:selector]); |
| 609 return |
| 610 [[self textMarkerHelper] performSelector:selector withObject:parameter]; |
| 611 } |
| 612 |
| 613 if ([self respondsToSelector:selector]) |
| 614 return [self performSelector:selector withObject:parameter]; |
| 615 |
| 616 // TODO(tapted): Move these to TextMarkerHelper. |
| 617 if ([attribute isEqualToString:@"AXStringForTextMarkerRange"]) |
| 618 return ui::GetTextForTextMarkerRange(parameter); |
| 619 |
| 620 if ([attribute isEqualToString:@"AXAttributedStringForTextMarkerRange"]) { |
| 621 if (NSString* str = ui::GetTextForTextMarkerRange(parameter)) { |
| 622 base::scoped_nsobject<NSAttributedString> attrString( |
| 623 [[NSAttributedString alloc] initWithString:str]); |
| 624 return attrString.autorelease(); |
| 625 } |
| 626 } |
| 627 |
| 628 if ([attribute isEqualToString:@"AXLengthForTextMarkerRange"]) { |
| 629 NSString* text = ui::GetTextForTextMarkerRange(parameter); |
| 630 return [NSNumber numberWithInt:[text length]]; |
| 631 } |
| 632 NSLog(@"Usupported: %@ for %@", attribute, parameter); |
| 633 return nil; |
| 634 } |
| 635 |
497 // NSAccessibility attributes. Order them according to | 636 // NSAccessibility attributes. Order them according to |
498 // NSAccessibilityConstants.h, or see https://crbug.com/678898. | 637 // NSAccessibilityConstants.h, or see https://crbug.com/678898. |
499 | 638 |
500 - (NSString*)AXRole { | 639 - (NSString*)AXRole { |
501 if (!node_) | 640 if (!node_) |
502 return nil; | 641 return nil; |
503 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; | 642 return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
504 } | 643 } |
505 | 644 |
506 - (NSString*)AXRoleDescription { | 645 - (NSString*)AXRoleDescription { |
(...skipping 19 matching lines...) Expand all Loading... |
526 default: | 665 default: |
527 break; | 666 break; |
528 } | 667 } |
529 return [AXPlatformNodeCocoa nativeSubroleFromAXRole:role]; | 668 return [AXPlatformNodeCocoa nativeSubroleFromAXRole:role]; |
530 } | 669 } |
531 | 670 |
532 - (NSString*)AXHelp { | 671 - (NSString*)AXHelp { |
533 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; | 672 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; |
534 } | 673 } |
535 | 674 |
| 675 - (NSString*)AXDescription { |
| 676 return [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; |
| 677 } |
| 678 |
536 - (id)AXValue { | 679 - (id)AXValue { |
537 switch (node_->GetData().role) { | 680 switch (node_->GetData().role) { |
538 case ui::AX_ROLE_TAB: | 681 case ui::AX_ROLE_TAB: |
539 return [self AXSelected]; | 682 return [self AXSelected]; |
540 case ui::AX_ROLE_STATIC_TEXT: | 683 case ui::AX_ROLE_STATIC_TEXT: |
541 return [self AXTitle]; | 684 return [self AXTitle]; |
542 default: | 685 default: |
543 break; | 686 break; |
544 } | 687 } |
545 return [self getStringAttribute:ui::AX_ATTR_VALUE]; | 688 return [self getStringAttribute:ui::AX_ATTR_VALUE]; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 - (NSValue*)AXSelectedTextRange { | 756 - (NSValue*)AXSelectedTextRange { |
614 // Selection might not be supported. Return (NSRange){0,0} in that case. | 757 // Selection might not be supported. Return (NSRange){0,0} in that case. |
615 int start = 0, end = 0; | 758 int start = 0, end = 0; |
616 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); | 759 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start); |
617 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); | 760 node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_END, &end); |
618 | 761 |
619 // NSRange cannot represent the direction the text was selected in. | 762 // NSRange cannot represent the direction the text was selected in. |
620 return [NSValue valueWithRange:{std::min(start, end), abs(end - start)}]; | 763 return [NSValue valueWithRange:{std::min(start, end), abs(end - start)}]; |
621 } | 764 } |
622 | 765 |
| 766 - (NSArray*)AXSelectedTextRanges { |
| 767 return @[ [self AXSelectedTextRange] ]; |
| 768 } |
| 769 |
623 - (NSNumber*)AXNumberOfCharacters { | 770 - (NSNumber*)AXNumberOfCharacters { |
624 return @([[self getAXValueAsString] length]); | 771 return @([[self getAXValueAsString] length]); |
625 } | 772 } |
626 | 773 |
627 - (NSValue*)AXVisibleCharacterRange { | 774 - (NSValue*)AXVisibleCharacterRange { |
628 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; | 775 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; |
629 } | 776 } |
630 | 777 |
631 - (NSNumber*)AXInsertionPointLineNumber { | 778 - (NSNumber*)AXInsertionPointLineNumber { |
632 // Multiline is not supported on views. | 779 // Multiline is not supported on views. |
633 return @0; | 780 return @0; |
634 } | 781 } |
635 | 782 |
| 783 - (id)AXStringForRange:(id)parameter { |
| 784 DCHECK([parameter isKindOfClass:[NSValue class]]); |
| 785 return [[self getAXValueAsString] substringWithRange:[parameter rangeValue]]; |
| 786 } |
| 787 |
| 788 - (id)AXAttributedStringForRange:(id)parameter { |
| 789 base::scoped_nsobject<NSAttributedString> attributedString( |
| 790 [[NSAttributedString alloc] |
| 791 initWithString:[self AXStringForRange:parameter]]); |
| 792 return attributedString.autorelease(); |
| 793 } |
| 794 |
| 795 - (id)AXRangeForLine:(id)parameter { |
| 796 DCHECK([parameter isKindOfClass:[NSNumber class]]); |
| 797 DCHECK_EQ(0, [parameter intValue]); |
| 798 id r = [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; |
| 799 NSLog(@"-> %@", r); |
| 800 return r; |
| 801 } |
| 802 |
| 803 - (id)AXLineForIndex:(id)parameter { |
| 804 DCHECK([parameter isKindOfClass:[NSNumber class]]); |
| 805 return @0; |
| 806 } |
| 807 |
| 808 - (id)AXOwns { |
| 809 return @[]; |
| 810 } |
| 811 |
| 812 - (id)AXSharedTextUIElements { |
| 813 return @[ self ]; |
| 814 } |
| 815 |
| 816 - (id)AXSharedCharacterRange { |
| 817 return [NSValue valueWithRange:{0, [[self getAXValueAsString] length]}]; |
| 818 } |
| 819 |
636 @end | 820 @end |
637 | 821 |
638 namespace ui { | 822 namespace ui { |
639 | 823 |
640 // static | 824 // static |
641 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { | 825 AXPlatformNode* AXPlatformNode::Create(AXPlatformNodeDelegate* delegate) { |
642 AXPlatformNodeBase* node = new AXPlatformNodeMac(); | 826 AXPlatformNodeBase* node = new AXPlatformNodeMac(); |
643 node->Init(delegate); | 827 node->Init(delegate); |
644 return node; | 828 return node; |
645 } | 829 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 break; | 870 break; |
687 } | 871 } |
688 NotifyMacEvent(native_node_, event_type); | 872 NotifyMacEvent(native_node_, event_type); |
689 } | 873 } |
690 | 874 |
691 int AXPlatformNodeMac::GetIndexInParent() { | 875 int AXPlatformNodeMac::GetIndexInParent() { |
692 // TODO(dmazzoni): implement this. http://crbug.com/396137 | 876 // TODO(dmazzoni): implement this. http://crbug.com/396137 |
693 return -1; | 877 return -1; |
694 } | 878 } |
695 | 879 |
| 880 AXPositionPointer NodePositionFactory::GetRoot() const { |
| 881 if (![node_ node]) |
| 882 return nullptr; |
| 883 |
| 884 return AXNodePosition::CreateTextPosition(1, [node_ node]->unique_id(), 0, |
| 885 AX_TEXT_AFFINITY_DOWNSTREAM); |
| 886 } |
| 887 |
| 888 AXRangePointer NodePositionFactory::GetSelection() const { |
| 889 return AXRangePointer(nullptr, nullptr); |
| 890 } |
| 891 |
| 892 AXPositionPointer NodePositionFactory::GetFromData( |
| 893 const AXPositionData& data) const { |
| 894 return AXNodePosition::CreateFromData(data); |
| 895 } |
| 896 |
| 897 id NodePositionFactory::GetAccessibilityObject( |
| 898 const AXPositionData& data) const { |
| 899 return node_; |
| 900 } |
| 901 |
696 } // namespace ui | 902 } // namespace ui |
OLD | NEW |