diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-19 00:17:42 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-19 00:17:42 +0000 |
commit | 3e1dc20c34c610471927ac76f92f76be221af5d5 (patch) | |
tree | 2e61e9d442895b4ca5a72afaf97b788611319fe6 /ui | |
parent | d91705531f6fe02d1a8cc25e30c5b24ac6d55ad3 (diff) | |
download | chromium_src-3e1dc20c34c610471927ac76f92f76be221af5d5.zip chromium_src-3e1dc20c34c610471927ac76f92f76be221af5d5.tar.gz chromium_src-3e1dc20c34c610471927ac76f92f76be221af5d5.tar.bz2 |
Enable disabled omnibox tests on aura
- SetText should move the cursor to the end of new tex.
- OmniboxView::GetSelectionBounds should return the cursor
position when there is no selection
- Undo when ctrl-shift-z is pressed
BUG=121558
TEST=OmniboxVitewTest::UndoRedo/BackspaceDeleteHalfWidthKatakana are enabled.
Review URL: https://chromiumcodereview.appspot.com/10412009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137992 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
4 files changed, 29 insertions, 26 deletions
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 35fe3e2..03086b8 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -860,14 +860,16 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { OnBeforeUserAction(); bool editable = !textfield_->read_only(); bool readable = !textfield_->IsObscured(); - bool selection = key_event.IsShiftDown(); + bool shift = key_event.IsShiftDown(); bool control = key_event.IsControlDown(); bool text_changed = false; bool cursor_changed = false; switch (key_code) { case ui::VKEY_Z: - if (control && editable) + if (control && !shift && editable) cursor_changed = text_changed = model_->Undo(); + else if (control && shift && editable) + cursor_changed = text_changed = model_->Redo(); break; case ui::VKEY_Y: if (control && editable) @@ -896,16 +898,16 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { model_->MoveCursor( control ? gfx::WORD_BREAK : gfx::CHARACTER_BREAK, (key_code == ui::VKEY_RIGHT) ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT, - selection); + shift); cursor_changed = true; break; case ui::VKEY_END: case ui::VKEY_HOME: if ((key_code == ui::VKEY_HOME) == (GetRenderText()->GetTextDirection() == base::i18n::RIGHT_TO_LEFT)) - model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, selection); + model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, shift); else - model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, selection); + model_->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, shift); cursor_changed = true; break; case ui::VKEY_BACK: @@ -915,7 +917,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { if (!model_->HasSelection()) { gfx::VisualCursorDirection direction = (key_code == ui::VKEY_DELETE) ? gfx::CURSOR_RIGHT : gfx::CURSOR_LEFT; - if (selection && control) { + if (shift && control) { // If both shift and control are pressed, then erase up to the // beginning/end of the buffer in ChromeOS. In windows, do nothing. #if defined(OS_WIN) diff --git a/ui/views/controls/textfield/native_textfield_views_unittest.cc b/ui/views/controls/textfield/native_textfield_views_unittest.cc index e11f29c..2d557cc 100644 --- a/ui/views/controls/textfield/native_textfield_views_unittest.cc +++ b/ui/views/controls/textfield/native_textfield_views_unittest.cc @@ -366,14 +366,14 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCase) { last_contents_.clear(); textfield_->SetText(ASCIIToUTF16("THIS IS")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(7U, textfield_->GetCursorPosition()); EXPECT_STR_EQ("this is", model_->GetText()); EXPECT_STR_EQ("THIS IS", textfield_->text()); EXPECT_TRUE(last_contents_.empty()); textfield_->AppendText(ASCIIToUTF16(" A TEST")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(7U, textfield_->GetCursorPosition()); EXPECT_STR_EQ("this is a test", model_->GetText()); EXPECT_STR_EQ("THIS IS A TEST", textfield_->text()); @@ -388,7 +388,7 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) { last_contents_.clear(); // Zenkaku Japanese "ABCabc" textfield_->SetText(WideToUTF16(L"\xFF21\xFF22\xFF23\xFF41\xFF42\xFF43")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(6U, textfield_->GetCursorPosition()); // Zenkaku Japanese "abcabc" EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43"), model_->GetText()); @@ -399,7 +399,7 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseI18n) { // Zenkaku Japanese "XYZxyz" textfield_->AppendText(WideToUTF16(L"\xFF38\xFF39\xFF3A\xFF58\xFF59\xFF5A")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(6U, textfield_->GetCursorPosition()); // Zenkaku Japanese "abcabcxyzxyz" EXPECT_EQ(WideToUTF16(L"\xFF41\xFF42\xFF43\xFF41\xFF42\xFF43" L"\xFF58\xFF59\xFF5A\xFF58\xFF59\xFF5A"), @@ -422,7 +422,7 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) { last_contents_.clear(); // Turkish 'I' should be converted to dotless 'i' (U+0131). textfield_->SetText(WideToUTF16(L"I")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(1U, textfield_->GetCursorPosition()); EXPECT_EQ(WideToUTF16(L"\x0131"), model_->GetText()); EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); EXPECT_TRUE(last_contents_.empty()); @@ -431,7 +431,7 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTestLowerCaseWithLocale) { // On default (en) locale, 'I' should be converted to 'i'. textfield_->SetText(WideToUTF16(L"I")); - EXPECT_EQ(0U, textfield_->GetCursorPosition()); + EXPECT_EQ(1U, textfield_->GetCursorPosition()); EXPECT_EQ(WideToUTF16(L"i"), model_->GetText()); EXPECT_EQ(WideToUTF16(L"I"), textfield_->text()); EXPECT_TRUE(last_contents_.empty()); @@ -462,8 +462,8 @@ TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) { // Insert a test string in a textfield. InitTextfield(Textfield::STYLE_DEFAULT); textfield_->SetText(ASCIIToUTF16("one two three")); - SendKeyEvent(ui::VKEY_RIGHT, - true /* shift */, false /* control */); + SendKeyEvent(ui::VKEY_HOME, false /* shift */, false /* control */); + SendKeyEvent(ui::VKEY_RIGHT, true, false); SendKeyEvent(ui::VKEY_RIGHT, true, false); SendKeyEvent(ui::VKEY_RIGHT, true, false); diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc index 6d8dd76..b26c7f0b 100644 --- a/ui/views/controls/textfield/textfield_views_model.cc +++ b/ui/views/controls/textfield/textfield_views_model.cc @@ -315,7 +315,8 @@ bool TextfieldViewsModel::SetText(const string16& text) { if (changed) // No need to remember composition. Undo(); size_t old_cursor = GetCursorPosition(); - size_t new_cursor = old_cursor > text.length() ? text.length() : old_cursor; + // SetText moves the cursor to the end. + size_t new_cursor = text.length(); SelectAll(); // If there is a composition text, don't merge with previous edit. // Otherwise, force merge the edits. diff --git a/ui/views/controls/textfield/textfield_views_model_unittest.cc b/ui/views/controls/textfield/textfield_views_model_unittest.cc index 8b581ea..80fd6cb 100644 --- a/ui/views/controls/textfield/textfield_views_model_unittest.cc +++ b/ui/views/controls/textfield/textfield_views_model_unittest.cc @@ -470,8 +470,8 @@ TEST_F(TextfieldViewsModelTest, SetText) { model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); model.SetText(ASCIIToUTF16("GOODBYE")); EXPECT_STR_EQ("GOODBYE", model.GetText()); - // SetText won't reset the cursor posistion. - EXPECT_EQ(5U, model.GetCursorPosition()); + // SetText move the cursor to the end of the new text. + EXPECT_EQ(7U, model.GetCursorPosition()); model.SelectAll(); EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); @@ -1104,7 +1104,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { EXPECT_STR_EQ("w", model.GetText()); EXPECT_EQ(1U, model.GetCursorPosition()); model.SetText(ASCIIToUTF16("www.google.com")); - EXPECT_EQ(1U, model.GetCursorPosition()); + EXPECT_EQ(14U, model.GetCursorPosition()); EXPECT_STR_EQ("www.google.com", model.GetText()); model.SelectRange(ui::Range(14, 1)); model.InsertChar('w'); @@ -1123,7 +1123,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { EXPECT_STR_EQ("www.y", model.GetText()); model.SetText(ASCIIToUTF16("www.youtube.com")); EXPECT_STR_EQ("www.youtube.com", model.GetText()); - EXPECT_EQ(5U, model.GetCursorPosition()); + EXPECT_EQ(15U, model.GetCursorPosition()); EXPECT_TRUE(model.Undo()); EXPECT_STR_EQ("www.google.com", model.GetText()); @@ -1166,7 +1166,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) { EXPECT_STR_EQ("w", model.GetText()); EXPECT_EQ(1U, model.GetCursorPosition()); model.SetText(ASCIIToUTF16("www.google.com")); - EXPECT_EQ(1U, model.GetCursorPosition()); + EXPECT_EQ(14U, model.GetCursorPosition()); EXPECT_STR_EQ("www.google.com", model.GetText()); model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text. model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); @@ -1202,7 +1202,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { EXPECT_STR_EQ("", model.GetText()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("ABCDE", model.GetText()); - EXPECT_EQ(0U, model.GetCursorPosition()); + EXPECT_EQ(5U, model.GetCursorPosition()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("ADE", model.GetText()); EXPECT_EQ(1U, model.GetCursorPosition()); @@ -1233,7 +1233,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { EXPECT_STR_EQ("", model.GetText()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("ABCDE", model.GetText()); // Redoing SetText - EXPECT_EQ(0U, model.GetCursorPosition()); + EXPECT_EQ(5U, model.GetCursorPosition()); // Redo EXPECT_TRUE(model.Redo()); @@ -1273,7 +1273,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { ResetModel(&model); model.SetText(ASCIIToUTF16("12345")); EXPECT_STR_EQ("12345", model.GetText()); - EXPECT_EQ(0U, model.GetCursorPosition()); + EXPECT_EQ(5U, model.GetCursorPosition()); model.SelectRange(ui::Range(1, 3)); model.Copy(); // Copy "23" EXPECT_STR_EQ("12345", model.GetText()); @@ -1297,7 +1297,7 @@ TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { // Redo EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("12345", model.GetText()); - EXPECT_EQ(0U, model.GetCursorPosition()); + EXPECT_EQ(5U, model.GetCursorPosition()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("12345", model.GetText()); // For 1st paste EXPECT_EQ(3U, model.GetCursorPosition()); @@ -1358,7 +1358,7 @@ void RunInsertReplaceTest(TextfieldViewsModel& model) { EXPECT_FALSE(model.Undo()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("abcd", model.GetText()); - EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText + EXPECT_EQ(4U, model.GetCursorPosition()); // By SetText EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("a123d", model.GetText()); EXPECT_EQ(4U, model.GetCursorPosition()); @@ -1385,7 +1385,7 @@ void RunOverwriteReplaceTest(TextfieldViewsModel& model) { EXPECT_FALSE(model.Undo()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("abcd", model.GetText()); - EXPECT_EQ(0U, model.GetCursorPosition()); + EXPECT_EQ(4U, model.GetCursorPosition()); EXPECT_TRUE(model.Redo()); EXPECT_STR_EQ("a1234", model.GetText()); EXPECT_EQ(5U, model.GetCursorPosition()); |