mock_input_method.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright (c) 2012 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 "ui/base/ime/mock_input_method.h"
6
7namespace ui {
8
9MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
10    : text_input_client_(NULL) {
11}
12
13MockInputMethod::~MockInputMethod() {
14}
15
16void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) {
17}
18
19void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) {
20  if (text_input_client_ == client)
21    return;
22  text_input_client_ = client;
23  if (client)
24    OnTextInputTypeChanged(client);
25}
26
27TextInputClient* MockInputMethod::GetTextInputClient() const {
28  return text_input_client_;
29}
30
31bool MockInputMethod::DispatchKeyEvent(const base::NativeEvent& native_event) {
32  return false;
33}
34
35bool MockInputMethod::DispatchFabricatedKeyEvent(const ui::KeyEvent& event) {
36  return false;
37}
38
39void MockInputMethod::Init(bool focused) {
40}
41
42void MockInputMethod::OnFocus() {
43  FOR_EACH_OBSERVER(Observer, observer_list_, OnFocus());
44}
45
46void MockInputMethod::OnBlur() {
47  FOR_EACH_OBSERVER(Observer, observer_list_, OnBlur());
48}
49
50bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
51                                               NativeEventResult* result) {
52  FOR_EACH_OBSERVER(Observer, observer_list_, OnUntranslatedIMEMessage(event));
53  if (result)
54    *result = NativeEventResult();
55  return false;
56}
57
58void MockInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {
59  FOR_EACH_OBSERVER(Observer, observer_list_, OnTextInputTypeChanged(client));
60  FOR_EACH_OBSERVER(Observer, observer_list_, OnTextInputStateChanged(client));
61}
62
63void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {
64  FOR_EACH_OBSERVER(Observer, observer_list_, OnCaretBoundsChanged(client));
65}
66
67void MockInputMethod::CancelComposition(const TextInputClient* client) {
68}
69
70void MockInputMethod::OnInputLocaleChanged() {
71  FOR_EACH_OBSERVER(Observer, observer_list_, OnInputLocaleChanged());
72}
73
74std::string MockInputMethod::GetInputLocale() {
75  return "";
76}
77
78base::i18n::TextDirection MockInputMethod::GetInputTextDirection() {
79  return base::i18n::UNKNOWN_DIRECTION;
80}
81
82bool MockInputMethod::IsActive() {
83  return true;
84}
85
86ui::TextInputType MockInputMethod::GetTextInputType() const {
87  return ui::TEXT_INPUT_TYPE_NONE;
88}
89
90bool MockInputMethod::CanComposeInline() const {
91  return true;
92}
93
94bool MockInputMethod::IsCandidatePopupOpen() const {
95  return false;
96}
97
98void MockInputMethod::AddObserver(InputMethodObserver* observer) {
99  observer_list_.AddObserver(static_cast<Observer*>(observer));
100}
101
102void MockInputMethod::RemoveObserver(InputMethodObserver* observer) {
103  observer_list_.RemoveObserver(static_cast<Observer*>(observer));
104}
105
106}  // namespace ui
107