Index: content/browser/accessibility/browser_accessibility_win.cc |
diff --git a/content/browser/accessibility/browser_accessibility_win.cc b/content/browser/accessibility/browser_accessibility_win.cc |
index 397214b5546706ee0797775eec316226fef888af..dc9307007268028fa17551f034c888fe1bfd7c82 100644 |
--- a/content/browser/accessibility/browser_accessibility_win.cc |
+++ b/content/browser/accessibility/browser_accessibility_win.cc |
@@ -6,6 +6,7 @@ |
#include <UIAutomationClient.h> |
#include <UIAutomationCoreApi.h> |
+#include <algorithm> |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_split.h" |
@@ -3297,6 +3298,9 @@ LONG BrowserAccessibilityWin::FindBoundary( |
IA2TextBoundaryType ia2_boundary, |
LONG start_offset, |
ui::TextBoundaryDirection direction) { |
+ if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD) |
+ return FindWordStartBoundary(text, start_offset, direction); |
+ |
HandleSpecialTextOffset(text, &start_offset); |
ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); |
const std::vector<int32>& line_breaks = GetIntListAttribute( |
@@ -3305,6 +3309,75 @@ LONG BrowserAccessibilityWin::FindBoundary( |
text, line_breaks, boundary, start_offset, direction); |
} |
+LONG BrowserAccessibilityWin::FindWordStartBoundary( |
dmazzoni
2014/10/15 22:03:10
Please move this to browser_accessibility.cc inste
|
+ const base::string16& text, |
+ LONG start_offset, |
+ ui::TextBoundaryDirection direction) { |
+ HandleSpecialTextOffset(text, &start_offset); |
+ if (!IsEditableText()) { |
+ // We don't actually need the line breaks. |
+ const std::vector<int32> line_breaks; |
+ return ui::FindAccessibleTextBoundary( |
+ text, line_breaks, ui::WORD_START_BOUNDARY, start_offset, direction); |
+ } |
+ |
+ LONG word_start = 0; |
+ LONG child_start = 0; |
+ LONG child_end = 0; |
+ |
+ for (size_t i = 0; i < InternalChildCount(); ++i) { |
+ // The next child starts where the previous one ended. |
+ child_start = child_end; |
+ BrowserAccessibilityWin* child = InternalGetChild( |
+ i)->ToBrowserAccessibilityWin(); |
+ DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX); |
+ const base::string16& child_text = child->TextForIAccessibleText(); |
+ LONG child_len = static_cast<LONG>(child_text.length()); |
+ child_end += child_len; // End is one passed the last character. |
+ |
+ if (start_offset >= child_end) |
+ continue; |
+ |
+ const std::vector<int32>& word_starts = child->GetIntListAttribute( |
+ ui::AX_ATTR_WORD_STARTS); |
+ if (!word_starts.empty()) { |
dmazzoni
2014/10/15 22:03:10
When possible, reverse the direction of a test to
|
+ int local_start = static_cast<int32>(start_offset, child_start); |
+ if (direction == ui::FORWARDS_DIRECTION) { |
+ std::vector<int32>::const_iterator iter = std::upper_bound( |
+ word_starts.cbegin(), word_starts.cend(), local_start); |
+ 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) { |
+ std::vector<int32>::const_iterator iter = std::lower_bound( |
+ word_starts.cbegin(), word_starts.cend(), local_start); |
+ if (iter != word_starts.cbegin() { |
+ --iter; |
+ word_start = *iter; |
+ break; |
+ } else { |
+ // Return the start of the last word in the previous child. |
+ for (int j = i - 1; j >= 0; --j) { |
+ child = InternalGetChild(j).ToBrowserAccessibilityWin(); |
+ word_starts = child->GetIntListAttribute(ui::AX_ATTR_WORD_STARTS); |
+ if (!word_starts.empty()) |
+ word_start = word_starts[word_starts.length() - 1]; |
+ } |
+ break; |
+ } |
+ } |
+ } |
+ } |
+ |
+ return word_start; |
+} |
+ |
BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32 id) { |
return manager()->GetFromID(id)->ToBrowserAccessibilityWin(); |
} |