OLD | NEW |
---|---|
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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
11 | 11 |
12 size_t FindAccessibleTextBoundary(const base::string16& text, | 12 size_t FindAccessibleTextBoundary(const base::string16& text, |
13 const std::vector<int>& line_breaks, | 13 const std::vector<int>& line_breaks, |
14 TextBoundaryType boundary, | 14 TextBoundaryType boundary, |
15 size_t start_offset, | 15 size_t start_offset, |
16 TextBoundaryDirection direction) { | 16 TextBoundaryDirection direction) { |
17 size_t text_size = text.size(); | 17 size_t text_size = text.size(); |
18 DCHECK(start_offset <= text_size); | 18 DCHECK(start_offset <= text_size); |
19 | 19 |
20 if (boundary == CHAR_BOUNDARY) { | 20 if (boundary == CHAR_BOUNDARY) { |
21 if (direction == FORWARDS_DIRECTION && start_offset < text_size) | 21 if (direction == FORWARDS_DIRECTION && start_offset < text_size) |
22 return start_offset + 1; | 22 return start_offset + 1; |
23 else | 23 else |
24 return start_offset; | 24 return start_offset; |
25 } else if (boundary == LINE_BOUNDARY) { | 25 } else if (boundary == LINE_BOUNDARY) { |
26 if (direction == FORWARDS_DIRECTION) { | 26 if (direction == FORWARDS_DIRECTION) { |
27 for (size_t j = 0; j < line_breaks.size(); ++j) { | 27 for (size_t j = 0; j < line_breaks.size(); ++j) { |
28 size_t line_break = line_breaks[j] >= 0 ? line_breaks[j] : 0; | 28 size_t line_break = line_breaks[j] >= 0 ? line_breaks[j] : 0; |
29 if (line_break > start_offset) | 29 if (line_break >= start_offset) |
dmazzoni
2015/02/20 18:16:21
Maybe don't include this change in the changelist?
| |
30 return line_break; | 30 return line_break; |
31 } | 31 } |
32 return text_size; | 32 return text_size; |
33 } else { | 33 } else { |
34 for (size_t j = line_breaks.size(); j != 0; --j) { | 34 for (size_t j = line_breaks.size(); j != 0; --j) { |
35 size_t line_break = line_breaks[j - 1] >= 0 ? line_breaks[j - 1] : 0; | 35 size_t line_break = line_breaks[j - 1] >= 0 ? line_breaks[j - 1] : 0; |
36 if (line_break < start_offset) | 36 if (line_break < start_offset) |
37 return line_break; | 37 return line_break; |
38 } | 38 } |
39 return 0; | 39 return 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 if (direction == FORWARDS_DIRECTION) { | 80 if (direction == FORWARDS_DIRECTION) { |
81 result++; | 81 result++; |
82 } else { | 82 } else { |
83 result--; | 83 result--; |
84 } | 84 } |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 } // Namespace ui | 88 } // Namespace ui |
OLD | NEW |