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

Side by Side Diff: ui/accessibility/ax_text_utils.cc

Issue 2191833003: Use text affinity to return correct accessible line boundaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bug in browser_accessibility_win.cc Created 4 years, 4 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
« no previous file with comments | « ui/accessibility/ax_text_utils.h ('k') | ui/accessibility/ax_text_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ui/accessibility/ax_text_utils.h" 5 #include "ui/accessibility/ax_text_utils.h"
6 6
7 #include "base/i18n/break_iterator.h" 7 #include "base/i18n/break_iterator.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 10
11 namespace ui { 11 namespace ui {
12 12
13 // line_breaks is a Misnomer. Blink provides the start offsets of each line 13 // line_breaks is a Misnomer. Blink provides the start offsets of each line
14 // not the line breaks. 14 // not the line breaks.
15 // TODO(nektar): Rename line_breaks a11y attribute and variable references. 15 // TODO(nektar): Rename line_breaks a11y attribute and variable references.
16 size_t FindAccessibleTextBoundary(const base::string16& text, 16 size_t FindAccessibleTextBoundary(const base::string16& text,
17 const std::vector<int>& line_breaks, 17 const std::vector<int>& line_breaks,
18 TextBoundaryType boundary, 18 TextBoundaryType boundary,
19 size_t start_offset, 19 size_t start_offset,
20 TextBoundaryDirection direction) { 20 TextBoundaryDirection direction,
21 AXTextAffinity affinity) {
21 size_t text_size = text.size(); 22 size_t text_size = text.size();
22 DCHECK_LE(start_offset, text_size); 23 DCHECK_LE(start_offset, text_size);
23 24
24 if (boundary == CHAR_BOUNDARY) { 25 if (boundary == CHAR_BOUNDARY) {
25 if (direction == FORWARDS_DIRECTION && start_offset < text_size) 26 if (direction == FORWARDS_DIRECTION && start_offset < text_size)
26 return start_offset + 1; 27 return start_offset + 1;
27 else 28 else
28 return start_offset; 29 return start_offset;
29 } 30 }
30 31
31 base::i18n::BreakIterator word_iter(text, 32 base::i18n::BreakIterator word_iter(text,
32 base::i18n::BreakIterator::BREAK_WORD); 33 base::i18n::BreakIterator::BREAK_WORD);
33 if (boundary == WORD_BOUNDARY) { 34 if (boundary == WORD_BOUNDARY) {
34 if (!word_iter.Init()) 35 if (!word_iter.Init())
35 return start_offset; 36 return start_offset;
36 } 37 }
37 38
38 if (boundary == LINE_BOUNDARY) { 39 if (boundary == LINE_BOUNDARY) {
39 if (direction == FORWARDS_DIRECTION) { 40 if (direction == FORWARDS_DIRECTION) {
40 for (size_t j = 0; j < line_breaks.size(); ++j) { 41 for (size_t j = 0; j < line_breaks.size(); ++j) {
41 size_t line_break = line_breaks[j] >= 0 ? line_breaks[j] : 0; 42 size_t line_break = line_breaks[j] >= 0 ? line_breaks[j] : 0;
42 if (line_break > start_offset) 43 if ((affinity == AX_TEXT_AFFINITY_DOWNSTREAM &&
44 line_break > start_offset) ||
45 (affinity == AX_TEXT_AFFINITY_UPSTREAM &&
46 line_break >= start_offset)) {
43 return line_break; 47 return line_break;
48 }
44 } 49 }
45 return text_size; 50 return text_size;
46 } else { 51 } else {
47 for (size_t j = line_breaks.size(); j != 0; --j) { 52 for (size_t j = line_breaks.size(); j != 0; --j) {
48 size_t line_break = line_breaks[j - 1] >= 0 ? line_breaks[j - 1] : 0; 53 size_t line_break = line_breaks[j - 1] >= 0 ? line_breaks[j - 1] : 0;
49 if (line_break <= start_offset) 54 if ((affinity == AX_TEXT_AFFINITY_DOWNSTREAM &&
55 line_break <= start_offset) ||
56 (affinity == AX_TEXT_AFFINITY_UPSTREAM &&
57 line_break < start_offset)) {
50 return line_break; 58 return line_break;
59 }
51 } 60 }
52 return 0; 61 return 0;
53 } 62 }
54 } 63 }
55 64
56 size_t result = start_offset; 65 size_t result = start_offset;
57 for (;;) { 66 for (;;) {
58 size_t pos; 67 size_t pos;
59 if (direction == FORWARDS_DIRECTION) { 68 if (direction == FORWARDS_DIRECTION) {
60 if (result >= text_size) 69 if (result >= text_size)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 106
98 if (direction == FORWARDS_DIRECTION) { 107 if (direction == FORWARDS_DIRECTION) {
99 result++; 108 result++;
100 } else { 109 } else {
101 result--; 110 result--;
102 } 111 }
103 } 112 }
104 } 113 }
105 114
106 } // namespace ui 115 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/ax_text_utils.h ('k') | ui/accessibility/ax_text_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698