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

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

Issue 1951353002: Fixed a bug that assumed that static text object span only one line (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 value = GetInnerText(); 514 value = GetInnerText();
515 return value; 515 return value;
516 } 516 }
517 517
518 int BrowserAccessibility::GetLineStartBoundary( 518 int BrowserAccessibility::GetLineStartBoundary(
519 int start, 519 int start,
520 ui::TextBoundaryDirection direction) const { 520 ui::TextBoundaryDirection direction) const {
521 DCHECK_GE(start, 0); 521 DCHECK_GE(start, 0);
522 DCHECK_LE(start, static_cast<int>(GetText().length())); 522 DCHECK_LE(start, static_cast<int>(GetText().length()));
523 523
524 if (IsSimpleTextControl()) { 524 // Standard text fields such as textarea have an embedded div inside them that
525 const std::vector<int32_t>& line_breaks = 525 // holds all the text.
526 GetIntListAttribute(ui::AX_ATTR_LINE_BREAKS); 526 if (IsSimpleTextControl() && InternalChildCount() == 1)
dmazzoni 2016/05/05 18:35:04 Why doesn't it work if you just delete this if sta
527 return ui::FindAccessibleTextBoundary(GetText(), line_breaks, 527 return InternalGetChild(0)->GetLineStartBoundary(start, direction);
528 ui::LINE_BOUNDARY, start, direction);
529 }
530 528
531 // Keeps track of the start offset of each consecutive line. 529 // Keeps track of the start offset of each consecutive line.
532 int line_start = 0; 530 int line_start = 0;
533 // Keeps track of the length of each consecutive line. 531 // Keeps track of the length of each consecutive line.
534 int line_length = 0; 532 int line_length = 0;
535 for (size_t i = 0; i < InternalChildCount(); ++i) { 533 for (size_t i = 0; i < InternalChildCount(); ++i) {
536 const BrowserAccessibility* child = InternalGetChild(i); 534 const BrowserAccessibility* child = InternalGetChild(i);
537 DCHECK(child); 535 DCHECK(child);
538 // Child objects are of length one, since they are represented by a 536 // Child objects are of length one, since they are represented by a
539 // single embedded object character. The exception is text-only objects. 537 // single embedded object character. The exception is text-only objects.
540 int child_length = 1; 538 int child_length = 1;
541 if (child->IsTextOnlyObject()) 539 if (child->IsTextOnlyObject())
542 child_length = static_cast<int>(child->GetText().length()); 540 child_length = static_cast<int>(child->GetText().length());
543 line_length += child_length; 541 line_length += child_length;
544 start -= child_length;
545 542
546 // Stop when we reach both the object containing our start offset and the 543 // Stop when we reach both the child containing our start offset and the
547 // end of the line on which this object is located. 544 // child that is at the end of the line on which this object is located.
548 if (start < 0 && !child->IsNextSiblingOnSameLine()) 545 if (start < child_length && !child->IsNextSiblingOnSameLine()) {
546 // Recurse into the inline text boxes.
547 if (child->GetRole() == ui::AX_ROLE_STATIC_TEXT)
548 return line_start + child->GetLineStartBoundary(start, direction);
549
550 // There are no inline text boxes to look at.
549 break; 551 break;
552 }
550 553
551 if (!child->IsNextSiblingOnSameLine()) { 554 if (!child->IsNextSiblingOnSameLine()) {
552 line_start += line_length; 555 line_start += line_length;
553 line_length = 0; 556 line_length = 0;
554 } 557 }
558 start -= child_length;
555 } 559 }
556 560
557 int result = 0;
558 switch (direction) { 561 switch (direction) {
559 case ui::FORWARDS_DIRECTION: 562 case ui::FORWARDS_DIRECTION:
560 result = line_start + line_length; 563 return line_start + line_length;
561 break;
562 case ui::BACKWARDS_DIRECTION: 564 case ui::BACKWARDS_DIRECTION:
563 result = line_start; 565 return line_start;
564 break;
565 default:
566 NOTREACHED();
567 } 566 }
568 return result; 567 NOTREACHED();
568 return 0;
569 } 569 }
570 570
571 int BrowserAccessibility::GetWordStartBoundary( 571 int BrowserAccessibility::GetWordStartBoundary(
572 int start, ui::TextBoundaryDirection direction) const { 572 int start, ui::TextBoundaryDirection direction) const {
573 DCHECK_GE(start, -1); 573 DCHECK_GE(start, -1);
574 // Special offset that indicates that a word boundary has not been found. 574 // Special offset that indicates that a word boundary has not been found.
575 int word_start_not_found = static_cast<int>(GetText().size()); 575 int word_start_not_found = static_cast<int>(GetText().size());
576 int word_start = word_start_not_found; 576 int word_start = word_start_not_found;
577 577
578 switch (GetRole()) { 578 switch (GetRole()) {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 break; 1168 break;
1169 1169
1170 manager = root->GetParent()->manager(); 1170 manager = root->GetParent()->manager();
1171 root = manager->GetRoot(); 1171 root = manager->GetRoot();
1172 } 1172 }
1173 1173
1174 return bounds; 1174 return bounds;
1175 } 1175 }
1176 1176
1177 } // namespace content 1177 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698