| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/renderer/mock_keyboard.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 MockKeyboard::MockKeyboard() | |
| 10 : keyboard_layout_(LAYOUT_NULL), | |
| 11 keyboard_modifiers_(INVALID) { | |
| 12 } | |
| 13 | |
| 14 MockKeyboard::~MockKeyboard() { | |
| 15 } | |
| 16 | |
| 17 int MockKeyboard::GetCharacters(Layout layout, | |
| 18 int key_code, | |
| 19 Modifiers modifiers, | |
| 20 std::wstring* output) { | |
| 21 #if defined(OS_WIN) | |
| 22 CHECK(output); | |
| 23 // Change the keyboard layout only when we have to because it takes a lot of | |
| 24 // time to load a keyboard-layout driver. | |
| 25 // When we change the layout, we reset the modifier status to force updating | |
| 26 // the keyboard status. | |
| 27 if (layout != keyboard_layout_) { | |
| 28 if (!driver_.SetLayout(layout)) | |
| 29 return -1; | |
| 30 keyboard_layout_ = layout; | |
| 31 keyboard_modifiers_ = INVALID; | |
| 32 } | |
| 33 | |
| 34 // Update the keyboard states. | |
| 35 if (modifiers != keyboard_modifiers_) { | |
| 36 if (!driver_.SetModifiers(modifiers)) | |
| 37 return -1; | |
| 38 keyboard_modifiers_ = modifiers; | |
| 39 } | |
| 40 | |
| 41 // Retrieve Unicode characters associate with the key code. | |
| 42 return driver_.GetCharacters(key_code, output); | |
| 43 #else | |
| 44 NOTIMPLEMENTED(); | |
| 45 return -1; | |
| 46 #endif | |
| 47 } | |
| OLD | NEW |