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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 {L"0000041e", MockKeyboard::LAYOUT_THAI}, | 93 {L"0000041e", MockKeyboard::LAYOUT_THAI}, |
94 {L"0000041d", MockKeyboard::LAYOUT_SWEDISH}, | 94 {L"0000041d", MockKeyboard::LAYOUT_SWEDISH}, |
95 {L"0000041f", MockKeyboard::LAYOUT_TURKISH_Q}, | 95 {L"0000041f", MockKeyboard::LAYOUT_TURKISH_Q}, |
96 {L"0000042a", MockKeyboard::LAYOUT_VIETNAMESE}, | 96 {L"0000042a", MockKeyboard::LAYOUT_VIETNAMESE}, |
97 {L"00000439", MockKeyboard::LAYOUT_DEVANAGARI_INSCRIPT}, | 97 {L"00000439", MockKeyboard::LAYOUT_DEVANAGARI_INSCRIPT}, |
98 {L"00000816", MockKeyboard::LAYOUT_PORTUGUESE}, | 98 {L"00000816", MockKeyboard::LAYOUT_PORTUGUESE}, |
99 {L"00001409", MockKeyboard::LAYOUT_UNITED_STATES_DVORAK}, | 99 {L"00001409", MockKeyboard::LAYOUT_UNITED_STATES_DVORAK}, |
100 {L"00001009", MockKeyboard::LAYOUT_CANADIAN_FRENCH}, | 100 {L"00001009", MockKeyboard::LAYOUT_CANADIAN_FRENCH}, |
101 }; | 101 }; |
102 | 102 |
103 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLanguageIDs); ++i) { | 103 for (size_t i = 0; i < arraysize(kLanguageIDs); ++i) { |
104 if (layout == kLanguageIDs[i].keyboard_layout) { | 104 if (layout == kLanguageIDs[i].keyboard_layout) { |
105 HKL new_keyboard_layout = LoadKeyboardLayout(kLanguageIDs[i].language, | 105 HKL new_keyboard_layout = LoadKeyboardLayout(kLanguageIDs[i].language, |
106 KLF_ACTIVATE); | 106 KLF_ACTIVATE); |
107 // loaded_keyboard_layout_ must always have a valid keyboard handle | 107 // loaded_keyboard_layout_ must always have a valid keyboard handle |
108 // so we only assign upon success. | 108 // so we only assign upon success. |
109 if (new_keyboard_layout) { | 109 if (new_keyboard_layout) { |
110 active_keyboard_layout_ = new_keyboard_layout; | 110 active_keyboard_layout_ = new_keyboard_layout; |
111 return true; | 111 return true; |
112 } | 112 } |
113 | 113 |
(...skipping 19 matching lines...) Expand all Loading... |
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_UNSAFE(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 | 149 |
150 return true; | 150 return true; |
151 } | 151 } |
152 | 152 |
153 int MockKeyboardDriverWin::GetCharacters(int key_code, | 153 int MockKeyboardDriverWin::GetCharacters(int key_code, |
154 std::wstring* output) { | 154 std::wstring* output) { |
155 // Retrieve Unicode characters composed from the input key-code and | 155 // Retrieve Unicode characters composed from the input key-code and |
156 // the mofifiers. | 156 // the mofifiers. |
157 CHECK(output); | 157 CHECK(output); |
158 wchar_t code[16]; | 158 wchar_t code[16]; |
159 int length = ToUnicodeEx(key_code, MapVirtualKey(key_code, 0), | 159 int length = ToUnicodeEx(key_code, MapVirtualKey(key_code, 0), |
160 &keyboard_states_[0], &code[0], arraysize(code), 0, | 160 &keyboard_states_[0], &code[0], arraysize(code), 0, |
161 active_keyboard_layout_); | 161 active_keyboard_layout_); |
162 if (length > 0) | 162 if (length > 0) |
163 output->assign(code); | 163 output->assign(code); |
164 return length; | 164 return length; |
165 } | 165 } |
166 | 166 |
167 } // namespace content | 167 } // namespace content |
OLD | NEW |