summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-11 14:14:59 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-11 14:14:59 +0000
commitc031aeda4ec93a6939cd8ed9f2273fb4279238ac (patch)
tree7965d2bca90855aafa3a461a83e6fb402aa85a75 /views
parentc806b3ba2c00eb6ea9eaf938d2dd24fb77ad8cce (diff)
downloadchromium_src-c031aeda4ec93a6939cd8ed9f2273fb4279238ac.zip
chromium_src-c031aeda4ec93a6939cd8ed9f2273fb4279238ac.tar.gz
chromium_src-c031aeda4ec93a6939cd8ed9f2273fb4279238ac.tar.bz2
views textfield: Handle ctrl and shift modifiers for Backspace and Delete
BUG=none TEST=NativeTextfieldViewsTest.InsertionDeletionTest Review URL: http://codereview.chromium.org/6119003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71041 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_views.cc28
-rw-r--r--views/controls/textfield/native_textfield_views.h1
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc32
3 files changed, 61 insertions, 0 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 677ada5..2a42c5a 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -464,10 +464,38 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
cursor_changed = true;
break;
case app::VKEY_BACK:
+ if (!model_->HasSelection()) {
+ if (selection && control) {
+ // If both shift and control are pressed, then erase upto the
+ // beginning of the buffer in ChromeOS. In windows, do nothing.
+#if defined(OS_WIN)
+ break;
+#else
+ model_->MoveCursorToStart(true);
+#endif
+ } else if (control) {
+ // If only control is pressed, then erase the previous word.
+ model_->MoveCursorToPreviousWord(true);
+ }
+ }
text_changed = model_->Backspace();
cursor_changed = true;
break;
case app::VKEY_DELETE:
+ if (!model_->HasSelection()) {
+ if (selection && control) {
+ // If both shift and control are pressed, then erase upto the
+ // end of the buffer in ChromeOS. In windows, do nothing.
+#if defined(OS_WIN)
+ break;
+#else
+ model_->MoveCursorToEnd(true);
+#endif
+ } else if (control) {
+ // If only control is pressed, then erase the next word.
+ model_->MoveCursorToNextWord(true);
+ }
+ }
text_changed = model_->Delete();
break;
case app::VKEY_INSERT:
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index 3c023ac..f87c42a 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -33,6 +33,7 @@ class TextfieldViewsModel;
// * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in
// chromeos, so we may not need them)
// * Double click to select word, and triple click to select all.
+// * Undo/Redo
class NativeTextfieldViews : public views::View,
public NativeTextfieldWrapper {
public:
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index efa7eb1..9fc883c 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -250,6 +250,38 @@ TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) {
textfield_->SelectAll();
SendKeyEventToTextfieldViews(app::VKEY_K);
EXPECT_STR_EQ("k", textfield_->text());
+
+ // Delete the previous word from cursor.
+ textfield_->SetText(ASCIIToUTF16("one two three four"));
+ SendKeyEventToTextfieldViews(app::VKEY_END);
+ SendKeyEventToTextfieldViews(app::VKEY_BACK, false, true, false);
+ EXPECT_STR_EQ("one two three ", textfield_->text());
+
+ // Delete upto the beginning of the buffer from cursor in chromeos, do nothing
+ // in windows.
+ SendKeyEventToTextfieldViews(app::VKEY_LEFT, false, true, false);
+ SendKeyEventToTextfieldViews(app::VKEY_BACK, true, true, false);
+#if defined(OS_WIN)
+ EXPECT_STR_EQ("one two three ", textfield_->text());
+#else
+ EXPECT_STR_EQ("three ", textfield_->text());
+#endif
+
+ // Delete the next word from cursor.
+ textfield_->SetText(ASCIIToUTF16("one two three four"));
+ SendKeyEventToTextfieldViews(app::VKEY_HOME);
+ SendKeyEventToTextfieldViews(app::VKEY_DELETE, false, true, false);
+ EXPECT_STR_EQ(" two three four", textfield_->text());
+
+ // Delete upto the end of the buffer from cursor in chromeos, do nothing
+ // in windows.
+ SendKeyEventToTextfieldViews(app::VKEY_RIGHT, false, true, false);
+ SendKeyEventToTextfieldViews(app::VKEY_DELETE, true, true, false);
+#if defined(OS_WIN)
+ EXPECT_STR_EQ(" two three four", textfield_->text());
+#else
+ EXPECT_STR_EQ(" two", textfield_->text());
+#endif
}
TEST_F(NativeTextfieldViewsTest, PasswordTest) {