OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 | 8 |
9 MSVC_PUSH_WARNING_LEVEL(0); | 9 MSVC_PUSH_WARNING_LEVEL(0); |
10 #include "EventTarget.h" | 10 #include "EventTarget.h" |
11 #include "KeyboardCodes.h" | 11 #include "KeyboardCodes.h" |
12 #include "KeyboardEvent.h" | 12 #include "KeyboardEvent.h" |
13 MSVC_POP_WARNING(); | 13 MSVC_POP_WARNING(); |
14 | 14 |
15 #undef LOG | 15 #undef LOG |
16 | 16 |
| 17 #include "base/string_util.h" |
17 #include "webkit/glue/editor_client_impl.h" | 18 #include "webkit/glue/editor_client_impl.h" |
18 #include "webkit/glue/event_conversion.h" | 19 #include "webkit/glue/event_conversion.h" |
19 #include "webkit/glue/webinputevent.h" | 20 #include "webkit/glue/webinputevent.h" |
| 21 #include "webkit/glue/webinputevent_util.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
22 using WebCore::PlatformKeyboardEvent; | 24 using WebCore::PlatformKeyboardEvent; |
23 using WebCore::KeyboardEvent; | 25 using WebCore::KeyboardEvent; |
24 | 26 |
25 class KeyboardTest : public testing::Test { | 27 class KeyboardTest : public testing::Test { |
26 public: | 28 public: |
27 void SetUp() { | 29 void SetUp() { |
28 WTF::initializeThreading(); | 30 WTF::initializeThreading(); |
29 } | 31 } |
30 | 32 |
31 // Pass a WebKeyboardEvent into the EditorClient and get back the string | 33 // Pass a WebKeyboardEvent into the EditorClient and get back the string |
32 // name of which editing event that key causes. | 34 // name of which editing event that key causes. |
33 // E.g., sending in the enter key gives back "InsertNewline". | 35 // E.g., sending in the enter key gives back "InsertNewline". |
34 const char* InterpretKeyEvent( | 36 const char* InterpretKeyEvent( |
35 const WebKeyboardEvent& keyboard_event, | 37 const WebKeyboardEvent& keyboard_event, |
36 PlatformKeyboardEvent::Type key_type) { | 38 PlatformKeyboardEvent::Type key_type) { |
37 EditorClientImpl editor_impl(NULL); | 39 EditorClientImpl editor_impl(NULL); |
38 | 40 |
39 MakePlatformKeyboardEvent evt(keyboard_event); | 41 MakePlatformKeyboardEvent evt(keyboard_event); |
40 evt.SetKeyType(key_type); | 42 evt.SetKeyType(key_type); |
41 RefPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(evt, NULL); | 43 RefPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(evt, NULL); |
42 return editor_impl.interpretKeyEvent(keyboardEvent.get()); | 44 return editor_impl.interpretKeyEvent(keyboardEvent.get()); |
43 } | 45 } |
44 | 46 |
45 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. | 47 // Set up a WebKeyboardEvent KEY_DOWN event with key code and modifiers. |
46 void SetupKeyDownEvent(WebKeyboardEvent* keyboard_event, | 48 void SetupKeyDownEvent(WebKeyboardEvent* keyboard_event, |
47 char key_code, | 49 char key_code, |
48 int modifiers) { | 50 int modifiers) { |
49 keyboard_event->key_code = key_code; | 51 keyboard_event->windows_key_code = key_code; |
50 keyboard_event->modifiers = modifiers; | 52 keyboard_event->modifiers = modifiers; |
51 keyboard_event->type = WebInputEvent::KEY_DOWN; | 53 keyboard_event->type = WebInputEvent::KEY_DOWN; |
52 #if defined(OS_LINUX) | 54 keyboard_event->text[0] = key_code; |
53 keyboard_event->text = key_code; | 55 std::string key_identifier_str = |
54 #elif defined(OS_MACOSX) | 56 webkit_glue::GetKeyIdentifierForWindowsKeyCode(key_code); |
55 keyboard_event->text.clear(); | 57 base::strlcpy(keyboard_event->key_identifier, key_identifier_str.c_str(), |
56 keyboard_event->text.push_back(key_code); | 58 kIdentifierLengthCap); |
57 #endif | |
58 } | 59 } |
59 | 60 |
60 // Like InterpretKeyEvent, but with pressing down OSModifier+|key_code|. | 61 // Like InterpretKeyEvent, but with pressing down OSModifier+|key_code|. |
61 // OSModifier is the platform's standard modifier key: control on most | 62 // OSModifier is the platform's standard modifier key: control on most |
62 // platforms, but meta (command) on Mac. | 63 // platforms, but meta (command) on Mac. |
63 const char* InterpretOSModifierKeyPress(char key_code) { | 64 const char* InterpretOSModifierKeyPress(char key_code) { |
64 WebKeyboardEvent keyboard_event; | 65 WebKeyboardEvent keyboard_event; |
65 #if defined(OS_WIN) || defined(OS_LINUX) | 66 #if defined(OS_WIN) || defined(OS_LINUX) |
66 WebInputEvent::Modifiers os_modifier = WebInputEvent::CTRL_KEY; | 67 WebInputEvent::Modifiers os_modifier = WebInputEvent::CTRL_KEY; |
67 #elif defined(OS_MACOSX) | 68 #elif defined(OS_MACOSX) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 156 |
156 TEST_F(KeyboardTest, TestInsertNewline3) { | 157 TEST_F(KeyboardTest, TestInsertNewline3) { |
157 EXPECT_STREQ("InsertNewline", InterpretNewLine(WebInputEvent::ALT_KEY)); | 158 EXPECT_STREQ("InsertNewline", InterpretNewLine(WebInputEvent::ALT_KEY)); |
158 } | 159 } |
159 | 160 |
160 TEST_F(KeyboardTest, TestInsertNewline4) { | 161 TEST_F(KeyboardTest, TestInsertNewline4) { |
161 int modifiers = WebInputEvent::ALT_KEY | WebInputEvent::SHIFT_KEY; | 162 int modifiers = WebInputEvent::ALT_KEY | WebInputEvent::SHIFT_KEY; |
162 const char* result = InterpretNewLine(modifiers); | 163 const char* result = InterpretNewLine(modifiers); |
163 EXPECT_STREQ("InsertNewline", result); | 164 EXPECT_STREQ("InsertNewline", result); |
164 } | 165 } |
OLD | NEW |