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

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

Issue 2988753002: Revert of Migrate BrowserAccessibility windows unique id handling to AXPlatformNodeWin. (Closed)
Patch Set: 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) { 132 STDMETHODIMP BrowserAccessibilityComWin::get_uniqueID(LONG* unique_id) {
133 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID); 133 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_UNIQUE_ID);
134 if (!owner()) 134 if (!owner())
135 return E_FAIL; 135 return E_FAIL;
136 136
137 if (!unique_id) 137 if (!unique_id)
138 return E_INVALIDARG; 138 return E_INVALIDARG;
139 139
140 *unique_id = -AXPlatformNodeWin::unique_id(); 140 *unique_id = -owner()->unique_id();
141 return S_OK; 141 return S_OK;
142 } 142 }
143 143
144 STDMETHODIMP BrowserAccessibilityComWin::get_windowHandle(HWND* window_handle) { 144 STDMETHODIMP BrowserAccessibilityComWin::get_windowHandle(HWND* window_handle) {
145 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE); 145 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_WINDOW_HANDLE);
146 if (!owner()) 146 if (!owner())
147 return E_FAIL; 147 return E_FAIL;
148 148
149 if (!window_handle) 149 if (!window_handle)
150 return E_INVALIDARG; 150 return E_INVALIDARG;
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes); 1242 AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
1243 if (!owner()) 1243 if (!owner())
1244 return E_FAIL; 1244 return E_FAIL;
1245 1245
1246 if (!hyperlink || index < 0 || 1246 if (!hyperlink || index < 0 ||
1247 index >= static_cast<long>(hyperlinks().size())) { 1247 index >= static_cast<long>(hyperlinks().size())) {
1248 return E_INVALIDARG; 1248 return E_INVALIDARG;
1249 } 1249 }
1250 1250
1251 int32_t id = hyperlinks()[index]; 1251 int32_t id = hyperlinks()[index];
1252 auto* link = static_cast<BrowserAccessibilityComWin*>( 1252 BrowserAccessibilityComWin* link =
1253 AXPlatformNodeWin::GetFromUniqueId(id)); 1253 ToBrowserAccessibilityComWin(owner()->GetFromUniqueID(id));
1254 if (!link) 1254 if (!link)
1255 return E_FAIL; 1255 return E_FAIL;
1256 1256
1257 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference()); 1257 *hyperlink = static_cast<IAccessibleHyperlink*>(link->NewReference());
1258 return S_OK; 1258 return S_OK;
1259 } 1259 }
1260 1260
1261 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlinkIndex( 1261 STDMETHODIMP BrowserAccessibilityComWin::get_hyperlinkIndex(
1262 long char_index, 1262 long char_index,
1263 long* hyperlink_index) { 1263 long* hyperlink_index) {
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 1701
1702 base::string16 tag; 1702 base::string16 tag;
1703 if (owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag)) 1703 if (owner()->GetString16Attribute(ui::AX_ATTR_HTML_TAG, &tag))
1704 *node_name = SysAllocString(tag.c_str()); 1704 *node_name = SysAllocString(tag.c_str());
1705 else 1705 else
1706 *node_name = nullptr; 1706 *node_name = nullptr;
1707 1707
1708 *name_space_id = 0; 1708 *name_space_id = 0;
1709 *node_value = SysAllocString(value().c_str()); 1709 *node_value = SysAllocString(value().c_str());
1710 *num_children = owner()->PlatformChildCount(); 1710 *num_children = owner()->PlatformChildCount();
1711 *unique_id = -AXPlatformNodeWin::unique_id(); 1711 *unique_id = -owner()->unique_id();
1712 1712
1713 if (owner()->IsDocument()) { 1713 if (owner()->IsDocument()) {
1714 *node_type = NODETYPE_DOCUMENT; 1714 *node_type = NODETYPE_DOCUMENT;
1715 } else if (owner()->IsTextOnlyObject()) { 1715 } else if (owner()->IsTextOnlyObject()) {
1716 *node_type = NODETYPE_TEXT; 1716 *node_type = NODETYPE_TEXT;
1717 } else { 1717 } else {
1718 *node_type = NODETYPE_ELEMENT; 1718 *node_type = NODETYPE_ELEMENT;
1719 } 1719 }
1720 1720
1721 return S_OK; 1721 return S_OK;
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 // the character index of each embedded object character to the id of the 2476 // the character index of each embedded object character to the id of the
2477 // child object it points to. 2477 // child object it points to.
2478 for (unsigned int i = 0; i < owner()->PlatformChildCount(); ++i) { 2478 for (unsigned int i = 0; i < owner()->PlatformChildCount(); ++i) {
2479 auto* child = ToBrowserAccessibilityComWin(owner()->PlatformGetChild(i)); 2479 auto* child = ToBrowserAccessibilityComWin(owner()->PlatformGetChild(i));
2480 DCHECK(child); 2480 DCHECK(child);
2481 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. 2481 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext.
2482 if (child->owner()->IsTextOnlyObject()) { 2482 if (child->owner()->IsTextOnlyObject()) {
2483 win_attributes_->hypertext += child->name(); 2483 win_attributes_->hypertext += child->name();
2484 } else { 2484 } else {
2485 int32_t char_offset = static_cast<int32_t>(owner()->GetText().size()); 2485 int32_t char_offset = static_cast<int32_t>(owner()->GetText().size());
2486 int32_t child_unique_id = child->unique_id(); 2486 int32_t child_unique_id = child->owner()->unique_id();
2487 int32_t index = hyperlinks().size(); 2487 int32_t index = hyperlinks().size();
2488 win_attributes_->hyperlink_offset_to_index[char_offset] = index; 2488 win_attributes_->hyperlink_offset_to_index[char_offset] = index;
2489 win_attributes_->hyperlinks.push_back(child_unique_id); 2489 win_attributes_->hyperlinks.push_back(child_unique_id);
2490 win_attributes_->hypertext += kEmbeddedCharacter; 2490 win_attributes_->hypertext += kEmbeddedCharacter;
2491 } 2491 }
2492 } 2492 }
2493 } 2493 }
2494 2494
2495 void BrowserAccessibilityComWin::UpdateStep3FireEvents( 2495 void BrowserAccessibilityComWin::UpdateStep3FireEvents(
2496 bool is_subtree_creation) { 2496 bool is_subtree_creation) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2591 // Detach BrowserAccessibilityWin from us. 2591 // Detach BrowserAccessibilityWin from us.
2592 owner_ = nullptr; 2592 owner_ = nullptr;
2593 AXPlatformNodeWin::Destroy(); 2593 AXPlatformNodeWin::Destroy();
2594 } 2594 }
2595 2595
2596 void BrowserAccessibilityComWin::Init(ui::AXPlatformNodeDelegate* delegate) { 2596 void BrowserAccessibilityComWin::Init(ui::AXPlatformNodeDelegate* delegate) {
2597 owner_ = static_cast<BrowserAccessibilityWin*>(delegate); 2597 owner_ = static_cast<BrowserAccessibilityWin*>(delegate);
2598 AXPlatformNodeBase::Init(delegate); 2598 AXPlatformNodeBase::Init(delegate);
2599 } 2599 }
2600 2600
2601 ui::AXPlatformNode* BrowserAccessibilityComWin::GetFromUniqueId(
2602 int32_t unique_id) {
2603 return ToBrowserAccessibilityComWin(
2604 BrowserAccessibility::GetFromUniqueID(unique_id));
2605 }
2606
2601 std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes() 2607 std::vector<base::string16> BrowserAccessibilityComWin::ComputeTextAttributes()
2602 const { 2608 const {
2603 std::vector<base::string16> attributes; 2609 std::vector<base::string16> attributes;
2604 2610
2605 // We include list markers for now, but there might be other objects that are 2611 // We include list markers for now, but there might be other objects that are
2606 // auto generated. 2612 // auto generated.
2607 // TODO(nektar): Compute what objects are auto-generated in Blink. 2613 // TODO(nektar): Compute what objects are auto-generated in Blink.
2608 if (owner()->GetRole() == ui::AX_ROLE_LIST_MARKER) 2614 if (owner()->GetRole() == ui::AX_ROLE_LIST_MARKER)
2609 attributes.push_back(L"auto-generated:true"); 2615 attributes.push_back(L"auto-generated:true");
2610 else 2616 else
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 2845
2840 LONG child_id = var_id.lVal; 2846 LONG child_id = var_id.lVal;
2841 if (child_id == CHILDID_SELF) 2847 if (child_id == CHILDID_SELF)
2842 return this; 2848 return this;
2843 2849
2844 if (child_id >= 1 && 2850 if (child_id >= 1 &&
2845 child_id <= static_cast<LONG>(owner()->PlatformChildCount())) 2851 child_id <= static_cast<LONG>(owner()->PlatformChildCount()))
2846 return ToBrowserAccessibilityComWin( 2852 return ToBrowserAccessibilityComWin(
2847 owner()->PlatformGetChild(child_id - 1)); 2853 owner()->PlatformGetChild(child_id - 1));
2848 2854
2849 auto* child = static_cast<BrowserAccessibilityComWin*>( 2855 BrowserAccessibilityComWin* child = ToBrowserAccessibilityComWin(
2850 AXPlatformNodeWin::GetFromUniqueId(-child_id)); 2856 BrowserAccessibility::GetFromUniqueID(-child_id));
2851 if (child && child->owner()->IsDescendantOf(owner())) 2857 if (child && child->owner()->IsDescendantOf(owner()))
2852 return child; 2858 return child;
2853 2859
2854 return nullptr; 2860 return nullptr;
2855 } 2861 }
2856 2862
2857 HRESULT BrowserAccessibilityComWin::GetStringAttributeAsBstr( 2863 HRESULT BrowserAccessibilityComWin::GetStringAttributeAsBstr(
2858 ui::AXStringAttribute attribute, 2864 ui::AXStringAttribute attribute,
2859 BSTR* value_bstr) { 2865 BSTR* value_bstr) {
2860 base::string16 str; 2866 base::string16 str;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 BrowserAccessibilityComWin::GetHyperlinkFromHypertextOffset(int offset) const { 2920 BrowserAccessibilityComWin::GetHyperlinkFromHypertextOffset(int offset) const {
2915 std::map<int32_t, int32_t>::iterator iterator = 2921 std::map<int32_t, int32_t>::iterator iterator =
2916 hyperlink_offset_to_index().find(offset); 2922 hyperlink_offset_to_index().find(offset);
2917 if (iterator == hyperlink_offset_to_index().end()) 2923 if (iterator == hyperlink_offset_to_index().end())
2918 return nullptr; 2924 return nullptr;
2919 2925
2920 int32_t index = iterator->second; 2926 int32_t index = iterator->second;
2921 DCHECK_GE(index, 0); 2927 DCHECK_GE(index, 0);
2922 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size())); 2928 DCHECK_LT(index, static_cast<int32_t>(hyperlinks().size()));
2923 int32_t id = hyperlinks()[index]; 2929 int32_t id = hyperlinks()[index];
2924 auto* hyperlink = static_cast<BrowserAccessibilityComWin*>( 2930 BrowserAccessibilityComWin* hyperlink =
2925 AXPlatformNodeWin::GetFromUniqueId(id)); 2931 ToBrowserAccessibilityComWin(owner()->GetFromUniqueID(id));
2926 if (!hyperlink) 2932 if (!hyperlink)
2927 return nullptr; 2933 return nullptr;
2928 return hyperlink; 2934 return hyperlink;
2929 } 2935 }
2930 2936
2931 int32_t BrowserAccessibilityComWin::GetHyperlinkIndexFromChild( 2937 int32_t BrowserAccessibilityComWin::GetHyperlinkIndexFromChild(
2932 const BrowserAccessibilityComWin& child) const { 2938 const BrowserAccessibilityComWin& child) const {
2933 if (hyperlinks().empty()) 2939 if (hyperlinks().empty())
2934 return -1; 2940 return -1;
2935 2941
2936 auto iterator = 2942 auto iterator = std::find(hyperlinks().begin(), hyperlinks().end(),
2937 std::find(hyperlinks().begin(), hyperlinks().end(), child.unique_id()); 2943 child.owner()->unique_id());
2938 if (iterator == hyperlinks().end()) 2944 if (iterator == hyperlinks().end())
2939 return -1; 2945 return -1;
2940 2946
2941 return static_cast<int32_t>(iterator - hyperlinks().begin()); 2947 return static_cast<int32_t>(iterator - hyperlinks().begin());
2942 } 2948 }
2943 2949
2944 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromHyperlinkIndex( 2950 int32_t BrowserAccessibilityComWin::GetHypertextOffsetFromHyperlinkIndex(
2945 int32_t hyperlink_index) const { 2951 int32_t hyperlink_index) const {
2946 for (auto& offset_index : hyperlink_offset_to_index()) { 2952 for (auto& offset_index : hyperlink_offset_to_index()) {
2947 if (offset_index.second == hyperlink_index) 2953 if (offset_index.second == hyperlink_index)
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3386 3392
3387 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin( 3393 BrowserAccessibilityComWin* ToBrowserAccessibilityComWin(
3388 BrowserAccessibility* obj) { 3394 BrowserAccessibility* obj) {
3389 if (!obj || !obj->IsNative()) 3395 if (!obj || !obj->IsNative())
3390 return nullptr; 3396 return nullptr;
3391 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM(); 3397 auto* result = static_cast<BrowserAccessibilityWin*>(obj)->GetCOM();
3392 return result; 3398 return result;
3393 } 3399 }
3394 3400
3395 } // namespace content 3401 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698