| 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> | 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 Loading... |
| 514 // Some screen readers like Jaws and older versions of VoiceOver require a | 514 // Some screen readers like Jaws and older versions of VoiceOver require a |
| 515 // value to be set in text fields with rich content, even though the same | 515 // value to be set in text fields with rich content, even though the same |
| 516 // information is available on the children. | 516 // information is available on the children. |
| 517 if (value.empty() && (IsSimpleTextControl() || IsRichTextControl())) | 517 if (value.empty() && (IsSimpleTextControl() || IsRichTextControl())) |
| 518 value = GetInnerText(); | 518 value = GetInnerText(); |
| 519 return value; | 519 return value; |
| 520 } | 520 } |
| 521 | 521 |
| 522 int BrowserAccessibility::GetLineStartBoundary( | 522 int BrowserAccessibility::GetLineStartBoundary( |
| 523 int start, | 523 int start, |
| 524 ui::TextBoundaryDirection direction) const { | 524 ui::TextBoundaryDirection direction, |
| 525 ui::AXTextAffinity affinity) const { |
| 525 DCHECK_GE(start, 0); | 526 DCHECK_GE(start, 0); |
| 526 DCHECK_LE(start, static_cast<int>(GetText().length())); | 527 DCHECK_LE(start, static_cast<int>(GetText().length())); |
| 527 | 528 |
| 528 if (IsSimpleTextControl()) { | 529 if (IsSimpleTextControl()) { |
| 529 const std::vector<int32_t>& line_breaks = | 530 const std::vector<int32_t>& line_breaks = |
| 530 GetIntListAttribute(ui::AX_ATTR_LINE_BREAKS); | 531 GetIntListAttribute(ui::AX_ATTR_LINE_BREAKS); |
| 531 return ui::FindAccessibleTextBoundary(GetText(), line_breaks, | 532 return ui::FindAccessibleTextBoundary(GetText(), line_breaks, |
| 532 ui::LINE_BOUNDARY, start, direction); | 533 ui::LINE_BOUNDARY, start, direction, |
| 534 affinity); |
| 533 } | 535 } |
| 534 | 536 |
| 535 // Keeps track of the start offset of each consecutive line. | 537 // Keeps track of the start offset of each consecutive line. |
| 536 int line_start = 0; | 538 int line_start = 0; |
| 537 // Keeps track of the length of each consecutive line. | 539 // Keeps track of the length of each consecutive line. |
| 538 int line_length = 0; | 540 int line_length = 0; |
| 539 for (size_t i = 0; i < InternalChildCount(); ++i) { | 541 for (size_t i = 0; i < InternalChildCount(); ++i) { |
| 540 const BrowserAccessibility* child = InternalGetChild(i); | 542 const BrowserAccessibility* child = InternalGetChild(i); |
| 541 DCHECK(child); | 543 DCHECK(child); |
| 542 // Child objects are of length one, since they are represented by a | 544 // Child objects are of length one, since they are represented by a |
| 543 // single embedded object character. The exception is text-only objects. | 545 // single embedded object character. The exception is text-only objects. |
| 544 int child_length = 1; | 546 int child_length = 1; |
| 545 if (child->IsTextOnlyObject()) | 547 if (child->IsTextOnlyObject()) |
| 546 child_length = static_cast<int>(child->GetText().length()); | 548 child_length = static_cast<int>(child->GetText().length()); |
| 547 | 549 |
| 550 // Determine if |start| is within this child. As a special case, if |
| 551 // the affinity is upstream, then the cursor position between two |
| 552 // lines belongs to the previous line. |
| 553 bool start_index_within_child = start < child_length; |
| 554 if (start == child_length && |
| 555 !child->IsNextSiblingOnSameLine() && |
| 556 affinity == ui::AX_TEXT_AFFINITY_UPSTREAM) { |
| 557 start_index_within_child = true; |
| 558 } |
| 559 |
| 548 // Stop when we reach both the child containing our start offset and, in | 560 // Stop when we reach both the child containing our start offset and, in |
| 549 // case we are searching forward, the child that is at the end of the line | 561 // case we are searching forward, the child that is at the end of the line |
| 550 // on which this object is located. | 562 // on which this object is located. |
| 551 if (start < child_length && (direction == ui::BACKWARDS_DIRECTION || | 563 if (start_index_within_child && (direction == ui::BACKWARDS_DIRECTION || |
| 552 !child->IsNextSiblingOnSameLine())) { | 564 !child->IsNextSiblingOnSameLine())) { |
| 553 // Recurse into the inline text boxes. | 565 // Recurse into the inline text boxes. |
| 554 if (child->GetRole() == ui::AX_ROLE_STATIC_TEXT) { | 566 if (child->GetRole() == ui::AX_ROLE_STATIC_TEXT) { |
| 555 switch (direction) { | 567 switch (direction) { |
| 556 case ui::FORWARDS_DIRECTION: | 568 case ui::FORWARDS_DIRECTION: |
| 557 line_length += | 569 line_length += child->GetLineStartBoundary( |
| 558 child->GetLineStartBoundary(std::max(start, 0), direction); | 570 std::max(start, 0), direction, affinity); |
| 559 break; | 571 break; |
| 560 case ui::BACKWARDS_DIRECTION: | 572 case ui::BACKWARDS_DIRECTION: |
| 561 line_start += | 573 line_start += child->GetLineStartBoundary( |
| 562 child->GetLineStartBoundary(std::max(start, 0), direction); | 574 std::max(start, 0), direction, affinity); |
| 563 break; | 575 break; |
| 564 } | 576 } |
| 565 } else { | 577 } else { |
| 566 line_length += child_length; | 578 line_length += child_length; |
| 567 } | 579 } |
| 568 | 580 |
| 569 break; | 581 break; |
| 570 } | 582 } |
| 571 line_length += child_length; | 583 line_length += child_length; |
| 572 | 584 |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 break; | 1216 break; |
| 1205 | 1217 |
| 1206 manager = root->GetParent()->manager(); | 1218 manager = root->GetParent()->manager(); |
| 1207 root = manager->GetRoot(); | 1219 root = manager->GetRoot(); |
| 1208 } | 1220 } |
| 1209 | 1221 |
| 1210 return bounds; | 1222 return bounds; |
| 1211 } | 1223 } |
| 1212 | 1224 |
| 1213 } // namespace content | 1225 } // namespace content |
| OLD | NEW |