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

Side by Side 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: Moved manual test changes to another branch. Created 5 years, 10 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
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 <algorithm>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/accessibility/browser_accessibility_manager.h" 13 #include "content/browser/accessibility/browser_accessibility_manager.h"
12 #include "content/common/accessibility_messages.h" 14 #include "content/common/accessibility_messages.h"
15 #include "ui/accessibility/ax_text_utils.h"
13 16
14 namespace content { 17 namespace content {
15 18
16 #if !defined(OS_MACOSX) && \ 19 #if !defined(OS_MACOSX) && \
17 !defined(OS_WIN) && \ 20 !defined(OS_WIN) && \
18 !defined(OS_ANDROID) 21 !defined(OS_ANDROID)
19 // We have subclassess of BrowserAccessibility on Mac and Win. For any other 22 // We have subclassess of BrowserAccessibility on Mac and Win. For any other
20 // platform, instantiate the base class. 23 // platform, instantiate the base class.
21 // static 24 // static
22 BrowserAccessibility* BrowserAccessibility::Create() { 25 BrowserAccessibility* BrowserAccessibility::Create() {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 const { 303 const {
301 gfx::Rect bounds = GetLocalBoundsForRange(start, len); 304 gfx::Rect bounds = GetLocalBoundsForRange(start, len);
302 305
303 // Adjust the bounds by the top left corner of the containing view's bounds 306 // Adjust the bounds by the top left corner of the containing view's bounds
304 // in screen coordinates. 307 // in screen coordinates.
305 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); 308 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
306 309
307 return bounds; 310 return bounds;
308 } 311 }
309 312
313 int BrowserAccessibility::GetWordStartBoundary(
314 int start, ui::TextBoundaryDirection direction) const {
315 int prev_word_start = 0;
316 int word_start = 0;
317 if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
318 int prev_child_y = -1;
319 for (size_t i = 0; i < InternalChildCount(); ++i) {
320 BrowserAccessibility* child = InternalGetChild(i);
321 int child_len = child->GetStaticTextLenRecursive();
322 int child_word_start = child->GetWordStartBoundary(start, direction);
323 word_start += child_word_start;
324 if (child_word_start != child_len)
325 break;
326 gfx::Rect child_rect = child->GetLocation();
327 int child_y = child_rect.y();
328 if (prev_child_y == -1)
329 prev_child_y = child_y;
330 if (prev_child_y != child_y) {
331 child_len += 1;
332 word_start += 1;
333 prev_child_y = child_y;
334 }
335 start -= child_len;
336 }
337 return word_start;
338 }
339
340 int child_start = 0;
341 int child_end = 0;
342 for (size_t i = 0; i < InternalChildCount(); ++i) {
343 // The next child starts where the previous one ended.
344 child_start = child_end;
345 BrowserAccessibility* child = InternalGetChild(i);
346 DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
347 std::string child_text;
348 child->GetStringAttribute(ui::AX_ATTR_VALUE, &child_text);
dmazzoni 2015/02/20 18:16:21 Minor nit: it's slightly better to write: const s
349 int child_len = static_cast<int>(child_text.size());
350 child_end += child_len; // End is one past the last character.
351
352 const std::vector<int32>& word_starts = child->GetIntListAttribute(
353 ui::AX_ATTR_WORD_STARTS);
354 if (word_starts.empty()) {
355 word_start = child_end;
356 continue;
357 }
358
359 int local_start = start - child_start;
360 std::vector<int32>::const_iterator iter = std::upper_bound(
361 word_starts.cbegin(), word_starts.cend(), local_start);
362 if (iter != word_starts.cend()) {
363 if (direction == ui::FORWARDS_DIRECTION) {
364 word_start = child_start + *iter;
365 } else if (direction == ui::BACKWARDS_DIRECTION) {
dmazzoni 2015/02/20 18:16:21 nit: handle the case where direction is not FORWAR
366 if (iter == word_starts.cbegin()) {
367 // Return the position of the last word in the previous child.
368 word_start = prev_word_start;
369 } else {
370 word_start = child_start + *(iter - 1);
371 }
372 }
373 break;
374 }
375 prev_word_start = *(iter - 1);
376 word_start = child_end;
377 }
378
379 return word_start;
380 }
381
310 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( 382 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint(
311 const gfx::Point& point) { 383 const gfx::Point& point) {
312 // The best result found that's a child of this object. 384 // The best result found that's a child of this object.
313 BrowserAccessibility* child_result = NULL; 385 BrowserAccessibility* child_result = NULL;
314 // The best result that's an indirect descendant like grandchild, etc. 386 // The best result that's an indirect descendant like grandchild, etc.
315 BrowserAccessibility* descendant_result = NULL; 387 BrowserAccessibility* descendant_result = NULL;
316 388
317 // Walk the children recursively looking for the BrowserAccessibility that 389 // Walk the children recursively looking for the BrowserAccessibility that
318 // most tightly encloses the specified point. Walk backwards so that in 390 // most tightly encloses the specified point. Walk backwards so that in
319 // the absence of any other information, we assume the object that occurs 391 // the absence of any other information, we assume the object that occurs
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 781 }
710 need_to_offset_web_area = true; 782 need_to_offset_web_area = true;
711 } 783 }
712 parent = parent->GetParentForBoundsCalculation(); 784 parent = parent->GetParentForBoundsCalculation();
713 } 785 }
714 786
715 return bounds; 787 return bounds;
716 } 788 }
717 789
718 } // namespace content 790 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698