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
7#include "ui/base/ime/text_input_focus_manager.h"
8#include "ui/base/ui_base_switches_util.h"
9
10namespace ui {
11
12MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
13    : text_input_client_(NULL) {
14}
15
16MockInputMethod::~MockInputMethod() {
17}
18
19void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) {
20}
21
22void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) {
23  if (switches::IsTextInputFocusManagerEnabled())
24    return;
25
26  if (text_input_client_ == client)
27    return;
28  text_input_client_ = client;
29  if (client)
30    OnTextInputTypeChanged(client);
31}
32
33void MockInputMethod::DetachTextInputClient(TextInputClient* client) {
34  if (text_input_client_ == client) {
35    text_input_client_ = NULL;
36  }
37}
38
39TextInputClient* MockInputMethod::GetTextInputClient() const {
40  if (switches::IsTextInputFocusManagerEnabled())
41    return TextInputFocusManager::GetInstance()->GetFocusedTextInputClient();
42
43  return text_input_client_;
44}
45
46bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) {
47  return false;
48}
49
50void MockInputMethod::Init(bool focused) {
51}
52
53void MockInputMethod::OnFocus() {
54  FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnFocus());
55}
56
57void MockInputMethod::OnBlur() {
58  FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnBlur());
59}
60
61bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
62                                               NativeEventResult* result) {
63  if (result)
64    *result = NativeEventResult();
65  return false;
66}
67
68void MockInputMethod::OnTextInputTypeChanged(const TextInputClient* client) {
69  FOR_EACH_OBSERVER(InputMethodObserver,
70                    observer_list_,
71                    OnTextInputTypeChanged(client));
72  FOR_EACH_OBSERVER(InputMethodObserver,
73                    observer_list_,
74                    OnTextInputStateChanged(client));
75}
76
77void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {
78  FOR_EACH_OBSERVER(InputMethodObserver,
79                    observer_list_,
80                    OnCaretBoundsChanged(client));
81}
82
83void MockInputMethod::CancelComposition(const TextInputClient* client) {
84}
85
86void MockInputMethod::OnInputLocaleChanged() {
87}
88
89std::string MockInputMethod::GetInputLocale() {
90  return "";
91}
92
93bool MockInputMethod::IsActive() {
94  return true;
95}
96
97TextInputType MockInputMethod::GetTextInputType() const {
98  return TEXT_INPUT_TYPE_NONE;
99}
100
101TextInputMode MockInputMethod::GetTextInputMode() const {
102  return TEXT_INPUT_MODE_DEFAULT;
103}
104
105bool MockInputMethod::CanComposeInline() const {
106  return true;
107}
108
109bool MockInputMethod::IsCandidatePopupOpen() const {
110  return false;
111}
112
113void MockInputMethod::ShowImeIfNeeded() {
114  FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnShowImeIfNeeded());
115}
116
117void MockInputMethod::AddObserver(InputMethodObserver* observer) {
118  observer_list_.AddObserver(observer);
119}
120
121void MockInputMethod::RemoveObserver(InputMethodObserver* observer) {
122  observer_list_.RemoveObserver(observer);
123}
124
125}  // namespace ui
126