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

Side by Side Diff: content/browser/accessibility/browser_accessibility_com_win.cc

Issue 2965873002: Move IA2 Role handling to AXPlatformNodeWin. (Closed)
Patch Set: handle presentation elements in axplatformnodewin. Also delete InitRoleAndState method Created 3 years, 5 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
OLDNEW
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
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 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after
3541 // Private methods. 3537 // Private methods.
3542 // 3538 //
3543 3539
3544 void BrowserAccessibilityComWin::UpdateStep1ComputeWinAttributes() { 3540 void BrowserAccessibilityComWin::UpdateStep1ComputeWinAttributes() {
3545 // Swap win_attributes_ to old_win_attributes_, allowing us to see 3541 // Swap win_attributes_ to old_win_attributes_, allowing us to see
3546 // exactly what changed and fire appropriate events. Note that 3542 // exactly what changed and fire appropriate events. Note that
3547 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents. 3543 // old_win_attributes_ is cleared at the end of UpdateStep3FireEvents.
3548 old_win_attributes_.swap(win_attributes_); 3544 old_win_attributes_.swap(win_attributes_);
3549 win_attributes_.reset(new WinAttributes()); 3545 win_attributes_.reset(new WinAttributes());
3550 3546
3551 InitRoleAndState(); 3547 win_attributes_->ia_role = MSAARole();
dmazzoni 2017/07/06 22:58:05 Nice!!!
3548 win_attributes_->ia_state = MSAAState();
3549 win_attributes_->role_name = base::UTF8ToUTF16(StringOverrideForMSAARole());
3550
3551 win_attributes_->ia2_role = MSAA_IA2Role();
3552 // If we didn't explicitly set the IAccessible2 role, make it the same
3553 // as the MSAA role.
3554 if (!win_attributes_->ia2_role)
3555 win_attributes_->ia2_role = win_attributes_->ia_role;
3556
3557 win_attributes_->ia2_state = MSAA_IA2State();
3552 3558
3553 win_attributes_->ia2_attributes.clear(); 3559 win_attributes_->ia2_attributes.clear();
3554 3560
3555 // Expose some HTLM and ARIA attributes in the IAccessible2 attributes string. 3561 // Expose some HTLM and ARIA attributes in the IAccessible2 attributes string.
3556 // "display", "tag", and "xml-roles" have somewhat unusual names for 3562 // "display", "tag", and "xml-roles" have somewhat unusual names for
3557 // historical reasons. Aside from that virtually every ARIA attribute 3563 // historical reasons. Aside from that virtually every ARIA attribute
3558 // is exposed in a really straightforward way, i.e. "aria-foo" is exposed 3564 // is exposed in a really straightforward way, i.e. "aria-foo" is exposed
3559 // as "foo". 3565 // as "foo".
3560 StringAttributeToIA2(ui::AX_ATTR_DISPLAY, "display"); 3566 StringAttributeToIA2(ui::AX_ATTR_DISPLAY, "display");
3561 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG, "tag"); 3567 StringAttributeToIA2(ui::AX_ATTR_HTML_TAG, "tag");
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 3732
3727 int member_of_id; 3733 int member_of_id;
3728 if (owner()->GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id)) 3734 if (owner()->GetIntAttribute(ui::AX_ATTR_MEMBER_OF_ID, &member_of_id))
3729 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id); 3735 AddRelation(IA2_RELATION_MEMBER_OF, member_of_id);
3730 3736
3731 int error_message_id; 3737 int error_message_id;
3732 if (owner()->GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID, &error_message_id)) 3738 if (owner()->GetIntAttribute(ui::AX_ATTR_ERRORMESSAGE_ID, &error_message_id))
3733 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id); 3739 AddRelation(IA2_RELATION_ERROR_MESSAGE, error_message_id);
3734 3740
3735 UpdateRequiredAttributes(); 3741 UpdateRequiredAttributes();
3736 // If this is a web area for a presentational iframe, give it a role of
3737 // something other than DOCUMENT so that the fact that it's a separate doc
3738 // is not exposed to AT.
3739 if (owner()->IsWebAreaForPresentationalIframe()) {
dmazzoni 2017/07/06 22:58:05 Hmmm, in one of the previous changes this was part
3740 win_attributes_->ia2_role = ROLE_SYSTEM_GROUPING;
3741 }
3742 } 3742 }
3743 3743
3744 void BrowserAccessibilityComWin::UpdateStep2ComputeHypertext() { 3744 void BrowserAccessibilityComWin::UpdateStep2ComputeHypertext() {
3745 if (owner()->IsSimpleTextControl()) { 3745 if (owner()->IsSimpleTextControl()) {
3746 win_attributes_->hypertext = value(); 3746 win_attributes_->hypertext = value();
3747 return; 3747 return;
3748 } 3748 }
3749 3749
3750 if (!owner()->PlatformChildCount()) { 3750 if (!owner()->PlatformChildCount()) {
3751 if (owner()->IsRichTextControl()) { 3751 if (owner()->IsRichTextControl()) {
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
4908 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type); 4908 win_attributes_->ia2_attributes.push_back(L"text-input-type:" + type);
4909 } 4909 }
4910 } 4910 }
4911 4911
4912 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const { 4912 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const {
4913 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange, 4913 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange,
4914 ui::AX_EVENT_NONE, win_event_type, owner())) 4914 ui::AX_EVENT_NONE, win_event_type, owner()))
4915 ->Fire(); 4915 ->Fire();
4916 } 4916 }
4917 4917
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 = MSAA_IA2State();
5055 }
5056
5057 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( 4918 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin(
5058 BrowserAccessibility* obj) { 4919 BrowserAccessibility* obj) {
5059 if (!obj || !obj->IsNative()) 4920 if (!obj || !obj->IsNative())
5060 return nullptr; 4921 return nullptr;
5061 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); 4922 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM();
5062 return result; 4923 return result;
5063 } 4924 }
5064 4925
5065 } // namespace content 4926 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698