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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 | 676 |
677 // | 677 // |
678 // IAccessible2 methods. | 678 // IAccessible2 methods. |
679 // | 679 // |
680 | 680 |
681 STDMETHODIMP BrowserAccessibilityComWin::role(LONG* role) { | 681 STDMETHODIMP BrowserAccessibilityComWin::role(LONG* role) { |
682 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ROLE); | 682 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ROLE); |
683 if (!owner()) | 683 if (!owner()) |
684 return E_FAIL; | 684 return E_FAIL; |
685 | 685 |
686 if (!role) | 686 return AXPlatformNodeWin::role(role); |
687 return E_INVALIDARG; | |
688 | |
689 *role = ia2_role(); | |
690 return S_OK; | |
691 } | 687 } |
692 | 688 |
693 STDMETHODIMP BrowserAccessibilityComWin::get_attributes(BSTR* attributes) { | 689 STDMETHODIMP BrowserAccessibilityComWin::get_attributes(BSTR* attributes) { |
694 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_GET_ATTRIBUTES); | 690 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IA2_GET_ATTRIBUTES); |
695 if (!owner()) | 691 if (!owner()) |
696 return E_FAIL; | 692 return E_FAIL; |
697 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); | 693 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); |
698 if (!attributes) | 694 if (!attributes) |
699 return E_INVALIDARG; | 695 return E_INVALIDARG; |
700 *attributes = nullptr; | 696 *attributes = nullptr; |
(...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 // Private methods. | 3536 // Private methods. |
3541 // | 3537 // |
3542 | 3538 |
3543 void BrowserAccessibilityComWin::UpdateStep1ComputeWinAttributes() { | 3539 void BrowserAccessibilityComWin::UpdateStep1ComputeWinAttributes() { |
3544 // Swap win_attributes_ to old_win_attributes_, allowing us to see | 3540 // Swap win_attributes_ to old_win_attributes_, allowing us to see |
3545 // exactly what changed and fire appropriate events. Note that | 3541 // exactly what changed and fire appropriate events. Note that |
3546 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents. | 3542 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents. |
3547 old_win_attributes_.swap(win_attributes_); | 3543 old_win_attributes_.swap(win_attributes_); |
3548 win_attributes_.reset(new WinAttributes()); | 3544 win_attributes_.reset(new WinAttributes()); |
3549 | 3545 |
3550 InitRoleAndState(); | 3546 win_attributes_->ia_role = MSAARole(); |
| 3547 win_attributes_->ia_state = MSAAState(); |
| 3548 win_attributes_->role_name = base::UTF8ToUTF16(StringOverrideForMSAARole()); |
| 3549 |
| 3550 win_attributes_->ia2_role = IA2Role(); |
| 3551 // If we didn't explicitly set the IAccessible2 role, make it the same |
| 3552 // as the MSAA role. |
| 3553 if (!win_attributes_->ia2_role) |
| 3554 win_attributes_->ia2_role = win_attributes_->ia_role; |
| 3555 |
| 3556 win_attributes_->ia2_state = IA2State(); |
3551 | 3557 |
3552 win_attributes_->ia2_attributes.clear(); | 3558 win_attributes_->ia2_attributes.clear(); |
3553 | 3559 |
3554 // Expose some HTLM and ARIA attributes in the IAccessible2 attributes string. | 3560 // Expose some HTLM and ARIA attributes in the IAccessible2 attributes string. |
3555 // "display", "tag", and "xml-roles" have somewhat unusual names for | 3561 // "display", "tag", and "xml-roles" have somewhat unusual names for |
3556 // historical reasons. Aside from that virtually every ARIA attribute | 3562 // historical reasons. Aside from that virtually every ARIA attribute |
3557 // is exposed in a really straightforward way, i.e. "aria-foo" is exposed | 3563 // is exposed in a really straightforward way, i.e. "aria-foo" is exposed |
3558 // as "foo". | 3564 // as "foo". |
3559 StringAttributeToIA2(ui::AX_ATTR_DISPLAY, "display"); | 3565 StringAttributeToIA2(ui::AX_ATTR_DISPLAY, "display"); |
3560 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG, "tag"); | 3566 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG, "tag"); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3724 | 3730 |
3725 int member_of_id; | 3731 int member_of_id; |
3726 if (owner()->GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id)) | 3732 if (owner()->GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id)) |
3727 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id); | 3733 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id); |
3728 | 3734 |
3729 int error_message_id; | 3735 int error_message_id; |
3730 if (owner()->GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID, &error_message_id)) | 3736 if (owner()->GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID, &error_message_id)) |
3731 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id); | 3737 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id); |
3732 | 3738 |
3733 UpdateRequiredAttributes(); | 3739 UpdateRequiredAttributes(); |
3734 // If this is a web area for a presentational iframe, give it a role of | |
3735 // something other than DOCUMENT so that the fact that it's a separate doc | |
3736 // is not exposed to AT. | |
3737 // TODO(dougt): When we move IA2 Role handling to AXPlatformNodeWin, we can | |
3738 // remove this ia2_role special case. | |
3739 if (owner()->IsWebAreaForPresentationalIframe()) { | |
3740 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING; | |
3741 } | |
3742 } | 3740 } |
3743 | 3741 |
3744 void BrowserAccessibilityComWin::UpdateStep2ComputeHypertext() { | 3742 void BrowserAccessibilityComWin::UpdateStep2ComputeHypertext() { |
3745 if (owner()->IsSimpleTextControl()) { | 3743 if (owner()->IsSimpleTextControl()) { |
3746 win_attributes_->hypertext = value(); | 3744 win_attributes_->hypertext = value(); |
3747 return; | 3745 return; |
3748 } | 3746 } |
3749 | 3747 |
3750 if (!owner()->PlatformChildCount()) { | 3748 if (!owner()->PlatformChildCount()) { |
3751 if (owner()->IsRichTextControl()) { | 3749 if (owner()->IsRichTextControl()) { |
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4908 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type); | 4906 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type); |
4909 } | 4907 } |
4910 } | 4908 } |
4911 | 4909 |
4912 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const { | 4910 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const { |
4913 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange, | 4911 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange, |
4914 ui::AX_EVENT_NONE, win_event_type, owner())) | 4912 ui::AX_EVENT_NONE, win_event_type, owner())) |
4915 ->Fire(); | 4913 ->Fire(); |
4916 } | 4914 } |
4917 | 4915 |
4918 void BrowserAccessibilityComWin::InitRoleAndState() { | |
4919 int32_t ia2_role = 0; | |
4920 | |
4921 base::string16 html_tag = owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG); | |
4922 switch (owner()->GetRole()) { | |
4923 case ui::AX_ROLE_BANNER: | |
4924 ia2_role = IA2_ROLE_HEADER; | |
4925 break; | |
4926 case ui::AX_ROLE_BLOCKQUOTE: | |
4927 ia2_role = IA2_ROLE_SECTION; | |
4928 break; | |
4929 case ui::AX_ROLE_CANVAS: | |
4930 if (owner()->GetBoolAttribute(ui::AX_ATTR_CANVAS_HAS_FALLBACK)) { | |
4931 ia2_role = IA2_ROLE_CANVAS; | |
4932 } | |
4933 break; | |
4934 case ui::AX_ROLE_CAPTION: | |
4935 ia2_role = IA2_ROLE_CAPTION; | |
4936 break; | |
4937 case ui::AX_ROLE_COLOR_WELL: | |
4938 ia2_role = IA2_ROLE_COLOR_CHOOSER; | |
4939 break; | |
4940 case ui::AX_ROLE_COMPLEMENTARY: | |
4941 ia2_role = IA2_ROLE_NOTE; | |
4942 break; | |
4943 case ui::AX_ROLE_CONTENT_INFO: | |
4944 ia2_role = IA2_ROLE_PARAGRAPH; | |
4945 break; | |
4946 case ui::AX_ROLE_DATE: | |
4947 case ui::AX_ROLE_DATE_TIME: | |
4948 ia2_role = IA2_ROLE_DATE_EDITOR; | |
4949 break; | |
4950 case ui::AX_ROLE_DEFINITION: | |
4951 ia2_role = IA2_ROLE_PARAGRAPH; | |
4952 break; | |
4953 case ui::AX_ROLE_DESCRIPTION_LIST_DETAIL: | |
4954 ia2_role = IA2_ROLE_PARAGRAPH; | |
4955 break; | |
4956 case ui::AX_ROLE_EMBEDDED_OBJECT: | |
4957 if (!owner()->PlatformChildCount()) { | |
4958 ia2_role = IA2_ROLE_EMBEDDED_OBJECT; | |
4959 } | |
4960 break; | |
4961 case ui::AX_ROLE_FIGCAPTION: | |
4962 ia2_role = IA2_ROLE_CAPTION; | |
4963 break; | |
4964 case ui::AX_ROLE_FORM: | |
4965 ia2_role = IA2_ROLE_FORM; | |
4966 break; | |
4967 case ui::AX_ROLE_FOOTER: | |
4968 ia2_role = IA2_ROLE_FOOTER; | |
4969 break; | |
4970 case ui::AX_ROLE_GENERIC_CONTAINER: | |
4971 ia2_role = IA2_ROLE_SECTION; | |
4972 break; | |
4973 case ui::AX_ROLE_HEADING: | |
4974 ia2_role = IA2_ROLE_HEADING; | |
4975 break; | |
4976 case ui::AX_ROLE_IFRAME: | |
4977 ia2_role = IA2_ROLE_INTERNAL_FRAME; | |
4978 break; | |
4979 case ui::AX_ROLE_IMAGE_MAP: | |
4980 ia2_role = IA2_ROLE_IMAGE_MAP; | |
4981 break; | |
4982 case ui::AX_ROLE_LABEL_TEXT: | |
4983 case ui::AX_ROLE_LEGEND: | |
4984 ia2_role = IA2_ROLE_LABEL; | |
4985 break; | |
4986 case ui::AX_ROLE_MAIN: | |
4987 ia2_role = IA2_ROLE_PARAGRAPH; | |
4988 break; | |
4989 case ui::AX_ROLE_MARK: | |
4990 ia2_role = IA2_ROLE_TEXT_FRAME; | |
4991 break; | |
4992 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: | |
4993 ia2_role = IA2_ROLE_CHECK_MENU_ITEM; | |
4994 break; | |
4995 case ui::AX_ROLE_MENU_ITEM_RADIO: | |
4996 ia2_role = IA2_ROLE_RADIO_MENU_ITEM; | |
4997 break; | |
4998 case ui::AX_ROLE_NAVIGATION: | |
4999 ia2_role = IA2_ROLE_SECTION; | |
5000 break; | |
5001 case ui::AX_ROLE_NOTE: | |
5002 ia2_role = IA2_ROLE_NOTE; | |
5003 break; | |
5004 case ui::AX_ROLE_PARAGRAPH: | |
5005 ia2_role = IA2_ROLE_PARAGRAPH; | |
5006 break; | |
5007 case ui::AX_ROLE_PRE: | |
5008 ia2_role = IA2_ROLE_PARAGRAPH; | |
5009 break; | |
5010 case ui::AX_ROLE_REGION: | |
5011 if (html_tag == L"section") { | |
5012 ia2_role = IA2_ROLE_SECTION; | |
5013 } | |
5014 break; | |
5015 case ui::AX_ROLE_RUBY: | |
5016 ia2_role = IA2_ROLE_TEXT_FRAME; | |
5017 break; | |
5018 case ui::AX_ROLE_RULER: | |
5019 ia2_role = IA2_ROLE_RULER; | |
5020 break; | |
5021 case ui::AX_ROLE_SCROLL_AREA: | |
5022 ia2_role = IA2_ROLE_SCROLL_PANE; | |
5023 break; | |
5024 case ui::AX_ROLE_SEARCH: | |
5025 ia2_role = IA2_ROLE_SECTION; | |
5026 break; | |
5027 case ui::AX_ROLE_SWITCH: | |
5028 ia2_role = IA2_ROLE_TOGGLE_BUTTON; | |
5029 break; | |
5030 case ui::AX_ROLE_TABLE_HEADER_CONTAINER: | |
5031 ia2_role = IA2_ROLE_SECTION; | |
5032 break; | |
5033 case ui::AX_ROLE_TOGGLE_BUTTON: | |
5034 ia2_role = IA2_ROLE_TOGGLE_BUTTON; | |
5035 break; | |
5036 case ui::AX_ROLE_ABBR: | |
5037 case ui::AX_ROLE_TIME: | |
5038 ia2_role = IA2_ROLE_TEXT_FRAME; | |
5039 break; | |
5040 default: | |
5041 break; | |
5042 } | |
5043 | |
5044 win_attributes_->ia_role = MSAARole(); | |
5045 win_attributes_->ia_state = MSAAState(); | |
5046 win_attributes_->role_name = base::UTF8ToUTF16(StringOverrideForMSAARole()); | |
5047 | |
5048 // If we didn't explicitly set the IAccessible2 role, make it the same | |
5049 // as the MSAA role. | |
5050 if (!ia2_role) | |
5051 ia2_role = win_attributes_->ia_role; | |
5052 | |
5053 win_attributes_->ia2_role = ia2_role; | |
5054 win_attributes_->ia2_state = IA2State(); | |
5055 } | |
5056 | |
5057 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( | 4916 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( |
5058 BrowserAccessibility* obj) { | 4917 BrowserAccessibility* obj) { |
5059 if (!obj || !obj->IsNative()) | 4918 if (!obj || !obj->IsNative()) |
5060 return nullptr; | 4919 return nullptr; |
5061 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); | 4920 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); |
5062 return result; | 4921 return result; |
5063 } | 4922 } |
5064 | 4923 |
5065 } // namespace content | 4924 } // namespace content |
OLD | NEW |