| 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.h" | 5 #include "content/test/mock_keyboard.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 MockKeyboard::MockKeyboard() | 11 MockKeyboard::MockKeyboard() |
| 12 : keyboard_layout_(LAYOUT_NULL), | 12 : keyboard_layout_(LAYOUT_NULL), |
| 13 keyboard_modifiers_(INVALID) { | 13 keyboard_modifiers_(INVALID) { |
| 14 } | 14 } |
| 15 | 15 |
| 16 MockKeyboard::~MockKeyboard() { | 16 MockKeyboard::~MockKeyboard() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 int MockKeyboard::GetCharacters(Layout layout, | 19 bool MockKeyboard::Update(Layout layout, Modifiers modifiers) { |
| 20 int key_code, | |
| 21 Modifiers modifiers, | |
| 22 std::wstring* output) { | |
| 23 #if defined(OS_WIN) | |
| 24 CHECK(output); | |
| 25 // Change the keyboard layout only when we have to because it takes a lot of | 20 // Change the keyboard layout only when we have to because it takes a lot of |
| 26 // time to load a keyboard-layout driver. | 21 // time to load a keyboard-layout driver. |
| 27 // When we change the layout, we reset the modifier status to force updating | 22 // When we change the layout, we reset the modifier status to force updating |
| 28 // the keyboard status. | 23 // the keyboard status. |
| 29 if (layout != keyboard_layout_) { | 24 if (layout != keyboard_layout_) { |
| 25 #if defined(OS_WIN) |
| 30 if (!driver_.SetLayout(layout)) | 26 if (!driver_.SetLayout(layout)) |
| 31 return -1; | 27 return false; |
| 28 #endif |
| 32 keyboard_layout_ = layout; | 29 keyboard_layout_ = layout; |
| 33 keyboard_modifiers_ = INVALID; | 30 keyboard_modifiers_ = INVALID; |
| 34 } | 31 } |
| 35 | 32 |
| 36 // Update the keyboard states. | 33 // Update the keyboard states. |
| 37 if (modifiers != keyboard_modifiers_) { | 34 if (modifiers != keyboard_modifiers_) { |
| 38 if (!driver_.SetModifiers(modifiers)) | 35 #if defined(OS_WIN) |
| 39 return -1; | 36 driver_.SetModifiers(modifiers); |
| 37 #endif |
| 40 keyboard_modifiers_ = modifiers; | 38 keyboard_modifiers_ = modifiers; |
| 41 } | 39 } |
| 42 | 40 |
| 41 return true; |
| 42 } |
| 43 |
| 44 int MockKeyboard::GetCharacters(int key_code, std::wstring* output) const { |
| 45 #if defined(OS_WIN) |
| 46 CHECK(output); |
| 43 // Retrieve Unicode characters associate with the key code. | 47 // Retrieve Unicode characters associate with the key code. |
| 44 return driver_.GetCharacters(key_code, output); | 48 return driver_.GetCharacters(key_code, output); |
| 45 #else | 49 #else |
| 46 NOTIMPLEMENTED(); | 50 NOTIMPLEMENTED(); |
| 47 return -1; | 51 return -1; |
| 48 #endif | 52 #endif |
| 49 } | 53 } |
| 50 | 54 |
| 51 } // namespace content | 55 } // namespace content |
| OLD | NEW |