OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/test/mock_keyboard_driver_win.h" | 5 #include "content/test/mock_keyboard_driver_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/test/mock_keyboard.h" | 9 #include "content/test/mock_keyboard.h" |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 return false; | 114 return false; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 // Return false if there are not any matching drivers. | 118 // Return false if there are not any matching drivers. |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 bool MockKeyboardDriverWin::SetModifiers(int modifiers) { | 122 void MockKeyboardDriverWin::SetModifiers(int modifiers) { |
123 // Over-write the keyboard status with our modifier-key status. | 123 // Over-write the keyboard status with our modifier-key status. |
124 // WebInputEventFactory::keyboardEvent() uses GetKeyState() to retrive | 124 // WebInputEventFactory::keyboardEvent() uses GetKeyState() to retrive |
125 // modifier-key status. So, we update the modifier-key status with this | 125 // modifier-key status. So, we update the modifier-key status with this |
126 // SetKeyboardState() call before creating NativeWebKeyboardEvent | 126 // SetKeyboardState() call before creating NativeWebKeyboardEvent |
127 // instances. | 127 // instances. |
128 memset(&keyboard_states_[0], 0, sizeof(keyboard_states_)); | 128 memset(&keyboard_states_[0], 0, sizeof(keyboard_states_)); |
129 static const struct { | 129 static const struct { |
130 int key_code; | 130 int key_code; |
131 int mask; | 131 int mask; |
132 } kModifierMasks[] = { | 132 } kModifierMasks[] = { |
133 {VK_SHIFT, MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT}, | 133 {VK_SHIFT, MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT}, |
134 {VK_CONTROL, MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL}, | 134 {VK_CONTROL, MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL}, |
135 {VK_MENU, MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT}, | 135 {VK_MENU, MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT}, |
136 {VK_LSHIFT, MockKeyboard::LEFT_SHIFT}, | 136 {VK_LSHIFT, MockKeyboard::LEFT_SHIFT}, |
137 {VK_LCONTROL, MockKeyboard::LEFT_CONTROL}, | 137 {VK_LCONTROL, MockKeyboard::LEFT_CONTROL}, |
138 {VK_LMENU, MockKeyboard::LEFT_ALT}, | 138 {VK_LMENU, MockKeyboard::LEFT_ALT}, |
139 {VK_RSHIFT, MockKeyboard::RIGHT_SHIFT}, | 139 {VK_RSHIFT, MockKeyboard::RIGHT_SHIFT}, |
140 {VK_RCONTROL, MockKeyboard::RIGHT_CONTROL}, | 140 {VK_RCONTROL, MockKeyboard::RIGHT_CONTROL}, |
141 {VK_RMENU, MockKeyboard::RIGHT_ALT}, | 141 {VK_RMENU, MockKeyboard::RIGHT_ALT}, |
142 }; | 142 }; |
143 for (size_t i = 0; i < arraysize(kModifierMasks); ++i) { | 143 for (size_t i = 0; i < arraysize(kModifierMasks); ++i) { |
144 const int kKeyDownMask = 0x80; | 144 const int kKeyDownMask = 0x80; |
145 if (modifiers & kModifierMasks[i].mask) | 145 if (modifiers & kModifierMasks[i].mask) |
146 keyboard_states_[kModifierMasks[i].key_code] = kKeyDownMask; | 146 keyboard_states_[kModifierMasks[i].key_code] = kKeyDownMask; |
147 } | 147 } |
148 SetKeyboardState(&keyboard_states_[0]); | 148 SetKeyboardState(&keyboard_states_[0]); |
149 | |
150 return true; | |
151 } | 149 } |
152 | 150 |
153 int MockKeyboardDriverWin::GetCharacters(int key_code, | 151 int MockKeyboardDriverWin::GetCharacters(int key_code, |
154 std::wstring* output) { | 152 std::wstring* output) const { |
155 // Retrieve Unicode characters composed from the input key-code and | 153 // Retrieve Unicode characters composed from the input key-code and |
156 // the mofifiers. | 154 // the mofifiers. |
157 CHECK(output); | 155 CHECK(output); |
158 wchar_t code[16]; | 156 wchar_t code[16]; |
159 int length = ToUnicodeEx(key_code, MapVirtualKey(key_code, 0), | 157 int length = ToUnicodeEx(key_code, MapVirtualKey(key_code, 0), |
160 &keyboard_states_[0], &code[0], arraysize(code), 0, | 158 &keyboard_states_[0], &code[0], arraysize(code), 0, |
161 active_keyboard_layout_); | 159 active_keyboard_layout_); |
162 if (length > 0) | 160 if (length > 0) |
163 output->assign(code); | 161 output->assign(code); |
164 return length; | 162 return length; |
165 } | 163 } |
166 | 164 |
167 } // namespace content | 165 } // namespace content |
OLD | NEW |