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

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

Issue 1435113003: Make use of new AX name calc in Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issue with ariaTextAlternative Created 5 years, 1 month 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) 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 gfx::Rect bounds; 263 gfx::Rect bounds;
264 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) { 264 for (size_t i = 0; i < InternalChildCount() && child_end < start + len; ++i) {
265 BrowserAccessibility* child = InternalGetChild(i); 265 BrowserAccessibility* child = InternalGetChild(i);
266 if (child->GetRole() != ui::AX_ROLE_INLINE_TEXT_BOX) { 266 if (child->GetRole() != ui::AX_ROLE_INLINE_TEXT_BOX) {
267 DLOG(WARNING) << "BrowserAccessibility objects with role STATIC_TEXT " << 267 DLOG(WARNING) << "BrowserAccessibility objects with role STATIC_TEXT " <<
268 "should have children of role INLINE_TEXT_BOX."; 268 "should have children of role INLINE_TEXT_BOX.";
269 continue; 269 continue;
270 } 270 }
271 271
272 std::string child_text; 272 std::string child_text;
273 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text); 273 child->GetStringAttribute(ui::AX_ATTR_NAME, &child_text);
274 int child_len = static_cast<int>(child_text.size()); 274 int child_len = static_cast<int>(child_text.size());
275 child_start = child_end; 275 child_start = child_end;
276 child_end += child_len; 276 child_end += child_len;
277 277
278 if (child_end < start) 278 if (child_end < start)
279 continue; 279 continue;
280 280
281 int overlap_start = std::max(start, child_start); 281 int overlap_start = std::max(start, child_start);
282 int overlap_end = std::min(end, child_end); 282 int overlap_end = std::min(end, child_end);
283 283
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 int child_start = 0; 362 int child_start = 0;
363 int child_end = 0; 363 int child_end = 0;
364 364
365 // Go through the inline text boxes. 365 // Go through the inline text boxes.
366 for (size_t i = 0; i < InternalChildCount(); ++i) { 366 for (size_t i = 0; i < InternalChildCount(); ++i) {
367 // The next child starts where the previous one ended. 367 // The next child starts where the previous one ended.
368 child_start = child_end; 368 child_start = child_end;
369 BrowserAccessibility* child = InternalGetChild(i); 369 BrowserAccessibility* child = InternalGetChild(i);
370 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX); 370 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
371 const std::string& child_text = child->GetStringAttribute( 371 const std::string& child_text = child->GetStringAttribute(
372 ui::AX_ATTR_VALUE); 372 ui::AX_ATTR_NAME);
373 int child_len = static_cast<int>(child_text.size()); 373 int child_len = static_cast<int>(child_text.size());
374 child_end += child_len; // End is one past the last character. 374 child_end += child_len; // End is one past the last character.
375 375
376 const std::vector<int32>& word_starts = child->GetIntListAttribute( 376 const std::vector<int32>& word_starts = child->GetIntListAttribute(
377 ui::AX_ATTR_WORD_STARTS); 377 ui::AX_ATTR_WORD_STARTS);
378 if (word_starts.empty()) { 378 if (word_starts.empty()) {
379 word_start = child_end; 379 word_start = child_end;
380 continue; 380 continue;
381 } 381 }
382 382
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 switch (GetRole()) { 718 switch (GetRole()) {
719 case ui::AX_ROLE_COMBO_BOX: 719 case ui::AX_ROLE_COMBO_BOX:
720 case ui::AX_ROLE_SEARCH_BOX: 720 case ui::AX_ROLE_SEARCH_BOX:
721 case ui::AX_ROLE_TEXT_FIELD: 721 case ui::AX_ROLE_TEXT_FIELD:
722 return true; 722 return true;
723 default: 723 default:
724 return false; 724 return false;
725 } 725 }
726 } 726 }
727 727
728 std::string BrowserAccessibility::ComputeAccessibleNameFromDescendants() {
729 std::string name;
730 for (size_t i = 0; i < InternalChildCount(); ++i) {
731 BrowserAccessibility* child = InternalGetChild(i);
732 std::string child_name;
733 if (child->GetStringAttribute(ui::AX_ATTR_NAME, &child_name)) {
734 if (!name.empty())
735 name += " ";
736 name += child_name;
737 } else if (!child->HasState(ui::AX_STATE_FOCUSABLE)) {
738 child_name = child->ComputeAccessibleNameFromDescendants();
739 if (!child_name.empty()) {
740 if (!name.empty())
741 name += " ";
742 name += child_name;
743 }
744 }
745 }
746
747 return name;
748 }
749
728 int BrowserAccessibility::GetStaticTextLenRecursive() const { 750 int BrowserAccessibility::GetStaticTextLenRecursive() const {
729 if (GetRole() == ui::AX_ROLE_STATIC_TEXT || 751 if (GetRole() == ui::AX_ROLE_STATIC_TEXT ||
730 GetRole() == ui::AX_ROLE_LINE_BREAK) { 752 GetRole() == ui::AX_ROLE_LINE_BREAK) {
731 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_VALUE).size()); 753 return static_cast<int>(GetStringAttribute(ui::AX_ATTR_NAME).size());
732 } 754 }
733 755
734 int len = 0; 756 int len = 0;
735 for (size_t i = 0; i < InternalChildCount(); ++i) 757 for (size_t i = 0; i < InternalChildCount(); ++i)
736 len += InternalGetChild(i)->GetStaticTextLenRecursive(); 758 len += InternalGetChild(i)->GetStaticTextLenRecursive();
737 return len; 759 return len;
738 } 760 }
739 761
740 void BrowserAccessibility::FixEmptyBounds(gfx::Rect* bounds) const 762 void BrowserAccessibility::FixEmptyBounds(gfx::Rect* bounds) const
741 { 763 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 819 }
798 need_to_offset_web_area = true; 820 need_to_offset_web_area = true;
799 } 821 }
800 parent = parent->GetParent(); 822 parent = parent->GetParent();
801 } 823 }
802 824
803 return bounds; 825 return bounds;
804 } 826 }
805 827
806 } // namespace content 828 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility.h ('k') | content/browser/accessibility/browser_accessibility_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698