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

Unified Diff: content/browser/accessibility/browser_accessibility.cc

Issue 660633002: Fixed IAccessibleText::TextAtOffset with IA2_TEXT_BOUNDARY_WORD to return text that spans from the … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Broke up different boundary tests in their own test cases. Created 6 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 side-by-side diff with in-line comments
Download patch
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..427f83e71f57aa66071faccc84ffbdb209b5d546 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,87 @@ gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len)
return bounds;
}
+int BrowserAccessibility::GetWordStartBoundary(
dmazzoni 2014/11/17 19:06:46 A few more comments in this function please?
+ int start, ui::TextBoundaryDirection direction) const {
+ int prev_word_start = 0;
+ int word_start = 0;
+ DLOG(INFO) << "Original start = " << start;
+ if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
+ for (size_t i = 0; i < InternalChildCount(); ++i) {
+ BrowserAccessibility* child = InternalGetChild(i);
+ int child_len = child->GetStaticTextLenRecursive();
+ DLOG(INFO) << "child_len = " << child_len;
+ int child_word_start = child->GetWordStartBoundary(start, direction);
+ word_start += child_word_start;
+ if (child_word_start != child_len)
+ break;
+ const std::vector<int32>& lines = child->GetIntListAttribute(
dmazzoni 2014/11/17 19:06:46 I think you can get rid of the line break search,
+ ui::AX_ATTR_LINE_BREAKS);
+ for (size_t l = 0; l < lines.size(); ++l) {
+ DLOG(INFO) << "Line breaks " << l << " = " << lines[l];
+ }
+ std::vector<int32>::const_iterator iter = std::find(
+ lines.cbegin(), lines.cend(), word_start);
+ if (iter != lines.cend()) {
+ child_len += 1;
+ word_start += 1;
+ DLOG(INFO) << "Found line break = " << word_start;
+ }
+ start -= child_len;
+ }
+ 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.
+ DLOG(INFO) << "child_start = " << child_start << " child_end " << child_end;
+
+ const std::vector<int32>& word_starts = child->GetIntListAttribute(
+ ui::AX_ATTR_WORD_STARTS);
+ if (word_starts.empty()) {
+ word_start = child_end;
+ continue;
+ }
+ DLOG(INFO) << "First word at = " << word_starts[0];
+ DLOG(INFO) << "Text = " << child_text;
+
+ int local_start = start - child_start;
dmazzoni 2014/11/17 19:06:46 nit: indentation
+ std::vector<int32>::const_iterator iter = std::upper_bound(
+ word_starts.cbegin(), word_starts.cend(), local_start);
+ if (iter != word_starts.cend()) {
+ if (direction == ui::FORWARDS_DIRECTION) {
+ word_start = child_start + *iter;
+ DLOG(INFO) << "Forward found at word_start = " << word_start;
+ } else if (direction == ui::BACKWARDS_DIRECTION) {
+ if (iter == word_starts.cbegin()) {
+ // Return the position of the last word in the previous child.
+ word_start = prev_word_start;
+ DLOG(INFO) << "Backward prev at word_start = " << word_start;
+ } else {
+ word_start = child_start + *(iter - 1);
+ DLOG(INFO) << "Backward at word_start = " << word_start;
+ }
+ }
+ break;
+ }
+ prev_word_start = *(iter - 1);
+ word_start = child_end;
+ DLOG(INFO) << "Not found at word_start = " << word_start;
+ }
+
+ DLOG(INFO) << "Final value word_start = " << word_start;
+ return word_start;
+}
+
BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint(
const gfx::Point& point) {
// The best result found that's a child of this object.

Powered by Google App Engine
This is Rietveld 408576698