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

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

Issue 2968833002: Move IA2 State handling to AXPlatformNodeWin. (Closed)
Patch Set: rebase 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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 DCHECK(*attributes); 713 DCHECK(*attributes);
714 return S_OK; 714 return S_OK;
715 } 715 }
716 716
717 STDMETHODIMP BrowserAccessibilityComWin::get_states(AccessibleStates* states) { 717 STDMETHODIMP BrowserAccessibilityComWin::get_states(AccessibleStates* states) {
718 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_STATES); 718 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_STATES);
719 if (!owner()) 719 if (!owner())
720 return E_FAIL; 720 return E_FAIL;
721 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 721 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
722 722
723 if (!states) 723 return AXPlatformNodeWin::get_states(states);
724 return E_INVALIDARG;
725
726 *states = ia2_state();
727
728 return S_OK;
729 } 724 }
730 725
731 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) { 726 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) {
732 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID); 727 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID);
733 if (!owner()) 728 if (!owner())
734 return E_FAIL; 729 return E_FAIL;
735 730
736 if (!unique_id) 731 if (!unique_id)
737 return E_INVALIDARG; 732 return E_INVALIDARG;
738 733
(...skipping 4176 matching lines...) Expand 10 before | Expand all | Expand 10 after
4915 } 4910 }
4916 4911
4917 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const { 4912 void BrowserAccessibilityComWin::FireNativeEvent(LONG win_event_type) const {
4918 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange, 4913 (new BrowserAccessibilityEventWin(BrowserAccessibilityEvent::FromTreeChange,
4919 ui::AX_EVENT_NONE, win_event_type, owner())) 4914 ui::AX_EVENT_NONE, win_event_type, owner()))
4920 ->Fire(); 4915 ->Fire();
4921 } 4916 }
4922 4917
4923 void BrowserAccessibilityComWin::InitRoleAndState() { 4918 void BrowserAccessibilityComWin::InitRoleAndState() {
4924 int32_t ia2_role = 0; 4919 int32_t ia2_role = 0;
4925 int32_t ia2_state = IA2_STATE_OPAQUE;
4926
4927 const auto checked_state = static_cast<ui::AXCheckedState>(
4928 owner()->GetIntAttribute(ui::AX_ATTR_CHECKED_STATE));
4929 if (checked_state) {
4930 ia2_state |= IA2_STATE_CHECKABLE;
4931 }
4932
4933 if (owner()->HasIntAttribute(ui::AX_ATTR_INVALID_STATE) &&
4934 owner()->GetIntAttribute(ui::AX_ATTR_INVALID_STATE) !=
4935 ui::AX_INVALID_STATE_FALSE)
4936 ia2_state |= IA2_STATE_INVALID_ENTRY;
4937 if (owner()->HasState(ui::AX_STATE_REQUIRED))
4938 ia2_state |= IA2_STATE_REQUIRED;
4939 if (owner()->HasState(ui::AX_STATE_VERTICAL))
4940 ia2_state |= IA2_STATE_VERTICAL;
4941 if (owner()->HasState(ui::AX_STATE_HORIZONTAL))
4942 ia2_state |= IA2_STATE_HORIZONTAL;
4943
4944 if (owner()->HasState(ui::AX_STATE_EDITABLE))
4945 ia2_state |= IA2_STATE_EDITABLE;
4946
4947 if (!owner()->GetStringAttribute(ui::AX_ATTR_AUTO_COMPLETE).empty())
4948 ia2_state |= IA2_STATE_SUPPORTS_AUTOCOMPLETION;
4949
4950 if (owner()->GetBoolAttribute(ui::AX_ATTR_MODAL))
4951 ia2_state |= IA2_STATE_MODAL;
4952 4920
4953 base::string16 html_tag = owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG); 4921 base::string16 html_tag = owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG);
4954 switch (owner()->GetRole()) { 4922 switch (owner()->GetRole()) {
4955 case ui::AX_ROLE_BANNER: 4923 case ui::AX_ROLE_BANNER:
4956 ia2_role = IA2_ROLE_HEADER; 4924 ia2_role = IA2_ROLE_HEADER;
4957 break; 4925 break;
4958 case ui::AX_ROLE_BLOCKQUOTE: 4926 case ui::AX_ROLE_BLOCKQUOTE:
4959 ia2_role = IA2_ROLE_SECTION; 4927 ia2_role = IA2_ROLE_SECTION;
4960 break; 4928 break;
4961 case ui::AX_ROLE_CANVAS: 4929 case ui::AX_ROLE_CANVAS:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
5020 break; 4988 break;
5021 case ui::AX_ROLE_MARK: 4989 case ui::AX_ROLE_MARK:
5022 ia2_role = IA2_ROLE_TEXT_FRAME; 4990 ia2_role = IA2_ROLE_TEXT_FRAME;
5023 break; 4991 break;
5024 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: 4992 case ui::AX_ROLE_MENU_ITEM_CHECK_BOX:
5025 ia2_role = IA2_ROLE_CHECK_MENU_ITEM; 4993 ia2_role = IA2_ROLE_CHECK_MENU_ITEM;
5026 break; 4994 break;
5027 case ui::AX_ROLE_MENU_ITEM_RADIO: 4995 case ui::AX_ROLE_MENU_ITEM_RADIO:
5028 ia2_role = IA2_ROLE_RADIO_MENU_ITEM; 4996 ia2_role = IA2_ROLE_RADIO_MENU_ITEM;
5029 break; 4997 break;
5030 case ui::AX_ROLE_MENU_LIST_POPUP:
5031 ia2_state &= ~(IA2_STATE_EDITABLE);
5032 break;
5033 case ui::AX_ROLE_MENU_LIST_OPTION:
5034 ia2_state &= ~(IA2_STATE_EDITABLE);
5035 break;
5036 case ui::AX_ROLE_NAVIGATION: 4998 case ui::AX_ROLE_NAVIGATION:
5037 ia2_role = IA2_ROLE_SECTION; 4999 ia2_role = IA2_ROLE_SECTION;
5038 break; 5000 break;
5039 case ui::AX_ROLE_NOTE: 5001 case ui::AX_ROLE_NOTE:
5040 ia2_role = IA2_ROLE_NOTE; 5002 ia2_role = IA2_ROLE_NOTE;
5041 break; 5003 break;
5042 case ui::AX_ROLE_PARAGRAPH: 5004 case ui::AX_ROLE_PARAGRAPH:
5043 ia2_role = IA2_ROLE_PARAGRAPH; 5005 ia2_role = IA2_ROLE_PARAGRAPH;
5044 break; 5006 break;
5045 case ui::AX_ROLE_PRE: 5007 case ui::AX_ROLE_PRE:
5046 ia2_role = IA2_ROLE_PARAGRAPH; 5008 ia2_role = IA2_ROLE_PARAGRAPH;
5047 break; 5009 break;
5048 case ui::AX_ROLE_REGION: 5010 case ui::AX_ROLE_REGION:
5049 if (html_tag == L"section") { 5011 if (html_tag == L"section") {
5050 ia2_role = IA2_ROLE_SECTION; 5012 ia2_role = IA2_ROLE_SECTION;
5051 } 5013 }
5052 break; 5014 break;
5053 case ui::AX_ROLE_RUBY: 5015 case ui::AX_ROLE_RUBY:
5054 ia2_role = IA2_ROLE_TEXT_FRAME; 5016 ia2_role = IA2_ROLE_TEXT_FRAME;
5055 break; 5017 break;
5056 case ui::AX_ROLE_RULER: 5018 case ui::AX_ROLE_RULER:
5057 ia2_role = IA2_ROLE_RULER; 5019 ia2_role = IA2_ROLE_RULER;
5058 break; 5020 break;
5059 case ui::AX_ROLE_SCROLL_AREA: 5021 case ui::AX_ROLE_SCROLL_AREA:
5060 ia2_role = IA2_ROLE_SCROLL_PANE; 5022 ia2_role = IA2_ROLE_SCROLL_PANE;
5061 ia2_state &= ~(IA2_STATE_EDITABLE);
5062 break; 5023 break;
5063 case ui::AX_ROLE_SEARCH: 5024 case ui::AX_ROLE_SEARCH:
5064 ia2_role = IA2_ROLE_SECTION; 5025 ia2_role = IA2_ROLE_SECTION;
5065 break; 5026 break;
5066 case ui::AX_ROLE_SWITCH: 5027 case ui::AX_ROLE_SWITCH:
5067 ia2_role = IA2_ROLE_TOGGLE_BUTTON; 5028 ia2_role = IA2_ROLE_TOGGLE_BUTTON;
5068 break; 5029 break;
5069 case ui::AX_ROLE_TABLE_HEADER_CONTAINER: 5030 case ui::AX_ROLE_TABLE_HEADER_CONTAINER:
5070 ia2_role = IA2_ROLE_SECTION; 5031 ia2_role = IA2_ROLE_SECTION;
5071 break; 5032 break;
5072 case ui::AX_ROLE_TOGGLE_BUTTON: 5033 case ui::AX_ROLE_TOGGLE_BUTTON:
5073 ia2_role = IA2_ROLE_TOGGLE_BUTTON; 5034 ia2_role = IA2_ROLE_TOGGLE_BUTTON;
5074 break; 5035 break;
5075 case ui::AX_ROLE_TEXT_FIELD:
5076 case ui::AX_ROLE_SEARCH_BOX:
5077 if (owner()->HasState(ui::AX_STATE_MULTILINE)) {
5078 ia2_state |= IA2_STATE_MULTI_LINE;
5079 } else {
5080 ia2_state |= IA2_STATE_SINGLE_LINE;
5081 }
5082 ia2_state |= IA2_STATE_SELECTABLE_TEXT;
5083 break;
5084 case ui::AX_ROLE_ABBR: 5036 case ui::AX_ROLE_ABBR:
5085 case ui::AX_ROLE_TIME: 5037 case ui::AX_ROLE_TIME:
5086 ia2_role = IA2_ROLE_TEXT_FRAME; 5038 ia2_role = IA2_ROLE_TEXT_FRAME;
5087 break; 5039 break;
5088 default: 5040 default:
5089 break; 5041 break;
5090 } 5042 }
5091 5043
5092 win_attributes_->ia_role = MSAARole(); 5044 win_attributes_->ia_role = MSAARole();
5093 win_attributes_->ia_state = MSAAState(); 5045 win_attributes_->ia_state = MSAAState();
5094 win_attributes_->role_name = base::UTF8ToUTF16(StringOverrideForMSAARole()); 5046 win_attributes_->role_name = base::UTF8ToUTF16(StringOverrideForMSAARole());
5095 5047
5096 // If we didn't explicitly set the IAccessible2 role, make it the same 5048 // If we didn't explicitly set the IAccessible2 role, make it the same
5097 // as the MSAA role. 5049 // as the MSAA role.
5098 if (!ia2_role) 5050 if (!ia2_role)
5099 ia2_role = win_attributes_->ia_role; 5051 ia2_role = win_attributes_->ia_role;
5100 5052
5101 win_attributes_->ia2_role = ia2_role; 5053 win_attributes_->ia2_role = ia2_role;
5102 win_attributes_->ia2_state = ia2_state; 5054 win_attributes_->ia2_state = MSAA_IA2State();
5103 } 5055 }
5104 5056
5105 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( 5057 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin(
5106 BrowserAccessibility* obj) { 5058 BrowserAccessibility* obj) {
5107 if (!obj || !obj->IsNative()) 5059 if (!obj || !obj->IsNative())
5108 return nullptr; 5060 return nullptr;
5109 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); 5061 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM();
5110 return result; 5062 return result;
5111 } 5063 }
5112 5064
5113 } // namespace content 5065 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698