diff options
author | nektar <nektar@chromium.org> | 2015-04-29 17:31:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-30 00:31:43 +0000 |
commit | 28f5f6444f311879cff2e7688011a54bf40a463b (patch) | |
tree | 37f8fc30bf4d3bc955f28fff42f94d76b533bf36 /ui/accessibility | |
parent | ea8c00ec4ea9fc6df348f0cb2b3a2b0f3ed2802e (diff) | |
download | chromium_src-28f5f6444f311879cff2e7688011a54bf40a463b.zip chromium_src-28f5f6444f311879cff2e7688011a54bf40a463b.tar.gz chromium_src-28f5f6444f311879cff2e7688011a54bf40a463b.tar.bz2 |
Fixed word and line navigation in multi-line text fields.
This might also fix the line break issue where lines appear joined together.
This CL should be submitted only after the Blink change removing a spurious line break at the end of all text fields is rolled into Chromium.
BUG=102231
R=dmazzoni
Review URL: https://codereview.chromium.org/1111163002
Cr-Commit-Position: refs/heads/master@{#327629}
Diffstat (limited to 'ui/accessibility')
-rw-r--r-- | ui/accessibility/ax_text_utils.cc | 7 | ||||
-rw-r--r-- | ui/accessibility/ax_text_utils_unittest.cc | 66 |
2 files changed, 41 insertions, 32 deletions
diff --git a/ui/accessibility/ax_text_utils.cc b/ui/accessibility/ax_text_utils.cc index cac5aee..da336b6 100644 --- a/ui/accessibility/ax_text_utils.cc +++ b/ui/accessibility/ax_text_utils.cc @@ -9,13 +9,16 @@ namespace ui { +// line_breaks is a Misnomer. Blink provides the start offsets of each line +// not the line breaks. +// TODO(nektar): Rename line_breaks a11y attribute and variable references. size_t FindAccessibleTextBoundary(const base::string16& text, const std::vector<int>& line_breaks, TextBoundaryType boundary, size_t start_offset, TextBoundaryDirection direction) { size_t text_size = text.size(); - DCHECK(start_offset <= text_size); + DCHECK_LE(start_offset, text_size); if (boundary == CHAR_BOUNDARY) { if (direction == FORWARDS_DIRECTION && start_offset < text_size) @@ -33,7 +36,7 @@ size_t FindAccessibleTextBoundary(const base::string16& text, } else { for (size_t j = line_breaks.size(); j != 0; --j) { size_t line_break = line_breaks[j - 1] >= 0 ? line_breaks[j - 1] : 0; - if (line_break < start_offset) + if (line_break <= start_offset) return line_break; } return 0; diff --git a/ui/accessibility/ax_text_utils_unittest.cc b/ui/accessibility/ax_text_utils_unittest.cc index 7163ef84..806401b 100644 --- a/ui/accessibility/ax_text_utils_unittest.cc +++ b/ui/accessibility/ax_text_utils_unittest.cc @@ -9,54 +9,60 @@ namespace ui { TEST(AXTextUtils, FindAccessibleTextBoundaryLine) { - const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n"); + const base::string16 text = base::UTF8ToUTF16("Line 1.\nLine 2\n\t"); const size_t text_length = text.length(); - std::vector<int> line_breaks; - line_breaks.push_back(7); - line_breaks.push_back(14); + std::vector<int> line_start_offsets; + line_start_offsets.push_back(8); + line_start_offsets.push_back(15); size_t result; // Basic cases. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 5, - FORWARDS_DIRECTION); - EXPECT_EQ(7UL, result); - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 9, - BACKWARDS_DIRECTION); - EXPECT_EQ(7UL, result); - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 10, - FORWARDS_DIRECTION); - EXPECT_EQ(14UL, result); + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 5, FORWARDS_DIRECTION); + EXPECT_EQ(8UL, result); + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 9, BACKWARDS_DIRECTION); + EXPECT_EQ(8UL, result); + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 10, FORWARDS_DIRECTION); + EXPECT_EQ(15UL, result); // Edge cases. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, text_length, BACKWARDS_DIRECTION); - EXPECT_EQ(14UL, result); + EXPECT_EQ(15UL, result); - // When the start_offset is on a line break and we are searching backwards, - // it should return the previous line break. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 14, - BACKWARDS_DIRECTION); - EXPECT_EQ(7UL, result); + // When the start_offset is at the start of the next line and we are searching + // backwards, it should not move. + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 15, BACKWARDS_DIRECTION); + EXPECT_EQ(15UL, result); - // When the start_offset is on a line break and we are searching forwards, - // it should return the next line break. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 7, - FORWARDS_DIRECTION); - EXPECT_EQ(14UL, result); + // When the start_offset is at a hard line break and we are searching + // backwards, it should return the start of the previous line. + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 14, BACKWARDS_DIRECTION); + EXPECT_EQ(8UL, result); + + // When the start_offset is at the start of a line and we are searching + // forwards, it should return the start of the next line. + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 8, FORWARDS_DIRECTION); + EXPECT_EQ(15UL, result); // When there is no previous line break and we are searching backwards, // it should return 0. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 4, - BACKWARDS_DIRECTION); + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 4, BACKWARDS_DIRECTION); EXPECT_EQ(0UL, result); - // When we are on the last line break and we are searching forwards. + // When we are at the start of the last line and we are searching forwards. // it should return the text length. - result = FindAccessibleTextBoundary(text, line_breaks, LINE_BOUNDARY, 14, - FORWARDS_DIRECTION); + result = FindAccessibleTextBoundary(text, line_start_offsets, LINE_BOUNDARY, + 15, FORWARDS_DIRECTION); EXPECT_EQ(text_length, result); } |