| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_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 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 } | 2509 } |
| 2510 | 2510 |
| 2511 STDMETHODIMP BrowserAccessibilityWin::get_startIndex(long* index) { | 2511 STDMETHODIMP BrowserAccessibilityWin::get_startIndex(long* index) { |
| 2512 if (!instance_active() || !IsHyperlink()) | 2512 if (!instance_active() || !IsHyperlink()) |
| 2513 return E_FAIL; | 2513 return E_FAIL; |
| 2514 | 2514 |
| 2515 if (!index) | 2515 if (!index) |
| 2516 return E_INVALIDARG; | 2516 return E_INVALIDARG; |
| 2517 | 2517 |
| 2518 int32_t hypertext_offset = 0; | 2518 int32_t hypertext_offset = 0; |
| 2519 const auto parent = GetParent(); | 2519 auto* parent = GetParent(); |
| 2520 if (parent) { | 2520 if (parent) { |
| 2521 hypertext_offset = | 2521 hypertext_offset = |
| 2522 ToBrowserAccessibilityWin(parent)->GetHypertextOffsetFromChild(*this); | 2522 ToBrowserAccessibilityWin(parent)->GetHypertextOffsetFromChild(*this); |
| 2523 } | 2523 } |
| 2524 *index = static_cast<LONG>(hypertext_offset); | 2524 *index = static_cast<LONG>(hypertext_offset); |
| 2525 return S_OK; | 2525 return S_OK; |
| 2526 } | 2526 } |
| 2527 | 2527 |
| 2528 STDMETHODIMP BrowserAccessibilityWin::get_endIndex(long* index) { | 2528 STDMETHODIMP BrowserAccessibilityWin::get_endIndex(long* index) { |
| 2529 LONG start_index; | 2529 LONG start_index; |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3302 ia_role != ROLE_SYSTEM_SLIDER) { | 3302 ia_role != ROLE_SYSTEM_SLIDER) { |
| 3303 *object = NULL; | 3303 *object = NULL; |
| 3304 return E_NOINTERFACE; | 3304 return E_NOINTERFACE; |
| 3305 } | 3305 } |
| 3306 } else if (iid == IID_ISimpleDOMDocument) { | 3306 } else if (iid == IID_ISimpleDOMDocument) { |
| 3307 if (ia_role != ROLE_SYSTEM_DOCUMENT) { | 3307 if (ia_role != ROLE_SYSTEM_DOCUMENT) { |
| 3308 *object = NULL; | 3308 *object = NULL; |
| 3309 return E_NOINTERFACE; | 3309 return E_NOINTERFACE; |
| 3310 } | 3310 } |
| 3311 } else if (iid == IID_IAccessibleHyperlink) { | 3311 } else if (iid == IID_IAccessibleHyperlink) { |
| 3312 auto ax_object = reinterpret_cast<const BrowserAccessibilityWin*>(this_ptr); | 3312 auto* ax_object = |
| 3313 reinterpret_cast<const BrowserAccessibilityWin*>(this_ptr); |
| 3313 if (!ax_object || !ax_object->IsHyperlink()) { | 3314 if (!ax_object || !ax_object->IsHyperlink()) { |
| 3314 *object = nullptr; | 3315 *object = nullptr; |
| 3315 return E_NOINTERFACE; | 3316 return E_NOINTERFACE; |
| 3316 } | 3317 } |
| 3317 } | 3318 } |
| 3318 | 3319 |
| 3319 return CComObjectRootBase::InternalQueryInterface( | 3320 return CComObjectRootBase::InternalQueryInterface( |
| 3320 this_ptr, entries, iid, object); | 3321 this_ptr, entries, iid, object); |
| 3321 } | 3322 } |
| 3322 | 3323 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3350 spelling_attribute.second.begin(), | 3351 spelling_attribute.second.begin(), |
| 3351 spelling_attribute.second.end()); | 3352 spelling_attribute.second.end()); |
| 3352 } | 3353 } |
| 3353 } | 3354 } |
| 3354 win_attributes_->offset_to_text_attributes.swap(attributes_map); | 3355 win_attributes_->offset_to_text_attributes.swap(attributes_map); |
| 3355 return; | 3356 return; |
| 3356 } | 3357 } |
| 3357 | 3358 |
| 3358 int start_offset = 0; | 3359 int start_offset = 0; |
| 3359 for (size_t i = 0; i < PlatformChildCount(); ++i) { | 3360 for (size_t i = 0; i < PlatformChildCount(); ++i) { |
| 3360 const auto child = ToBrowserAccessibilityWin(PlatformGetChild(i)); | 3361 auto* child = ToBrowserAccessibilityWin(PlatformGetChild(i)); |
| 3361 DCHECK(child); | 3362 DCHECK(child); |
| 3362 std::vector<base::string16> attributes(child->ComputeTextAttributes()); | 3363 std::vector<base::string16> attributes(child->ComputeTextAttributes()); |
| 3363 | 3364 |
| 3364 if (attributes_map.empty()) { | 3365 if (attributes_map.empty()) { |
| 3365 attributes_map[start_offset] = attributes; | 3366 attributes_map[start_offset] = attributes; |
| 3366 } else { | 3367 } else { |
| 3367 // Only add the attributes for this child if we are at the start of a new | 3368 // Only add the attributes for this child if we are at the start of a new |
| 3368 // style span. | 3369 // style span. |
| 3369 std::vector<base::string16> previous_attributes = | 3370 std::vector<base::string16> previous_attributes = |
| 3370 attributes_map.rbegin()->second; | 3371 attributes_map.rbegin()->second; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3575 win_attributes_->hypertext = name(); | 3576 win_attributes_->hypertext = name(); |
| 3576 return; | 3577 return; |
| 3577 } | 3578 } |
| 3578 | 3579 |
| 3579 // Construct the hypertext for this node, which contains the concatenation | 3580 // Construct the hypertext for this node, which contains the concatenation |
| 3580 // of all of the static text and widespace of this node's children and an | 3581 // of all of the static text and widespace of this node's children and an |
| 3581 // embedded object character for all the other children. Build up a map from | 3582 // embedded object character for all the other children. Build up a map from |
| 3582 // the character index of each embedded object character to the id of the | 3583 // the character index of each embedded object character to the id of the |
| 3583 // child object it points to. | 3584 // child object it points to. |
| 3584 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { | 3585 for (unsigned int i = 0; i < PlatformChildCount(); ++i) { |
| 3585 const auto child = ToBrowserAccessibilityWin(PlatformGetChild(i)); | 3586 auto* child = ToBrowserAccessibilityWin(PlatformGetChild(i)); |
| 3586 DCHECK(child); | 3587 DCHECK(child); |
| 3587 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. | 3588 // Similar to Firefox, we don't expose text-only objects in IA2 hypertext. |
| 3588 if (child->IsTextOnlyObject()) { | 3589 if (child->IsTextOnlyObject()) { |
| 3589 win_attributes_->hypertext += child->name(); | 3590 win_attributes_->hypertext += child->name(); |
| 3590 } else { | 3591 } else { |
| 3591 int32_t char_offset = static_cast<int32_t>(GetText().size()); | 3592 int32_t char_offset = static_cast<int32_t>(GetText().size()); |
| 3592 int32_t child_unique_id = child->unique_id(); | 3593 int32_t child_unique_id = child->unique_id(); |
| 3593 int32_t index = hyperlinks().size(); | 3594 int32_t index = hyperlinks().size(); |
| 3594 win_attributes_->hyperlink_offset_to_index[char_offset] = index; | 3595 win_attributes_->hyperlink_offset_to_index[char_offset] = index; |
| 3595 win_attributes_->hyperlinks.push_back(child_unique_id); | 3596 win_attributes_->hyperlinks.push_back(child_unique_id); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3913 spelling_attributes[start_offset] = start_attributes; | 3914 spelling_attributes[start_offset] = start_attributes; |
| 3914 spelling_attributes[end_offset] = end_attributes; | 3915 spelling_attributes[end_offset] = end_attributes; |
| 3915 } | 3916 } |
| 3916 } | 3917 } |
| 3917 if (IsSimpleTextControl()) { | 3918 if (IsSimpleTextControl()) { |
| 3918 int start_offset = 0; | 3919 int start_offset = 0; |
| 3919 for (const BrowserAccessibility* static_text = | 3920 for (const BrowserAccessibility* static_text = |
| 3920 BrowserAccessibilityManager::NextTextOnlyObject( | 3921 BrowserAccessibilityManager::NextTextOnlyObject( |
| 3921 InternalGetChild(0)); | 3922 InternalGetChild(0)); |
| 3922 static_text; static_text = static_text->GetNextSibling()) { | 3923 static_text; static_text = static_text->GetNextSibling()) { |
| 3923 auto text_win = ToBrowserAccessibilityWin(static_text); | 3924 auto* text_win = ToBrowserAccessibilityWin(static_text); |
| 3924 if (text_win) { | 3925 if (text_win) { |
| 3925 std::map<int, std::vector<base::string16>> text_spelling_attributes = | 3926 std::map<int, std::vector<base::string16>> text_spelling_attributes = |
| 3926 text_win->GetSpellingAttributes(); | 3927 text_win->GetSpellingAttributes(); |
| 3927 for (auto& attribute : text_spelling_attributes) { | 3928 for (auto& attribute : text_spelling_attributes) { |
| 3928 spelling_attributes[start_offset + attribute.first] = | 3929 spelling_attributes[start_offset + attribute.first] = |
| 3929 std::move(attribute.second); | 3930 std::move(attribute.second); |
| 3930 } | 3931 } |
| 3931 start_offset += static_cast<int>(text_win->GetText().length()); | 3932 start_offset += static_cast<int>(text_win->GetText().length()); |
| 3932 } | 3933 } |
| 3933 } | 3934 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4015 int value; | 4016 int value; |
| 4016 if (GetIntAttribute(attribute, &value)) { | 4017 if (GetIntAttribute(attribute, &value)) { |
| 4017 win_attributes_->ia2_attributes.push_back( | 4018 win_attributes_->ia2_attributes.push_back( |
| 4018 base::ASCIIToUTF16(ia2_attr) + L":" + | 4019 base::ASCIIToUTF16(ia2_attr) + L":" + |
| 4019 base::IntToString16(value)); | 4020 base::IntToString16(value)); |
| 4020 } | 4021 } |
| 4021 } | 4022 } |
| 4022 | 4023 |
| 4023 bool BrowserAccessibilityWin::IsHyperlink() const { | 4024 bool BrowserAccessibilityWin::IsHyperlink() const { |
| 4024 int32_t hyperlink_index = -1; | 4025 int32_t hyperlink_index = -1; |
| 4025 const auto parent = GetParent(); | 4026 auto* parent = GetParent(); |
| 4026 if (parent) { | 4027 if (parent) { |
| 4027 hyperlink_index = | 4028 hyperlink_index = |
| 4028 ToBrowserAccessibilityWin(parent)->GetHyperlinkIndexFromChild(*this); | 4029 ToBrowserAccessibilityWin(parent)->GetHyperlinkIndexFromChild(*this); |
| 4029 } | 4030 } |
| 4030 | 4031 |
| 4031 if (hyperlink_index >= 0) | 4032 if (hyperlink_index >= 0) |
| 4032 return true; | 4033 return true; |
| 4033 return false; | 4034 return false; |
| 4034 } | 4035 } |
| 4035 | 4036 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4102 | 4103 |
| 4103 int32_t hyperlink_index = GetHyperlinkIndexFromChild(child); | 4104 int32_t hyperlink_index = GetHyperlinkIndexFromChild(child); |
| 4104 if (hyperlink_index < 0) | 4105 if (hyperlink_index < 0) |
| 4105 return -1; | 4106 return -1; |
| 4106 | 4107 |
| 4107 return GetHypertextOffsetFromHyperlinkIndex(hyperlink_index); | 4108 return GetHypertextOffsetFromHyperlinkIndex(hyperlink_index); |
| 4108 } | 4109 } |
| 4109 | 4110 |
| 4110 int32_t BrowserAccessibilityWin::GetHypertextOffsetFromDescendant( | 4111 int32_t BrowserAccessibilityWin::GetHypertextOffsetFromDescendant( |
| 4111 const BrowserAccessibilityWin& descendant) const { | 4112 const BrowserAccessibilityWin& descendant) const { |
| 4112 auto parent_object = ToBrowserAccessibilityWin(descendant.GetParent()); | 4113 auto* parent_object = ToBrowserAccessibilityWin(descendant.GetParent()); |
| 4113 auto current_object = const_cast<BrowserAccessibilityWin*>(&descendant); | 4114 auto* current_object = const_cast<BrowserAccessibilityWin*>(&descendant); |
| 4114 while (parent_object && parent_object != this) { | 4115 while (parent_object && parent_object != this) { |
| 4115 current_object = parent_object; | 4116 current_object = parent_object; |
| 4116 parent_object = ToBrowserAccessibilityWin(current_object->GetParent()); | 4117 parent_object = ToBrowserAccessibilityWin(current_object->GetParent()); |
| 4117 } | 4118 } |
| 4118 if (!parent_object) | 4119 if (!parent_object) |
| 4119 return -1; | 4120 return -1; |
| 4120 | 4121 |
| 4121 return parent_object->GetHypertextOffsetFromChild(*current_object); | 4122 return parent_object->GetHypertextOffsetFromChild(*current_object); |
| 4122 } | 4123 } |
| 4123 | 4124 |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5199 return static_cast<BrowserAccessibilityWin*>(obj); | 5200 return static_cast<BrowserAccessibilityWin*>(obj); |
| 5200 } | 5201 } |
| 5201 | 5202 |
| 5202 const BrowserAccessibilityWin* | 5203 const BrowserAccessibilityWin* |
| 5203 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { | 5204 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { |
| 5204 DCHECK(!obj || obj->IsNative()); | 5205 DCHECK(!obj || obj->IsNative()); |
| 5205 return static_cast<const BrowserAccessibilityWin*>(obj); | 5206 return static_cast<const BrowserAccessibilityWin*>(obj); |
| 5206 } | 5207 } |
| 5207 | 5208 |
| 5208 } // namespace content | 5209 } // namespace content |
| OLD | NEW |