| 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/accessibility_tree_formatter.h" | 5 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
| 6 | 6 |
| 7 #include <oleacc.h> | 7 #include <oleacc.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return new AccessibilityTreeFormatterWin(); | 47 return new AccessibilityTreeFormatterWin(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 AccessibilityTreeFormatterWin::AccessibilityTreeFormatterWin() { | 50 AccessibilityTreeFormatterWin::AccessibilityTreeFormatterWin() { |
| 51 ui::win::CreateATLModuleIfNeeded(); | 51 ui::win::CreateATLModuleIfNeeded(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 AccessibilityTreeFormatterWin::~AccessibilityTreeFormatterWin() { | 54 AccessibilityTreeFormatterWin::~AccessibilityTreeFormatterWin() { |
| 55 } | 55 } |
| 56 | 56 |
| 57 const char* ALL_ATTRIBUTES[] = { | 57 const char* ALL_ATTRIBUTES[] = {"name", |
| 58 "name", | 58 "value", |
| 59 "value", | 59 "states", |
| 60 "states", | 60 "attributes", |
| 61 "attributes", | 61 "text_attributes", |
| 62 "role_name", | 62 "role_name", |
| 63 "ia2_hypertext", | 63 "ia2_hypertext", |
| 64 "currentValue", | 64 "currentValue", |
| 65 "minimumValue", | 65 "minimumValue", |
| 66 "maximumValue", | 66 "maximumValue", |
| 67 "description", | 67 "description", |
| 68 "default_action", | 68 "default_action", |
| 69 "keyboard_shortcut", | 69 "keyboard_shortcut", |
| 70 "location", | 70 "location", |
| 71 "size", | 71 "size", |
| 72 "index_in_parent", | 72 "index_in_parent", |
| 73 "n_relations", | 73 "n_relations", |
| 74 "group_level", | 74 "group_level", |
| 75 "similar_items_in_group", | 75 "similar_items_in_group", |
| 76 "position_in_group", | 76 "position_in_group", |
| 77 "table_rows", | 77 "table_rows", |
| 78 "table_columns", | 78 "table_columns", |
| 79 "row_index", | 79 "row_index", |
| 80 "column_index", | 80 "column_index", |
| 81 "n_characters", | 81 "n_characters", |
| 82 "caret_offset", | 82 "caret_offset", |
| 83 "n_selections", | 83 "n_selections", |
| 84 "selection_start", | 84 "selection_start", |
| 85 "selection_end" | 85 "selection_end"}; |
| 86 }; | |
| 87 | 86 |
| 88 namespace { | 87 namespace { |
| 89 | 88 |
| 90 base::string16 GetIA2Hypertext(BrowserAccessibilityWin& ax_object) { | 89 base::string16 GetIA2Hypertext(BrowserAccessibilityWin& ax_object) { |
| 91 base::win::ScopedBstr text_bstr; | 90 base::win::ScopedBstr text_bstr; |
| 92 HRESULT hr; | 91 HRESULT hr; |
| 93 | 92 |
| 94 hr = ax_object.get_text(0, IA2_TEXT_OFFSET_LENGTH, text_bstr.Receive()); | 93 hr = ax_object.get_text(0, IA2_TEXT_OFFSET_LENGTH, text_bstr.Receive()); |
| 95 if (FAILED(hr)) | 94 if (FAILED(hr)) |
| 96 return base::string16(); | 95 return base::string16(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 std::vector<base::string16> state_strings; | 182 std::vector<base::string16> state_strings; |
| 184 int32_t ia_state = ax_object->ia_state(); | 183 int32_t ia_state = ax_object->ia_state(); |
| 185 | 184 |
| 186 // Avoid flakiness: these states depend on whether the window is focused | 185 // Avoid flakiness: these states depend on whether the window is focused |
| 187 // and the position of the mouse cursor. | 186 // and the position of the mouse cursor. |
| 188 ia_state &= ~STATE_SYSTEM_HOTTRACKED; | 187 ia_state &= ~STATE_SYSTEM_HOTTRACKED; |
| 189 ia_state &= ~STATE_SYSTEM_OFFSCREEN; | 188 ia_state &= ~STATE_SYSTEM_OFFSCREEN; |
| 190 | 189 |
| 191 IAccessibleStateToStringVector(ia_state, &state_strings); | 190 IAccessibleStateToStringVector(ia_state, &state_strings); |
| 192 IAccessible2StateToStringVector(ax_object->ia2_state(), &state_strings); | 191 IAccessible2StateToStringVector(ax_object->ia2_state(), &state_strings); |
| 193 base::ListValue* states = new base::ListValue; | 192 scoped_ptr<base::ListValue> states(new base::ListValue()); |
| 194 for (const auto& state_string : state_strings) | 193 for (const base::string16& state_string : state_strings) |
| 195 states->AppendString(base::UTF16ToUTF8(state_string)); | 194 states->AppendString(base::UTF16ToUTF8(state_string)); |
| 196 dict->Set("states", states); | 195 dict->Set("states", std::move(states)); |
| 197 | 196 |
| 198 const std::vector<base::string16>& ia2_attributes = | 197 const std::vector<base::string16>& ia2_attributes = |
| 199 ax_object->ia2_attributes(); | 198 ax_object->ia2_attributes(); |
| 200 base::ListValue* attributes = new base::ListValue; | 199 scoped_ptr<base::ListValue> attributes(new base::ListValue()); |
| 201 for (const auto& ia2_attribute : ia2_attributes) | 200 for (const base::string16& ia2_attribute : ia2_attributes) |
| 202 attributes->AppendString(base::UTF16ToUTF8(ia2_attribute)); | 201 attributes->AppendString(base::UTF16ToUTF8(ia2_attribute)); |
| 203 dict->Set("attributes", attributes); | 202 dict->Set("attributes", std::move(attributes)); |
| 203 |
| 204 ax_object->ComputeStylesIfNeeded(); |
| 205 const std::map<int, std::vector<base::string16>>& ia2_text_attributes = |
| 206 ax_object->offset_to_text_attributes(); |
| 207 scoped_ptr<base::ListValue> text_attributes(new base::ListValue()); |
| 208 for (const auto& style_span : ia2_text_attributes) { |
| 209 int start_offset = style_span.first; |
| 210 text_attributes->AppendString("offset:" + base::IntToString(start_offset)); |
| 211 for (const base::string16& text_attribute : style_span.second) |
| 212 text_attributes->AppendString(base::UTF16ToUTF8(text_attribute)); |
| 213 } |
| 214 dict->Set("text_attributes", std::move(text_attributes)); |
| 204 | 215 |
| 205 dict->SetString("role_name", ax_object->role_name()); | 216 dict->SetString("role_name", ax_object->role_name()); |
| 206 dict->SetString("ia2_hypertext", GetIA2Hypertext(*ax_object)); | 217 dict->SetString("ia2_hypertext", GetIA2Hypertext(*ax_object)); |
| 207 | 218 |
| 208 VARIANT currentValue; | 219 VARIANT currentValue; |
| 209 if (ax_object->get_currentValue(¤tValue) == S_OK) | 220 if (ax_object->get_currentValue(¤tValue) == S_OK) |
| 210 dict->SetDouble("currentValue", V_R8(¤tValue)); | 221 dict->SetDouble("currentValue", V_R8(¤tValue)); |
| 211 | 222 |
| 212 VARIANT minimumValue; | 223 VARIANT minimumValue; |
| 213 if (ax_object->get_minimumValue(&minimumValue) == S_OK) | 224 if (ax_object->get_minimumValue(&minimumValue) == S_OK) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 428 |
| 418 const std::string AccessibilityTreeFormatterWin::GetAllowString() { | 429 const std::string AccessibilityTreeFormatterWin::GetAllowString() { |
| 419 return "@WIN-ALLOW:"; | 430 return "@WIN-ALLOW:"; |
| 420 } | 431 } |
| 421 | 432 |
| 422 const std::string AccessibilityTreeFormatterWin::GetDenyString() { | 433 const std::string AccessibilityTreeFormatterWin::GetDenyString() { |
| 423 return "@WIN-DENY:"; | 434 return "@WIN-DENY:"; |
| 424 } | 435 } |
| 425 | 436 |
| 426 } // namespace content | 437 } // namespace content |
| OLD | NEW |