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.h" | 5 #include "content/browser/accessibility/browser_accessibility.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
13 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
14 #include "content/common/accessibility_messages.h" | 16 #include "content/common/accessibility_messages.h" |
15 #include "ui/accessibility/ax_text_utils.h" | 17 #include "ui/accessibility/ax_text_utils.h" |
16 | 18 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 case ui::AX_ROLE_SCROLL_BAR: | 61 case ui::AX_ROLE_SCROLL_BAR: |
60 case ui::AX_ROLE_SLIDER: | 62 case ui::AX_ROLE_SLIDER: |
61 case ui::AX_ROLE_SPLITTER: | 63 case ui::AX_ROLE_SPLITTER: |
62 case ui::AX_ROLE_PROGRESS_INDICATOR: | 64 case ui::AX_ROLE_PROGRESS_INDICATOR: |
63 return true; | 65 return true; |
64 default: | 66 default: |
65 return false; | 67 return false; |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 uint32 BrowserAccessibility::PlatformChildCount() const { | 71 uint32_t BrowserAccessibility::PlatformChildCount() const { |
70 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { | 72 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { |
71 BrowserAccessibilityManager* child_manager = | 73 BrowserAccessibilityManager* child_manager = |
72 BrowserAccessibilityManager::FromID( | 74 BrowserAccessibilityManager::FromID( |
73 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); | 75 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); |
74 if (child_manager) | 76 if (child_manager) |
75 return 1; | 77 return 1; |
76 | 78 |
77 return 0; | 79 return 0; |
78 } | 80 } |
79 | 81 |
(...skipping 14 matching lines...) Expand all Loading... |
94 | 96 |
95 return false; | 97 return false; |
96 } | 98 } |
97 | 99 |
98 bool BrowserAccessibility::IsTextOnlyObject() const { | 100 bool BrowserAccessibility::IsTextOnlyObject() const { |
99 return GetRole() == ui::AX_ROLE_STATIC_TEXT || | 101 return GetRole() == ui::AX_ROLE_STATIC_TEXT || |
100 GetRole() == ui::AX_ROLE_LINE_BREAK; | 102 GetRole() == ui::AX_ROLE_LINE_BREAK; |
101 } | 103 } |
102 | 104 |
103 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( | 105 BrowserAccessibility* BrowserAccessibility::PlatformGetChild( |
104 uint32 child_index) const { | 106 uint32_t child_index) const { |
105 DCHECK(child_index < PlatformChildCount()); | 107 DCHECK(child_index < PlatformChildCount()); |
106 BrowserAccessibility* result = nullptr; | 108 BrowserAccessibility* result = nullptr; |
107 | 109 |
108 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { | 110 if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) { |
109 BrowserAccessibilityManager* child_manager = | 111 BrowserAccessibilityManager* child_manager = |
110 BrowserAccessibilityManager::FromID( | 112 BrowserAccessibilityManager::FromID( |
111 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); | 113 GetIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)); |
112 if (child_manager) | 114 if (child_manager) |
113 result = child_manager->GetRoot(); | 115 result = child_manager->GetRoot(); |
114 } else { | 116 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 166 |
165 auto deepest_child = PlatformGetChild(PlatformChildCount() - 1); | 167 auto deepest_child = PlatformGetChild(PlatformChildCount() - 1); |
166 while (deepest_child->PlatformChildCount()) { | 168 while (deepest_child->PlatformChildCount()) { |
167 deepest_child = deepest_child->PlatformGetChild( | 169 deepest_child = deepest_child->PlatformGetChild( |
168 deepest_child->PlatformChildCount() - 1); | 170 deepest_child->PlatformChildCount() - 1); |
169 } | 171 } |
170 | 172 |
171 return deepest_child; | 173 return deepest_child; |
172 } | 174 } |
173 | 175 |
174 uint32 BrowserAccessibility::InternalChildCount() const { | 176 uint32_t BrowserAccessibility::InternalChildCount() const { |
175 if (!node_ || !manager_) | 177 if (!node_ || !manager_) |
176 return 0; | 178 return 0; |
177 return static_cast<uint32>(node_->child_count()); | 179 return static_cast<uint32_t>(node_->child_count()); |
178 } | 180 } |
179 | 181 |
180 BrowserAccessibility* BrowserAccessibility::InternalGetChild( | 182 BrowserAccessibility* BrowserAccessibility::InternalGetChild( |
181 uint32 child_index) const { | 183 uint32_t child_index) const { |
182 if (!node_ || !manager_ || child_index >= InternalChildCount()) | 184 if (!node_ || !manager_ || child_index >= InternalChildCount()) |
183 return nullptr; | 185 return nullptr; |
184 | 186 |
185 const auto child_node = node_->ChildAtIndex(child_index); | 187 const auto child_node = node_->ChildAtIndex(child_index); |
186 DCHECK(child_node); | 188 DCHECK(child_node); |
187 return manager_->GetFromAXNode(child_node); | 189 return manager_->GetFromAXNode(child_node); |
188 } | 190 } |
189 | 191 |
190 BrowserAccessibility* BrowserAccessibility::GetParent() const { | 192 BrowserAccessibility* BrowserAccessibility::GetParent() const { |
191 if (!node_ || !manager_) | 193 if (!node_ || !manager_) |
192 return NULL; | 194 return NULL; |
193 ui::AXNode* parent = node_->parent(); | 195 ui::AXNode* parent = node_->parent(); |
194 if (parent) | 196 if (parent) |
195 return manager_->GetFromAXNode(parent); | 197 return manager_->GetFromAXNode(parent); |
196 | 198 |
197 return manager_->GetParentNodeFromParentTree(); | 199 return manager_->GetParentNodeFromParentTree(); |
198 } | 200 } |
199 | 201 |
200 BrowserAccessibility* BrowserAccessibility::InternalGetParent() const { | 202 BrowserAccessibility* BrowserAccessibility::InternalGetParent() const { |
201 if (!node_ || !manager_) | 203 if (!node_ || !manager_) |
202 return nullptr; | 204 return nullptr; |
203 ui::AXNode* parent = node_->parent(); | 205 ui::AXNode* parent = node_->parent(); |
204 if (parent) | 206 if (parent) |
205 return manager_->GetFromAXNode(parent); | 207 return manager_->GetFromAXNode(parent); |
206 | 208 |
207 return nullptr; | 209 return nullptr; |
208 } | 210 } |
209 | 211 |
210 int32 BrowserAccessibility::GetIndexInParent() const { | 212 int32_t BrowserAccessibility::GetIndexInParent() const { |
211 return node_ ? node_->index_in_parent() : -1; | 213 return node_ ? node_->index_in_parent() : -1; |
212 } | 214 } |
213 | 215 |
214 int32 BrowserAccessibility::GetId() const { | 216 int32_t BrowserAccessibility::GetId() const { |
215 return node_ ? node_->id() : -1; | 217 return node_ ? node_->id() : -1; |
216 } | 218 } |
217 | 219 |
218 const ui::AXNodeData& BrowserAccessibility::GetData() const { | 220 const ui::AXNodeData& BrowserAccessibility::GetData() const { |
219 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ()); | 221 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ()); |
220 if (node_) | 222 if (node_) |
221 return node_->data(); | 223 return node_->data(); |
222 else | 224 else |
223 return empty_data; | 225 return empty_data; |
224 } | 226 } |
225 | 227 |
226 gfx::Rect BrowserAccessibility::GetLocation() const { | 228 gfx::Rect BrowserAccessibility::GetLocation() const { |
227 return GetData().location; | 229 return GetData().location; |
228 } | 230 } |
229 | 231 |
230 int32 BrowserAccessibility::GetRole() const { | 232 int32_t BrowserAccessibility::GetRole() const { |
231 return GetData().role; | 233 return GetData().role; |
232 } | 234 } |
233 | 235 |
234 int32 BrowserAccessibility::GetState() const { | 236 int32_t BrowserAccessibility::GetState() const { |
235 return GetData().state; | 237 return GetData().state; |
236 } | 238 } |
237 | 239 |
238 const BrowserAccessibility::HtmlAttributes& | 240 const BrowserAccessibility::HtmlAttributes& |
239 BrowserAccessibility::GetHtmlAttributes() const { | 241 BrowserAccessibility::GetHtmlAttributes() const { |
240 return GetData().html_attributes; | 242 return GetData().html_attributes; |
241 } | 243 } |
242 | 244 |
243 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { | 245 gfx::Rect BrowserAccessibility::GetLocalBoundsRect() const { |
244 gfx::Rect bounds = GetLocation(); | 246 gfx::Rect bounds = GetLocation(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 302 |
301 int overlap_start = std::max(start, child_start); | 303 int overlap_start = std::max(start, child_start); |
302 int overlap_end = std::min(end, child_end); | 304 int overlap_end = std::min(end, child_end); |
303 | 305 |
304 int local_start = overlap_start - child_start; | 306 int local_start = overlap_start - child_start; |
305 int local_end = overlap_end - child_start; | 307 int local_end = overlap_end - child_start; |
306 | 308 |
307 gfx::Rect child_rect = child->GetLocation(); | 309 gfx::Rect child_rect = child->GetLocation(); |
308 int text_direction = child->GetIntAttribute( | 310 int text_direction = child->GetIntAttribute( |
309 ui::AX_ATTR_TEXT_DIRECTION); | 311 ui::AX_ATTR_TEXT_DIRECTION); |
310 const std::vector<int32>& character_offsets = child->GetIntListAttribute( | 312 const std::vector<int32_t>& character_offsets = |
311 ui::AX_ATTR_CHARACTER_OFFSETS); | 313 child->GetIntListAttribute(ui::AX_ATTR_CHARACTER_OFFSETS); |
312 int start_pixel_offset = | 314 int start_pixel_offset = |
313 local_start > 0 ? character_offsets[local_start - 1] : 0; | 315 local_start > 0 ? character_offsets[local_start - 1] : 0; |
314 int end_pixel_offset = | 316 int end_pixel_offset = |
315 local_end > 0 ? character_offsets[local_end - 1] : 0; | 317 local_end > 0 ? character_offsets[local_end - 1] : 0; |
316 | 318 |
317 gfx::Rect child_overlap_rect; | 319 gfx::Rect child_overlap_rect; |
318 switch (text_direction) { | 320 switch (text_direction) { |
319 case ui::AX_TEXT_DIRECTION_NONE: | 321 case ui::AX_TEXT_DIRECTION_NONE: |
320 case ui::AX_TEXT_DIRECTION_LTR: { | 322 case ui::AX_TEXT_DIRECTION_LTR: { |
321 int left = child_rect.x() + start_pixel_offset; | 323 int left = child_rect.x() + start_pixel_offset; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 for (size_t i = 0; i < InternalChildCount(); ++i) { | 395 for (size_t i = 0; i < InternalChildCount(); ++i) { |
394 // The next child starts where the previous one ended. | 396 // The next child starts where the previous one ended. |
395 child_start = child_end; | 397 child_start = child_end; |
396 BrowserAccessibility* child = InternalGetChild(i); | 398 BrowserAccessibility* child = InternalGetChild(i); |
397 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX); | 399 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX); |
398 const std::string& child_text = child->GetStringAttribute( | 400 const std::string& child_text = child->GetStringAttribute( |
399 ui::AX_ATTR_NAME); | 401 ui::AX_ATTR_NAME); |
400 int child_len = static_cast<int>(child_text.size()); | 402 int child_len = static_cast<int>(child_text.size()); |
401 child_end += child_len; // End is one past the last character. | 403 child_end += child_len; // End is one past the last character. |
402 | 404 |
403 const std::vector<int32>& word_starts = child->GetIntListAttribute( | 405 const std::vector<int32_t>& word_starts = |
404 ui::AX_ATTR_WORD_STARTS); | 406 child->GetIntListAttribute(ui::AX_ATTR_WORD_STARTS); |
405 if (word_starts.empty()) { | 407 if (word_starts.empty()) { |
406 word_start = child_end; | 408 word_start = child_end; |
407 continue; | 409 continue; |
408 } | 410 } |
409 | 411 |
410 int local_start = start - child_start; | 412 int local_start = start - child_start; |
411 std::vector<int32>::const_iterator iter = std::upper_bound( | 413 std::vector<int32_t>::const_iterator iter = std::upper_bound( |
412 word_starts.begin(), word_starts.end(), local_start); | 414 word_starts.begin(), word_starts.end(), local_start); |
413 if (iter != word_starts.end()) { | 415 if (iter != word_starts.end()) { |
414 if (direction == ui::FORWARDS_DIRECTION) { | 416 if (direction == ui::FORWARDS_DIRECTION) { |
415 word_start = child_start + *iter; | 417 word_start = child_start + *iter; |
416 } else if (direction == ui::BACKWARDS_DIRECTION) { | 418 } else if (direction == ui::BACKWARDS_DIRECTION) { |
417 if (iter == word_starts.begin()) { | 419 if (iter == word_starts.begin()) { |
418 // Return the position of the last word in the previous child. | 420 // Return the position of the last word in the previous child. |
419 word_start = prev_word_start; | 421 word_start = prev_word_start; |
420 } else { | 422 } else { |
421 word_start = child_start + *(iter - 1); | 423 word_start = child_start + *(iter - 1); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 ui::AXStringAttribute attribute, | 606 ui::AXStringAttribute attribute, |
605 base::string16* value) const { | 607 base::string16* value) const { |
606 return GetData().GetString16Attribute(attribute, value); | 608 return GetData().GetString16Attribute(attribute, value); |
607 } | 609 } |
608 | 610 |
609 bool BrowserAccessibility::HasIntListAttribute( | 611 bool BrowserAccessibility::HasIntListAttribute( |
610 ui::AXIntListAttribute attribute) const { | 612 ui::AXIntListAttribute attribute) const { |
611 return GetData().HasIntListAttribute(attribute); | 613 return GetData().HasIntListAttribute(attribute); |
612 } | 614 } |
613 | 615 |
614 const std::vector<int32>& BrowserAccessibility::GetIntListAttribute( | 616 const std::vector<int32_t>& BrowserAccessibility::GetIntListAttribute( |
615 ui::AXIntListAttribute attribute) const { | 617 ui::AXIntListAttribute attribute) const { |
616 return GetData().GetIntListAttribute(attribute); | 618 return GetData().GetIntListAttribute(attribute); |
617 } | 619 } |
618 | 620 |
619 bool BrowserAccessibility::GetIntListAttribute( | 621 bool BrowserAccessibility::GetIntListAttribute( |
620 ui::AXIntListAttribute attribute, | 622 ui::AXIntListAttribute attribute, |
621 std::vector<int32>* value) const { | 623 std::vector<int32_t>* value) const { |
622 return GetData().GetIntListAttribute(attribute, value); | 624 return GetData().GetIntListAttribute(attribute, value); |
623 } | 625 } |
624 | 626 |
625 bool BrowserAccessibility::GetHtmlAttribute( | 627 bool BrowserAccessibility::GetHtmlAttribute( |
626 const char* html_attr, std::string* value) const { | 628 const char* html_attr, std::string* value) const { |
627 return GetData().GetHtmlAttribute(html_attr, value); | 629 return GetData().GetHtmlAttribute(html_attr, value); |
628 } | 630 } |
629 | 631 |
630 bool BrowserAccessibility::GetHtmlAttribute( | 632 bool BrowserAccessibility::GetHtmlAttribute( |
631 const char* html_attr, base::string16* value) const { | 633 const char* html_attr, base::string16* value) const { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 } | 670 } |
669 | 671 |
670 bool BrowserAccessibility::HasCaret() const { | 672 bool BrowserAccessibility::HasCaret() const { |
671 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && | 673 if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) && |
672 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_START) && | 674 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_START) && |
673 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_END)) { | 675 HasIntAttribute(ui::AX_ATTR_TEXT_SEL_END)) { |
674 return true; | 676 return true; |
675 } | 677 } |
676 | 678 |
677 // The caret is always at the focus of the selection. | 679 // The caret is always at the focus of the selection. |
678 int32 focus_id = manager()->GetTreeData().sel_focus_object_id; | 680 int32_t focus_id = manager()->GetTreeData().sel_focus_object_id; |
679 BrowserAccessibility* focus_object = manager()->GetFromID(focus_id); | 681 BrowserAccessibility* focus_object = manager()->GetFromID(focus_id); |
680 if (!focus_object) | 682 if (!focus_object) |
681 return false; | 683 return false; |
682 | 684 |
683 if (!focus_object->IsDescendantOf(this)) | 685 if (!focus_object->IsDescendantOf(this)) |
684 return false; | 686 return false; |
685 | 687 |
686 return true; | 688 return true; |
687 } | 689 } |
688 | 690 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 } | 856 } |
855 need_to_offset_web_area = true; | 857 need_to_offset_web_area = true; |
856 } | 858 } |
857 parent = parent->GetParent(); | 859 parent = parent->GetParent(); |
858 } | 860 } |
859 | 861 |
860 return bounds; | 862 return bounds; |
861 } | 863 } |
862 | 864 |
863 } // namespace content | 865 } // namespace content |
OLD | NEW |