Commit f8ecc8d0 authored by msw@chromium.org's avatar msw@chromium.org

Make Views Textfield key handling execute commands.

Add commands similar to WebKit text editing commands.
Translate key events to commands for textfield execution.
Consolidate key handling and command execution code.
Fix unit tests.

Modify Windows behavior for CTRL+SHIFT+[BACK|DEL].
(now behaves the same as CTRL+[BACK|DEL], not no-op)

BUG=319437
TEST=No behavior changes except for CTRL+SHIFT+[BACK|DEL] on Windows.
R=oshima@chromium.org, erg@chromium.org

Review URL: https://codereview.chromium.org/211593006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260310 0039d316-1c4b-4281-b951-d872f2087c98
parent c7ae9787
...@@ -1878,7 +1878,7 @@ need to be translated for each locale.--> ...@@ -1878,7 +1878,7 @@ need to be translated for each locale.-->
Scroll Down Scroll Down
</message> </message>
<!-- Edit field context menu item labels. --> <!-- Textfield context menu item labels. -->
<message name="IDS_APP_UNDO" desc="The text label of the Undo menu item"> <message name="IDS_APP_UNDO" desc="The text label of the Undo menu item">
&amp;Undo &amp;Undo
</message> </message>
...@@ -1898,6 +1898,66 @@ need to be translated for each locale.--> ...@@ -1898,6 +1898,66 @@ need to be translated for each locale.-->
Select &amp;all Select &amp;all
</message> </message>
<!-- Textfield editing commands; their actual string contents are unused. -->
<!-- These match third_party/WebKit/Source/core/editing/EditorCommand.cpp. -->
<message name="IDS_DELETE_BACKWARD" desc="A command to delete backward.">
Delete Backward
</message>
<message name="IDS_DELETE_FORWARD" desc="A command to delete forward.">
Delete Forward
</message>
<message name="IDS_DELETE_TO_BEGINNING_OF_LINE" desc="A command to delete to the beginning of the line.">
Delete To Beginning Of Line
</message>
<message name="IDS_DELETE_TO_END_OF_LINE" desc="A command to delete to the end of the line.">
Delete To End Of Line
</message>
<message name="IDS_DELETE_WORD_BACKWARD" desc="A command to delete backward by a word.">
Delete Word Backward
</message>
<message name="IDS_DELETE_WORD_FORWARD" desc="A command to delete forward by a word.">
Delete Word Forward
</message>
<message name="IDS_MOVE_LEFT" desc="A command to move the cursor left.">
Move Left
</message>
<message name="IDS_MOVE_LEFT_AND_MODIFY_SELECTION" desc="A command to move the cursor left and modify the selection.">
Move Left And Modify Selection
</message>
<message name="IDS_MOVE_RIGHT" desc="A command to move the cursor right.">
Move Right
</message>
<message name="IDS_MOVE_RIGHT_AND_MODIFY_SELECTION" desc="A command to move the cursor right and modify the selection.">
Move Right And Modify Selection
</message>
<message name="IDS_MOVE_WORD_LEFT" desc="A command to move the cursor left to the next word break.">
Move Word Left
</message>
<message name="IDS_MOVE_WORD_LEFT_AND_MODIFY_SELECTION" desc="A command to move the cursor left to the next word break and modify the selection.">
Move Word Left And Modify Selection
</message>
<message name="IDS_MOVE_WORD_RIGHT" desc="A command to move the cursor right to the next word break.">
Move Word Right
</message>
<message name="IDS_MOVE_WORD_RIGHT_AND_MODIFY_SELECTION" desc="A command to move the cursor right to the next word break and modify the selection.">
Move Word Right And Modify Selection
</message>
<message name="IDS_MOVE_TO_BEGINNING_OF_LINE" desc="A command to move the cursor to the beginning of the line.">
Move To Beginning Of Line
</message>
<message name="IDS_MOVE_TO_BEGINNING_OF_LINE_AND_MODIFY_SELECTION" desc="A command to move the cursor to the beginning of the line and modify the selection.">
Move To Beginning Of Line And Modify Selection
</message>
<message name="IDS_MOVE_TO_END_OF_LINE" desc="A command to move the cursor to the end of the line.">
Move To End Of Line
</message>
<message name="IDS_MOVE_TO_END_OF_LINE_AND_MODIFY_SELECTION" desc="A command to move the cursor to the end of the line and modify the selection.">
Move To End Of Line And Modify Selection
</message>
<message name="IDS_APP_REDO" desc="A command to redo an action.">
Redo
</message>
<!-- Generic terms --> <!-- Generic terms -->
<message name="IDS_APP_OK" desc="Used for Ok on buttons"> <message name="IDS_APP_OK" desc="Used for Ok on buttons">
OK OK
......
This diff is collapsed.
...@@ -430,13 +430,13 @@ TEST_F(TextfieldTest, InsertionDeletionTest) { ...@@ -430,13 +430,13 @@ TEST_F(TextfieldTest, InsertionDeletionTest) {
SendKeyEvent(ui::VKEY_BACK, false, false, true, false); SendKeyEvent(ui::VKEY_BACK, false, false, true, false);
EXPECT_STR_EQ("one two three ", textfield_->text()); EXPECT_STR_EQ("one two three ", textfield_->text());
// Delete to a line break on Linux and ChromeOS, no-op on Windows. // Delete to a line break on Linux and ChromeOS, to a word break on Windows.
SendKeyEvent(ui::VKEY_LEFT, false, false, true, false); SendKeyEvent(ui::VKEY_LEFT, false, false, true, false);
SendKeyEvent(ui::VKEY_BACK, false, true, true, false); SendKeyEvent(ui::VKEY_BACK, false, true, true, false);
#if defined(OS_LINUX) #if defined(OS_LINUX)
EXPECT_STR_EQ("three ", textfield_->text()); EXPECT_STR_EQ("three ", textfield_->text());
#else #else
EXPECT_STR_EQ("one two three ", textfield_->text()); EXPECT_STR_EQ("one three ", textfield_->text());
#endif #endif
// Delete the next word from cursor. // Delete the next word from cursor.
...@@ -445,13 +445,13 @@ TEST_F(TextfieldTest, InsertionDeletionTest) { ...@@ -445,13 +445,13 @@ TEST_F(TextfieldTest, InsertionDeletionTest) {
SendKeyEvent(ui::VKEY_DELETE, false, false, true, false); SendKeyEvent(ui::VKEY_DELETE, false, false, true, false);
EXPECT_STR_EQ(" two three four", textfield_->text()); EXPECT_STR_EQ(" two three four", textfield_->text());
// Delete to a line break on Linux and ChromeOS, no-op on Windows. // Delete to a line break on Linux and ChromeOS, to a word break on Windows.
SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false); SendKeyEvent(ui::VKEY_RIGHT, false, false, true, false);
SendKeyEvent(ui::VKEY_DELETE, false, true, true, false); SendKeyEvent(ui::VKEY_DELETE, false, true, true, false);
#if defined(OS_LINUX) #if defined(OS_LINUX)
EXPECT_STR_EQ(" two", textfield_->text()); EXPECT_STR_EQ(" two", textfield_->text());
#else #else
EXPECT_STR_EQ(" two three four", textfield_->text()); EXPECT_STR_EQ(" two four", textfield_->text());
#endif #endif
} }
...@@ -523,61 +523,45 @@ TEST_F(TextfieldTest, TextInputType) { ...@@ -523,61 +523,45 @@ TEST_F(TextfieldTest, TextInputType) {
TEST_F(TextfieldTest, OnKeyPressReturnValueTest) { TEST_F(TextfieldTest, OnKeyPressReturnValueTest) {
InitTextfield(); InitTextfield();
// Character keys will be handled by input method. // Character keys are handled by the input method.
SendKeyEvent(ui::VKEY_A); SendKeyEvent(ui::VKEY_A);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_FALSE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
// Home will be handled. // Arrow keys and home/end are handled by the textfield.
SendKeyEvent(ui::VKEY_HOME); SendKeyEvent(ui::VKEY_LEFT);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_TRUE(textfield_->key_handled()); EXPECT_TRUE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
// F24, up/down key won't be handled. SendKeyEvent(ui::VKEY_RIGHT);
SendKeyEvent(ui::VKEY_F24);
EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled());
textfield_->clear();
SendKeyEvent(ui::VKEY_UP);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_TRUE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
SendKeyEvent(ui::VKEY_DOWN); SendKeyEvent(ui::VKEY_HOME);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_TRUE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
// Empty Textfield does not handle left/right. SendKeyEvent(ui::VKEY_END);
textfield_->SetText(base::string16());
SendKeyEvent(ui::VKEY_LEFT);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_TRUE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
SendKeyEvent(ui::VKEY_RIGHT); // F24, up/down key won't be handled.
SendKeyEvent(ui::VKEY_F24);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_FALSE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
// Add a char. Right key should not be handled when cursor is at the end. SendKeyEvent(ui::VKEY_UP);
SendKeyEvent(ui::VKEY_B);
SendKeyEvent(ui::VKEY_RIGHT);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_FALSE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
// First left key is handled to move cursor left to the beginning. SendKeyEvent(ui::VKEY_DOWN);
SendKeyEvent(ui::VKEY_LEFT);
EXPECT_TRUE(textfield_->key_received());
EXPECT_TRUE(textfield_->key_handled());
textfield_->clear();
// Now left key should not be handled.
SendKeyEvent(ui::VKEY_LEFT);
EXPECT_TRUE(textfield_->key_received()); EXPECT_TRUE(textfield_->key_received());
EXPECT_FALSE(textfield_->key_handled()); EXPECT_FALSE(textfield_->key_handled());
textfield_->clear(); textfield_->clear();
...@@ -1106,8 +1090,8 @@ TEST_F(TextfieldTest, TextInputClientTest) { ...@@ -1106,8 +1090,8 @@ TEST_F(TextfieldTest, TextInputClientTest) {
EXPECT_TRUE(client->GetCompositionTextRange(&range)); EXPECT_TRUE(client->GetCompositionTextRange(&range));
EXPECT_STR_EQ("0321456789", textfield_->text()); EXPECT_STR_EQ("0321456789", textfield_->text());
EXPECT_EQ(gfx::Range(1, 4), range); EXPECT_EQ(gfx::Range(1, 4), range);
EXPECT_EQ(2, on_before_user_action_); EXPECT_EQ(1, on_before_user_action_);
EXPECT_EQ(2, on_after_user_action_); EXPECT_EQ(1, on_after_user_action_);
input_method_->SetResultTextForNextKey(UTF8ToUTF16("123")); input_method_->SetResultTextForNextKey(UTF8ToUTF16("123"));
on_before_user_action_ = on_after_user_action_ = 0; on_before_user_action_ = on_after_user_action_ = 0;
...@@ -1118,8 +1102,8 @@ TEST_F(TextfieldTest, TextInputClientTest) { ...@@ -1118,8 +1102,8 @@ TEST_F(TextfieldTest, TextInputClientTest) {
EXPECT_FALSE(client->HasCompositionText()); EXPECT_FALSE(client->HasCompositionText());
EXPECT_FALSE(input_method_->cancel_composition_called()); EXPECT_FALSE(input_method_->cancel_composition_called());
EXPECT_STR_EQ("0123456789", textfield_->text()); EXPECT_STR_EQ("0123456789", textfield_->text());
EXPECT_EQ(2, on_before_user_action_); EXPECT_EQ(1, on_before_user_action_);
EXPECT_EQ(2, on_after_user_action_); EXPECT_EQ(1, on_after_user_action_);
input_method_->Clear(); input_method_->Clear();
input_method_->SetCompositionTextForNextKey(composition); input_method_->SetCompositionTextForNextKey(composition);
......
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