OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 #include "content/browser/accessibility/browser_accessibility_com_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_com_win.h" |
6 | 6 |
7 #include <UIAutomationClient.h> | 7 #include <UIAutomationClient.h> |
8 #include <UIAutomationCoreApi.h> | 8 #include <UIAutomationCoreApi.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 // * There are some methods that don't touch any state such as get_toolkitName. | 423 // * There are some methods that don't touch any state such as get_toolkitName. |
424 // For these rare cases, you may not need to call owner(). | 424 // For these rare cases, you may not need to call owner(). |
425 // | 425 // |
426 | 426 |
427 HRESULT BrowserAccessibilityComWin::accDoDefaultAction(VARIANT var_id) { | 427 HRESULT BrowserAccessibilityComWin::accDoDefaultAction(VARIANT var_id) { |
428 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION); | 428 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION); |
429 | 429 |
430 if (!owner()) | 430 if (!owner()) |
431 return E_FAIL; | 431 return E_FAIL; |
432 | 432 |
433 auto* manager = Manager(); | 433 return AXPlatformNodeWin::accDoDefaultAction(var_id); |
434 if (!manager) | |
435 return E_FAIL; | |
436 | |
437 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id); | |
438 if (!target) | |
439 return E_INVALIDARG; | |
440 | |
441 // Return an error if it hasn't got a custom action verb to describe what | |
442 // happens on click. | |
443 if (!target->owner()->HasIntAttribute(ui::AX_ATTR_DEFAULT_ACTION_VERB)) | |
444 return DISP_E_MEMBERNOTFOUND; | |
445 | |
446 manager->DoDefaultAction(*target->owner()); | |
447 return S_OK; | |
448 } | 434 } |
449 | 435 |
450 STDMETHODIMP BrowserAccessibilityComWin::accHitTest(LONG x_left, | 436 STDMETHODIMP BrowserAccessibilityComWin::accHitTest(LONG x_left, |
451 LONG y_top, | 437 LONG y_top, |
452 VARIANT* child) { | 438 VARIANT* child) { |
453 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST); | 439 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST); |
454 | 440 |
455 if (!owner()) | 441 if (!owner()) |
456 return E_FAIL; | 442 return E_FAIL; |
457 | 443 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 end->pdispVal = ToBrowserAccessibilityComWin(result)->NewReference(); | 533 end->pdispVal = ToBrowserAccessibilityComWin(result)->NewReference(); |
548 return S_OK; | 534 return S_OK; |
549 } | 535 } |
550 | 536 |
551 STDMETHODIMP BrowserAccessibilityComWin::get_accChild(VARIANT var_child, | 537 STDMETHODIMP BrowserAccessibilityComWin::get_accChild(VARIANT var_child, |
552 IDispatch** disp_child) { | 538 IDispatch** disp_child) { |
553 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD); | 539 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD); |
554 if (!owner()) | 540 if (!owner()) |
555 return E_FAIL; | 541 return E_FAIL; |
556 | 542 |
557 if (!disp_child) | 543 return AXPlatformNodeWin::get_accChild(var_child, disp_child); |
558 return E_INVALIDARG; | |
559 | |
560 *disp_child = NULL; | |
561 | |
562 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_child); | |
563 if (!target) | |
564 return E_INVALIDARG; | |
565 | |
566 (*disp_child) = target->NewReference(); | |
567 return S_OK; | |
568 } | 544 } |
569 | 545 |
570 STDMETHODIMP BrowserAccessibilityComWin::get_accChildCount(LONG* child_count) { | 546 STDMETHODIMP BrowserAccessibilityComWin::get_accChildCount(LONG* child_count) { |
571 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD_COUNT); | 547 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_CHILD_COUNT); |
572 if (!owner()) | 548 if (!owner()) |
573 return E_FAIL; | 549 return E_FAIL; |
574 | 550 |
575 if (!child_count) | 551 return AXPlatformNodeWin::get_accChildCount(child_count); |
576 return E_INVALIDARG; | |
577 | |
578 *child_count = owner()->PlatformChildCount(); | |
579 | |
580 return S_OK; | |
581 } | 552 } |
582 | 553 |
583 STDMETHODIMP BrowserAccessibilityComWin::get_accDefaultAction( | 554 STDMETHODIMP BrowserAccessibilityComWin::get_accDefaultAction( |
584 VARIANT var_id, | 555 VARIANT var_id, |
585 BSTR* def_action) { | 556 BSTR* def_action) { |
586 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DEFAULT_ACTION); | 557 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DEFAULT_ACTION); |
587 if (!owner()) | 558 if (!owner()) |
588 return E_FAIL; | 559 return E_FAIL; |
589 | 560 |
590 if (!def_action) | 561 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); |
591 return E_INVALIDARG; | 562 return AXPlatformNodeWin::get_accDefaultAction(var_id, def_action); |
592 | |
593 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id); | |
594 if (!target) | |
595 return E_INVALIDARG; | |
596 | |
597 return target->get_localizedName(0, def_action); | |
598 } | 563 } |
599 | 564 |
600 STDMETHODIMP BrowserAccessibilityComWin::get_accDescription(VARIANT var_id, | 565 STDMETHODIMP BrowserAccessibilityComWin::get_accDescription(VARIANT var_id, |
601 BSTR* desc) { | 566 BSTR* desc) { |
602 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION); | 567 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION); |
603 if (!owner()) | 568 if (!owner()) |
604 return E_FAIL; | 569 return E_FAIL; |
605 | 570 |
606 if (!desc) | 571 return AXPlatformNodeWin::get_accDescription(var_id, desc); |
607 return E_INVALIDARG; | |
608 | |
609 BrowserAccessibilityComWin* target = GetTargetFromChildID(var_id); | |
610 if (!target) | |
611 return E_INVALIDARG; | |
612 | |
613 base::string16 description_str = target->description(); | |
614 if (description_str.empty()) | |
615 return S_FALSE; | |
616 | |
617 *desc = SysAllocString(description_str.c_str()); | |
618 | |
619 DCHECK(*desc); | |
620 return S_OK; | |
621 } | 572 } |
622 | 573 |
623 STDMETHODIMP BrowserAccessibilityComWin::get_accFocus(VARIANT* focus_child) { | 574 STDMETHODIMP BrowserAccessibilityComWin::get_accFocus(VARIANT* focus_child) { |
624 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_FOCUS); | 575 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_FOCUS); |
625 if (!owner()) | 576 if (!owner()) |
626 return E_FAIL; | 577 return E_FAIL; |
627 | 578 |
628 auto* manager = Manager(); | 579 return AXPlatformNodeWin::get_accFocus(focus_child); |
629 if (!manager) | |
630 return E_FAIL; | |
631 | |
632 if (!focus_child) | |
633 return E_INVALIDARG; | |
634 | |
635 BrowserAccessibilityWin* focus = | |
636 static_cast<BrowserAccessibilityWin*>(manager->GetFocus()); | |
637 if (focus == owner()) { | |
638 focus_child->vt = VT_I4; | |
639 focus_child->lVal = CHILDID_SELF; | |
640 } else if (focus == NULL) { | |
641 focus_child->vt = VT_EMPTY; | |
642 } else { | |
643 focus_child->vt = VT_DISPATCH; | |
644 focus_child->pdispVal = focus->GetCOM()->NewReference(); | |
645 } | |
646 | |
647 return S_OK; | |
648 } | 580 } |
649 | 581 |
650 STDMETHODIMP BrowserAccessibilityComWin::get_accHelp(VARIANT var_id, | 582 STDMETHODIMP BrowserAccessibilityComWin::get_accHelp(VARIANT var_id, |
651 BSTR* help) { | 583 BSTR* help) { |
652 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP); | 584 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_HELP); |
653 if (!owner()) | 585 if (!owner()) |
654 return E_FAIL; | 586 return E_FAIL; |
655 | 587 |
656 return AXPlatformNodeWin::get_accHelp(var_id, help); | 588 return AXPlatformNodeWin::get_accHelp(var_id, help); |
657 } | 589 } |
(...skipping 27 matching lines...) Expand all Loading... |
685 | 617 |
686 return AXPlatformNodeWin::get_accName(var_id, name); | 618 return AXPlatformNodeWin::get_accName(var_id, name); |
687 } | 619 } |
688 | 620 |
689 STDMETHODIMP BrowserAccessibilityComWin::get_accParent( | 621 STDMETHODIMP BrowserAccessibilityComWin::get_accParent( |
690 IDispatch** disp_parent) { | 622 IDispatch** disp_parent) { |
691 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_PARENT); | 623 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_PARENT); |
692 if (!owner()) | 624 if (!owner()) |
693 return E_FAIL; | 625 return E_FAIL; |
694 | 626 |
695 if (!disp_parent) | 627 return AXPlatformNodeWin::get_accParent(disp_parent); |
696 return E_INVALIDARG; | |
697 | |
698 IAccessible* parent_obj = | |
699 ToBrowserAccessibilityComWin(owner()->PlatformGetParent()); | |
700 if (parent_obj == NULL) { | |
701 // This happens if we're the root of the tree; | |
702 // return the IAccessible for the window. | |
703 parent_obj = | |
704 Manager()->ToBrowserAccessibilityManagerWin()->GetParentIAccessible(); | |
705 // |parent| can only be NULL if the manager was created before the parent | |
706 // IAccessible was known and it wasn't subsequently set before a client | |
707 // requested it. This has been fixed. |parent| may also be NULL during | |
708 // destruction. Possible cases where this could occur include tabs being | |
709 // dragged to a new window, etc. | |
710 if (!parent_obj) { | |
711 DVLOG(1) << "In Function: " << __func__ | |
712 << ". Parent IAccessible interface is NULL. Returning failure"; | |
713 return E_FAIL; | |
714 } | |
715 } | |
716 parent_obj->AddRef(); | |
717 *disp_parent = parent_obj; | |
718 return S_OK; | |
719 } | 628 } |
720 | 629 |
721 STDMETHODIMP BrowserAccessibilityComWin::get_accRole(VARIANT var_id, | 630 STDMETHODIMP BrowserAccessibilityComWin::get_accRole(VARIANT var_id, |
722 VARIANT* role) { | 631 VARIANT* role) { |
723 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_ROLE); | 632 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_ROLE); |
724 if (!owner()) | 633 if (!owner()) |
725 return E_FAIL; | 634 return E_FAIL; |
726 | 635 |
727 if (!role) | 636 if (!role) |
728 return E_INVALIDARG; | 637 return E_INVALIDARG; |
(...skipping 4994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5723 | 5632 |
5724 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( | 5633 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( |
5725 BrowserAccessibility* obj) { | 5634 BrowserAccessibility* obj) { |
5726 if (!obj || !obj->IsNative()) | 5635 if (!obj || !obj->IsNative()) |
5727 return nullptr; | 5636 return nullptr; |
5728 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); | 5637 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); |
5729 return result; | 5638 return result; |
5730 } | 5639 } |
5731 | 5640 |
5732 } // namespace content | 5641 } // namespace content |
OLD | NEW |