summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-04 21:58:26 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-04 21:58:26 +0000
commit05ac486c5a2931027f23d816c244ef20f1c2e0b8 (patch)
treee5ae27e1e8a3fc14f5e52f3569d973b57d45d28a /views
parentf1881430dda113b144fba5e3ee849e06b5d6049e (diff)
downloadchromium_src-05ac486c5a2931027f23d816c244ef20f1c2e0b8.zip
chromium_src-05ac486c5a2931027f23d816c244ef20f1c2e0b8.tar.gz
chromium_src-05ac486c5a2931027f23d816c244ef20f1c2e0b8.tar.bz2
views: Fix shifted keyevents in textfield.
Pressing 0-9 in a textfield with caps lock turned on would generate shifted keyevents, which it shouldn't. So distinguish between caps-lock and shift. BUG=none TEST=none Review URL: http://codereview.chromium.org/6068005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_views.cc5
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc21
2 files changed, 22 insertions, 4 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 5ea8b23..df45d99 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -485,7 +485,8 @@ char16 NativeTextfieldViews::GetPrintableChar(const KeyEvent& key_event) {
// TODO(oshima): IME, i18n support.
// This only works for UCS-2 characters.
app::KeyboardCode key_code = key_event.GetKeyCode();
- bool shift = key_event.IsShiftDown() ^ key_event.IsCapsLockDown();
+ bool shift = key_event.IsShiftDown();
+ bool upper = shift ^ key_event.IsCapsLockDown();
// TODO(oshima): We should have a utility function
// under app to convert a KeyboardCode to a printable character,
// probably in keyboard_code_conversion{.h, _x
@@ -569,7 +570,7 @@ char16 NativeTextfieldViews::GetPrintableChar(const KeyEvent& key_event) {
case app::VKEY_X:
case app::VKEY_Y:
case app::VKEY_Z:
- return (shift ? 'A' : 'a') + (key_code - app::VKEY_A);
+ return (upper ? 'A' : 'a') + (key_code - app::VKEY_A);
case app::VKEY_OEM_1:
return shift ? ':' : ';';
case app::VKEY_OEM_PLUS:
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index eecac8e..08ad9ab 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -73,13 +73,21 @@ class NativeTextfieldViewsTest : public ::testing::Test,
bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code,
bool shift,
- bool control) {
+ bool control,
+ bool capslock) {
int flags = (shift ? KeyEvent::EF_SHIFT_DOWN : 0) |
- (control ? KeyEvent::EF_CONTROL_DOWN : 0);
+ (control ? KeyEvent::EF_CONTROL_DOWN : 0) |
+ (capslock ? KeyEvent::EF_CAPS_LOCK_DOWN : 0);
KeyEvent event(KeyEvent::ET_KEY_PRESSED, key_code, flags, 1, 0);
return textfield_view_->OnKeyPressed(event);
}
+ bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code,
+ bool shift,
+ bool control) {
+ return SendKeyEventToTextfieldViews(key_code, shift, control, false);
+ }
+
bool SendKeyEventToTextfieldViews(app::KeyboardCode key_code) {
return SendKeyEventToTextfieldViews(key_code, false, false);
}
@@ -140,6 +148,15 @@ TEST_F(NativeTextfieldViewsTest, KeyTest) {
SendKeyEventToTextfieldViews(app::VKEY_R, false, false);
EXPECT_STR_EQ("Cr", textfield_->text());
EXPECT_STR_EQ("Cr", last_contents_);
+
+ textfield_->SetText(ASCIIToUTF16(""));
+ SendKeyEventToTextfieldViews(app::VKEY_C, true, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_C, false, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_1, false, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_1, true, false, true);
+ SendKeyEventToTextfieldViews(app::VKEY_1, true, false, false);
+ EXPECT_STR_EQ("cC1!!", textfield_->text());
+ EXPECT_STR_EQ("cC1!!", last_contents_);
}
TEST_F(NativeTextfieldViewsTest, ControlAndSelectTest) {