Commit a91a682e authored by jongkwon.lee's avatar jongkwon.lee Committed by Commit Bot

gfx::RenderText Rename gfx::BreakType types

Merges the temporary type LINE_BREAK_MULTILINE to LINE_BREAK and introduces
new type FIELD_BREAK for edge selection. As LineSelectionModel returns
EdgeSelectionModel for a single line text, there is no behavioral change.
Adds some tests for FIELD_BREAK.

Change-Id: I7636852f13e61a6e0b8a70ca59d4f925c1c68ce3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626845
Commit-Queue: Michael Wasserman <msw@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664402}
parent 8dee606f
...@@ -591,8 +591,8 @@ void RenderText::MoveCursor(BreakType break_type, ...@@ -591,8 +591,8 @@ void RenderText::MoveCursor(BreakType break_type,
} }
// Cancelling a selection moves to the edge of the selection. // Cancelling a selection moves to the edge of the selection.
if (break_type != LINE_BREAK && !selection().is_empty() && if (break_type != FIELD_BREAK && break_type != LINE_BREAK &&
selection_behavior == SELECTION_NONE) { !selection().is_empty() && selection_behavior == SELECTION_NONE) {
// Use the nearest word boundary in the proper |direction| for word breaks. // Use the nearest word boundary in the proper |direction| for word breaks.
if (break_type == WORD_BREAK) if (break_type == WORD_BREAK)
cursor = GetAdjacentSelectionModel(cursor, break_type, direction); cursor = GetAdjacentSelectionModel(cursor, break_type, direction);
...@@ -1130,9 +1130,9 @@ SelectionModel RenderText::GetAdjacentSelectionModel( ...@@ -1130,9 +1130,9 @@ SelectionModel RenderText::GetAdjacentSelectionModel(
if (direction == CURSOR_UP || direction == CURSOR_DOWN) if (direction == CURSOR_UP || direction == CURSOR_DOWN)
return AdjacentLineSelectionModel(current, direction); return AdjacentLineSelectionModel(current, direction);
if (break_type == LINE_BREAK || text().empty()) if (break_type == FIELD_BREAK || text().empty())
return EdgeSelectionModel(direction); return EdgeSelectionModel(direction);
if (break_type == LINE_BREAK_MULTILINE) if (break_type == LINE_BREAK)
return LineSelectionModel(GetLineContainingCaret(current), direction); return LineSelectionModel(GetLineContainingCaret(current), direction);
if (break_type == CHARACTER_BREAK) if (break_type == CHARACTER_BREAK)
return AdjacentCharSelectionModel(current, direction); return AdjacentCharSelectionModel(current, direction);
...@@ -1149,13 +1149,19 @@ SelectionModel RenderText::EdgeSelectionModel( ...@@ -1149,13 +1149,19 @@ SelectionModel RenderText::EdgeSelectionModel(
SelectionModel RenderText::LineSelectionModel(size_t line_index, SelectionModel RenderText::LineSelectionModel(size_t line_index,
VisualCursorDirection direction) { VisualCursorDirection direction) {
DCHECK(direction == CURSOR_LEFT || direction == CURSOR_RIGHT);
const internal::Line& line = lines()[line_index]; const internal::Line& line = lines()[line_index];
if (line.segments.empty()) { if (line.segments.empty()) {
// Only the last line can be empty. // Only the last line can be empty.
DCHECK_EQ(lines().size() - 1, line_index); DCHECK_EQ(lines().size() - 1, line_index);
return EdgeSelectionModel(GetVisualDirectionOfLogicalEnd()); return EdgeSelectionModel(GetVisualDirectionOfLogicalEnd());
} }
if (line_index ==
(direction == GetVisualDirectionOfLogicalEnd() ? GetNumLines() - 1 : 0)) {
return EdgeSelectionModel(direction);
}
DCHECK_GT(GetNumLines(), 1U);
size_t max_index = 0; size_t max_index = 0;
size_t min_index = text().length(); size_t min_index = text().length();
for (const auto& segment : line.segments) { for (const auto& segment : line.segments) {
...@@ -1175,9 +1181,9 @@ SelectionModel RenderText::LineSelectionModel(size_t line_index, ...@@ -1175,9 +1181,9 @@ SelectionModel RenderText::LineSelectionModel(size_t line_index,
// line number of the cursor in multiline text. // line number of the cursor in multiline text.
return direction == GetVisualDirectionOfLogicalEnd() return direction == GetVisualDirectionOfLogicalEnd()
? SelectionModel(DisplayIndexToTextIndex(max_index), ? SelectionModel(DisplayIndexToTextIndex(max_index),
multiline() ? CURSOR_BACKWARD : CURSOR_FORWARD) CURSOR_BACKWARD)
: SelectionModel(DisplayIndexToTextIndex(min_index), : SelectionModel(DisplayIndexToTextIndex(min_index),
multiline() ? CURSOR_FORWARD : CURSOR_BACKWARD); CURSOR_FORWARD);
} }
void RenderText::SetSelectionModel(const SelectionModel& model) { void RenderText::SetSelectionModel(const SelectionModel& model) {
...@@ -1301,7 +1307,9 @@ Point RenderText::ToViewPoint(const PointF& point, ...@@ -1301,7 +1307,9 @@ Point RenderText::ToViewPoint(const PointF& point,
const auto float_ge = [](float a, float b) { const auto float_ge = [](float a, float b) {
return a > b || std::fabs(a - b) <= kFloatComparisonEpsilon; return a > b || std::fabs(a - b) <= kFloatComparisonEpsilon;
}; };
const auto float_gt = [](float a, float b) { return a - b > kFloatComparisonEpsilon; }; const auto float_gt = [](float a, float b) {
return a - b > kFloatComparisonEpsilon;
};
const size_t num_lines = GetNumLines(); const size_t num_lines = GetNumLines();
if (num_lines == 1) { if (num_lines == 1) {
......
...@@ -1571,77 +1571,79 @@ TEST_F(RenderTextTest, MoveCursor_Line) { ...@@ -1571,77 +1571,79 @@ TEST_F(RenderTextTest, MoveCursor_Line) {
render_text->SetText(UTF8ToUTF16("123 456 789")); render_text->SetText(UTF8ToUTF16("123 456 789"));
std::vector<Range> expected; std::vector<Range> expected;
// SELECTION_NONE. for (auto break_type : {LINE_BREAK, FIELD_BREAK}) {
render_text->SelectRange(Range(6)); // SELECTION_NONE.
render_text->SelectRange(Range(6));
// Move right twice.
expected.push_back(Range(11));
expected.push_back(Range(11));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_NONE, &expected);
// Move left twice.
expected.push_back(Range(0));
expected.push_back(Range(0));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
SELECTION_NONE, &expected);
// SELECTION_CARET.
render_text->SelectRange(Range(6));
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_CARET, &expected);
// Move left twice.
expected.push_back(Range(6));
expected.push_back(Range(6, 0));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
SELECTION_CARET, &expected);
// Move right.
expected.push_back(Range(6));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_CARET, &expected);
// SELECTION_RETAIN.
render_text->SelectRange(Range(6));
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_RETAIN, &expected);
// Move left twice.
expected.push_back(Range(6, 0));
expected.push_back(Range(6, 0));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT,
SELECTION_RETAIN, &expected);
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_RETAIN, &expected);
// SELECTION_EXTEND.
render_text->SelectRange(Range(6));
// Move right. // Move right twice.
expected.push_back(Range(6, 11)); expected.push_back(Range(11));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT, expected.push_back(Range(11));
SELECTION_EXTEND, &expected); RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_NONE, &expected);
// Move left twice. // Move left twice.
expected.push_back(Range(11, 0)); expected.push_back(Range(0));
expected.push_back(Range(11, 0)); expected.push_back(Range(0));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_LEFT, RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_LEFT,
SELECTION_EXTEND, &expected); SELECTION_NONE, &expected);
// Move right. // SELECTION_CARET.
expected.push_back(Range(0, 11)); render_text->SelectRange(Range(6));
RunMoveCursorTestAndClearExpectations(render_text, LINE_BREAK, CURSOR_RIGHT,
SELECTION_EXTEND, &expected); // Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_CARET, &expected);
// Move left twice.
expected.push_back(Range(6));
expected.push_back(Range(6, 0));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_LEFT,
SELECTION_CARET, &expected);
// Move right.
expected.push_back(Range(6));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_CARET, &expected);
// SELECTION_RETAIN.
render_text->SelectRange(Range(6));
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_RETAIN, &expected);
// Move left twice.
expected.push_back(Range(6, 0));
expected.push_back(Range(6, 0));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_LEFT,
SELECTION_RETAIN, &expected);
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_RETAIN, &expected);
// SELECTION_EXTEND.
render_text->SelectRange(Range(6));
// Move right.
expected.push_back(Range(6, 11));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_EXTEND, &expected);
// Move left twice.
expected.push_back(Range(11, 0));
expected.push_back(Range(11, 0));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_LEFT,
SELECTION_EXTEND, &expected);
// Move right.
expected.push_back(Range(0, 11));
RunMoveCursorTestAndClearExpectations(render_text, break_type, CURSOR_RIGHT,
SELECTION_EXTEND, &expected);
}
} }
TEST_F(RenderTextTest, MoveCursor_UpDown) { TEST_F(RenderTextTest, MoveCursor_UpDown) {
...@@ -2335,13 +2337,13 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) { ...@@ -2335,13 +2337,13 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) {
EXPECT_EQ(4U, render_text->GetNumLines()); EXPECT_EQ(4U, render_text->GetNumLines());
// Move cursor right to the end of the text. // Move cursor right to the end of the text.
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(4), render_text->selection()); EXPECT_EQ(Range(4), render_text->selection());
EXPECT_EQ(0U, GetLineContainingCaret()); EXPECT_EQ(0U, GetLineContainingCaret());
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(5), render_text->selection()); EXPECT_EQ(Range(5), render_text->selection());
EXPECT_EQ(1U, GetLineContainingCaret()); EXPECT_EQ(1U, GetLineContainingCaret());
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(7), render_text->selection()); EXPECT_EQ(Range(7), render_text->selection());
EXPECT_EQ(1U, GetLineContainingCaret()); EXPECT_EQ(1U, GetLineContainingCaret());
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
...@@ -2350,12 +2352,12 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) { ...@@ -2350,12 +2352,12 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) {
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(9), render_text->selection()); EXPECT_EQ(Range(9), render_text->selection());
EXPECT_EQ(3U, GetLineContainingCaret()); EXPECT_EQ(3U, GetLineContainingCaret());
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_RIGHT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(11), render_text->selection()); EXPECT_EQ(Range(11), render_text->selection());
EXPECT_EQ(3U, GetLineContainingCaret()); EXPECT_EQ(3U, GetLineContainingCaret());
// Move cursor left to the beginning of the text. // Move cursor left to the beginning of the text.
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(9), render_text->selection()); EXPECT_EQ(Range(9), render_text->selection());
EXPECT_EQ(3U, GetLineContainingCaret()); EXPECT_EQ(3U, GetLineContainingCaret());
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
...@@ -2364,13 +2366,13 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) { ...@@ -2364,13 +2366,13 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) {
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(7), render_text->selection()); EXPECT_EQ(Range(7), render_text->selection());
EXPECT_EQ(1U, GetLineContainingCaret()); EXPECT_EQ(1U, GetLineContainingCaret());
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(4), render_text->selection()); EXPECT_EQ(Range(4), render_text->selection());
EXPECT_EQ(1U, GetLineContainingCaret()); EXPECT_EQ(1U, GetLineContainingCaret());
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(3), render_text->selection()); EXPECT_EQ(Range(3), render_text->selection());
EXPECT_EQ(0U, GetLineContainingCaret()); EXPECT_EQ(0U, GetLineContainingCaret());
render_text->MoveCursor(LINE_BREAK_MULTILINE, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(0), render_text->selection()); EXPECT_EQ(Range(0), render_text->selection());
EXPECT_EQ(0U, GetLineContainingCaret()); EXPECT_EQ(0U, GetLineContainingCaret());
...@@ -2404,6 +2406,16 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) { ...@@ -2404,6 +2406,16 @@ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection_Multiline) {
render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE); render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(0), render_text->selection()); EXPECT_EQ(Range(0), render_text->selection());
EXPECT_EQ(0U, GetLineContainingCaret()); EXPECT_EQ(0U, GetLineContainingCaret());
// Move cursor right with FIELD_BREAK.
render_text->MoveCursor(FIELD_BREAK, CURSOR_RIGHT, SELECTION_NONE);
EXPECT_EQ(Range(11), render_text->selection());
EXPECT_EQ(3U, GetLineContainingCaret());
// Move cursor left with FIELD_BREAK.
render_text->MoveCursor(FIELD_BREAK, CURSOR_LEFT, SELECTION_NONE);
EXPECT_EQ(Range(0), render_text->selection());
EXPECT_EQ(0U, GetLineContainingCaret());
} }
TEST_F(RenderTextTest, CenteredDisplayOffset) { TEST_F(RenderTextTest, CenteredDisplayOffset) {
......
...@@ -9,12 +9,11 @@ namespace gfx { ...@@ -9,12 +9,11 @@ namespace gfx {
// TODO(msw): Distinguish between logical character stops and glyph stops? // TODO(msw): Distinguish between logical character stops and glyph stops?
// TODO(msw): Merge with base::i18n::BreakIterator::BreakType. // TODO(msw): Merge with base::i18n::BreakIterator::BreakType.
// TODO(jongkwon.lee): Rename LINE_BREAK_MULTILINE, LINE_BREAK.
enum BreakType { enum BreakType {
CHARACTER_BREAK = 0, // Stop cursor movement on neighboring characters CHARACTER_BREAK = 0, // Stop cursor movement on neighboring characters.
WORD_BREAK, // Stop cursor movement on nearest word boundaries WORD_BREAK, // Stop cursor movement on nearest word boundaries.
LINE_BREAK, // Stop cursor movement on line ends as shown on screen LINE_BREAK, // Stop cursor movement on line ends as shown on screen.
LINE_BREAK_MULTILINE, // LINE_BREAK for multiline FIELD_BREAK, // Stop cursor movement on text ends.
}; };
// Specifies the selection behavior for a move/move-and-select command. For // Specifies the selection behavior for a move/move-and-select command. For
......
...@@ -1859,15 +1859,21 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { ...@@ -1859,15 +1859,21 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break; break;
case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN); model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN);
text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
break; break;
case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
model_->MoveCursor(gfx::FIELD_BREAK, begin, gfx::SELECTION_RETAIN);
text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_TO_END_OF_LINE: case ui::TextEditCommand::DELETE_TO_END_OF_LINE:
case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN); model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN);
text_changed = cursor_changed = model_->Delete(add_to_kill_buffer); text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break; break;
case ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH:
model_->MoveCursor(gfx::FIELD_BREAK, end, gfx::SELECTION_RETAIN);
text_changed = cursor_changed = model_->Delete(add_to_kill_buffer);
break;
case ui::TextEditCommand::DELETE_WORD_BACKWARD: case ui::TextEditCommand::DELETE_WORD_BACKWARD:
model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_RETAIN); model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_RETAIN);
text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer); text_changed = cursor_changed = model_->Backspace(add_to_kill_buffer);
...@@ -1904,46 +1910,55 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { ...@@ -1904,46 +1910,55 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, model_->MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
gfx::SELECTION_RETAIN); gfx::SELECTION_RETAIN);
break; break;
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE: case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE:
model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_NONE);
break;
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH: case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_PARAGRAPH:
case ui::TextEditCommand::MOVE_UP: case ui::TextEditCommand::MOVE_UP:
case ui::TextEditCommand::MOVE_PAGE_UP: case ui::TextEditCommand::MOVE_PAGE_UP:
model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_NONE); model_->MoveCursor(gfx::FIELD_BREAK, begin, gfx::SELECTION_NONE);
break;
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, begin, kLineSelectionBehavior);
break; break;
case ui::TextEditCommand:: case ui::TextEditCommand::
MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION: MOVE_TO_BEGINNING_OF_DOCUMENT_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION:
case ui::TextEditCommand:: case ui::TextEditCommand::
MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION: MOVE_TO_BEGINNING_OF_PARAGRAPH_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, begin, kLineSelectionBehavior); model_->MoveCursor(gfx::FIELD_BREAK, begin, kLineSelectionBehavior);
break; break;
case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_PAGE_UP_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_UP_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, begin, gfx::SELECTION_RETAIN); model_->MoveCursor(gfx::FIELD_BREAK, begin, gfx::SELECTION_RETAIN);
break; break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_END_OF_LINE: case ui::TextEditCommand::MOVE_TO_END_OF_LINE:
model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_NONE);
break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH: case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH:
case ui::TextEditCommand::MOVE_DOWN: case ui::TextEditCommand::MOVE_DOWN:
case ui::TextEditCommand::MOVE_PAGE_DOWN: case ui::TextEditCommand::MOVE_PAGE_DOWN:
model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_NONE); model_->MoveCursor(gfx::FIELD_BREAK, end, gfx::SELECTION_NONE);
break; break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, end, kLineSelectionBehavior); model_->MoveCursor(gfx::LINE_BREAK, end, kLineSelectionBehavior);
break; break;
case ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_TO_END_OF_PARAGRAPH_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::FIELD_BREAK, end, kLineSelectionBehavior);
break;
case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_PAGE_DOWN_AND_MODIFY_SELECTION:
case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_DOWN_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, end, gfx::SELECTION_RETAIN); model_->MoveCursor(gfx::FIELD_BREAK, end, gfx::SELECTION_RETAIN);
break; break;
case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_PARAGRAPH_BACKWARD_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, begin, model_->MoveCursor(gfx::FIELD_BREAK, begin,
kMoveParagraphSelectionBehavior); kMoveParagraphSelectionBehavior);
break; break;
case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION: case ui::TextEditCommand::MOVE_PARAGRAPH_FORWARD_AND_MODIFY_SELECTION:
model_->MoveCursor(gfx::LINE_BREAK, end, kMoveParagraphSelectionBehavior); model_->MoveCursor(gfx::FIELD_BREAK, end,
kMoveParagraphSelectionBehavior);
break; break;
case ui::TextEditCommand::MOVE_WORD_BACKWARD: case ui::TextEditCommand::MOVE_WORD_BACKWARD:
model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_NONE); model_->MoveCursor(gfx::WORD_BREAK, begin, gfx::SELECTION_NONE);
......
...@@ -1249,6 +1249,28 @@ TEST_F(TextfieldTest, DeletionWithSelection) { ...@@ -1249,6 +1249,28 @@ TEST_F(TextfieldTest, DeletionWithSelection) {
} }
} }
// Test deletions not covered by other tests with key events.
TEST_F(TextfieldTest, DeletionWithEditCommands) {
struct {
ui::TextEditCommand command;
const char* expected;
} cases[] = {
{ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE, "two three"},
{ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH, "two three"},
{ui::TextEditCommand::DELETE_TO_END_OF_LINE, "one "},
{ui::TextEditCommand::DELETE_TO_END_OF_PARAGRAPH, "one "},
};
InitTextfield();
for (size_t i = 0; i < base::size(cases); ++i) {
SCOPED_TRACE(base::StringPrintf("Testing cases[%" PRIuS "]", i));
textfield_->SetText(ASCIIToUTF16("one two three"));
textfield_->SelectRange(gfx::Range(4));
test_api_->ExecuteTextEditCommand(cases[i].command);
EXPECT_STR_EQ(cases[i].expected, textfield_->text());
}
}
TEST_F(TextfieldTest, PasswordTest) { TEST_F(TextfieldTest, PasswordTest) {
InitTextfield(); InitTextfield();
textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment