| Index: content/browser/accessibility/browser_accessibility.cc
|
| diff --git a/content/browser/accessibility/browser_accessibility.cc b/content/browser/accessibility/browser_accessibility.cc
|
| index a700e9a9fd30538f4703fdf92d837a50058eb2c0..a2c4c681881b4e45d731700f6d641cbbad7e0e0a 100644
|
| --- a/content/browser/accessibility/browser_accessibility.cc
|
| +++ b/content/browser/accessibility/browser_accessibility.cc
|
| @@ -4,12 +4,15 @@
|
|
|
| #include "content/browser/accessibility/browser_accessibility.h"
|
|
|
| +#include <algorithm>
|
| +
|
| #include "base/logging.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "content/browser/accessibility/browser_accessibility_manager.h"
|
| #include "content/common/accessibility_messages.h"
|
| +#include "ui/accessibility/ax_text_utils.h"
|
|
|
| namespace content {
|
|
|
| @@ -337,6 +340,81 @@ gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len)
|
| return bounds;
|
| }
|
|
|
| +int BrowserAccessibility::GetWordStartBoundary(
|
| + int start, ui::TextBoundaryDirection direction) const {
|
| + int word_start = 0;
|
| + if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
|
| + for (size_t i = 0; i < InternalChildCount() && start >= 0; ++i) {
|
| + BrowserAccessibility* child = InternalGetChild(i);
|
| + int child_len = child->GetStaticTextLenRecursive();
|
| + if (start >= child_len) {
|
| + word_start += child_len;
|
| + start -= child_len;
|
| + continue;
|
| + }
|
| +
|
| + word_start = child->GetWordStartBoundary(start, direction);
|
| + }
|
| + return word_start;
|
| + }
|
| +
|
| + int child_start = 0;
|
| + int child_end = 0;
|
| +
|
| + for (size_t i = 0; i < InternalChildCount(); ++i) {
|
| + // The next child starts where the previous one ended.
|
| + child_start = child_end;
|
| + BrowserAccessibility* child = InternalGetChild(i);
|
| + DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
|
| + std::string child_text;
|
| + child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text);
|
| + int child_len = static_cast<int>(child_text.size());
|
| + child_end += child_len; // End is one past the last character.
|
| +
|
| + if (start >= child_end)
|
| + continue;
|
| +
|
| + const std::vector<int32>& word_starts = child->GetIntListAttribute(
|
| + ui::AX_ATTR_WORD_STARTS);
|
| + if (word_starts.empty())
|
| + continue;
|
| +
|
| + int local_start = start - child_start;
|
| + std::vector<int32>::const_iterator iter = std::upper_bound(
|
| + word_starts.cbegin(), word_starts.cend(), local_start);
|
| + if (direction == ui::FORWARDS_DIRECTION) {
|
| + if (iter != word_starts.cend()) {
|
| + word_start = *iter;
|
| + break;
|
| + } else {
|
| + // In case there are no more children or remaining children have no
|
| + // text, e.g., an image.
|
| + word_start = child_end;
|
| + continue;
|
| + }
|
| + } else if (direction == ui::BACKWARDS_DIRECTION) {
|
| + if (iter != word_starts.cbegin()) {
|
| + --iter;
|
| + word_start = *iter;
|
| + } else {
|
| + // Return the start of the last word in the previous child.
|
| + for (int j = i - 1; j >= 0; --j) {
|
| + BrowserAccessibility* child = InternalGetChild(j);
|
| + const std::vector<int32>& word_starts = child->GetIntListAttribute(
|
| + ui::AX_ATTR_WORD_STARTS);
|
| + if (word_starts.empty())
|
| + continue;
|
| +
|
| + word_start = word_starts[word_starts.size() - 1];
|
| + }
|
| + }
|
| + break;
|
| + }
|
| + }
|
| +
|
| + return word_start;
|
| +}
|
| +
|
| BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint(
|
| const gfx::Point& point) {
|
| // The best result found that's a child of this object.
|
|
|