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
3// found in the LICENSE file.
4
5#include "content/test/mock_keyboard.h"
6
7#include "base/logging.h"
8
9namespace content {
10
11MockKeyboard::MockKeyboard()
12    : keyboard_layout_(LAYOUT_NULL),
13      keyboard_modifiers_(INVALID) {
14}
15
16MockKeyboard::~MockKeyboard() {
17}
18
19int MockKeyboard::GetCharacters(Layout layout,
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
26  // time to load a keyboard-layout driver.
27  // When we change the layout, we reset the modifier status to force updating
28  // the keyboard status.
29  if (layout != keyboard_layout_) {
30    if (!driver_.SetLayout(layout))
31      return -1;
32    keyboard_layout_ = layout;
33    keyboard_modifiers_ = INVALID;
34  }
35
36  // Update the keyboard states.
37  if (modifiers != keyboard_modifiers_) {
38    if (!driver_.SetModifiers(modifiers))
39      return -1;
40    keyboard_modifiers_ = modifiers;
41  }
42
43  // Retrieve Unicode characters associate with the key code.
44  return driver_.GetCharacters(key_code, output);
45#else
46  NOTIMPLEMENTED();
47  return -1;
48#endif
49}
50
51}  // namespace content
52