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.
5 #include "ui/base/ime/mock_input_method.h"
7 #include "ui/base/ime/text_input_focus_manager.h"
8 #include "ui/base/ui_base_switches_util.h"
12 MockInputMethod::MockInputMethod(internal::InputMethodDelegate
* delegate
)
13 : text_input_client_(NULL
) {
16 MockInputMethod::~MockInputMethod() {
19 void MockInputMethod::SetDelegate(internal::InputMethodDelegate
* delegate
) {
22 void MockInputMethod::SetFocusedTextInputClient(TextInputClient
* client
) {
23 if (switches::IsTextInputFocusManagerEnabled())
26 if (text_input_client_
== client
)
28 text_input_client_
= client
;
30 OnTextInputTypeChanged(client
);
33 void MockInputMethod::DetachTextInputClient(TextInputClient
* client
) {
34 if (text_input_client_
== client
) {
35 text_input_client_
= NULL
;
39 TextInputClient
* MockInputMethod::GetTextInputClient() const {
40 if (switches::IsTextInputFocusManagerEnabled())
41 return TextInputFocusManager::GetInstance()->GetFocusedTextInputClient();
43 return text_input_client_
;
46 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent
& event
) {
50 void MockInputMethod::Init(bool focused
) {
53 void MockInputMethod::OnFocus() {
54 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnFocus());
57 void MockInputMethod::OnBlur() {
58 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnBlur());
61 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent
& event
,
62 NativeEventResult
* result
) {
64 *result
= NativeEventResult();
68 void MockInputMethod::OnTextInputTypeChanged(const TextInputClient
* client
) {
69 FOR_EACH_OBSERVER(InputMethodObserver
,
71 OnTextInputTypeChanged(client
));
72 FOR_EACH_OBSERVER(InputMethodObserver
,
74 OnTextInputStateChanged(client
));
77 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient
* client
) {
78 FOR_EACH_OBSERVER(InputMethodObserver
,
80 OnCaretBoundsChanged(client
));
83 void MockInputMethod::CancelComposition(const TextInputClient
* client
) {
86 void MockInputMethod::OnInputLocaleChanged() {
89 std::string
MockInputMethod::GetInputLocale() {
93 bool MockInputMethod::IsActive() {
97 TextInputType
MockInputMethod::GetTextInputType() const {
98 return TEXT_INPUT_TYPE_NONE
;
101 TextInputMode
MockInputMethod::GetTextInputMode() const {
102 return TEXT_INPUT_MODE_DEFAULT
;
105 int MockInputMethod::GetTextInputFlags() const {
109 bool MockInputMethod::CanComposeInline() const {
113 bool MockInputMethod::IsCandidatePopupOpen() const {
117 void MockInputMethod::ShowImeIfNeeded() {
118 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnShowImeIfNeeded());
121 void MockInputMethod::AddObserver(InputMethodObserver
* observer
) {
122 observer_list_
.AddObserver(observer
);
125 void MockInputMethod::RemoveObserver(InputMethodObserver
* observer
) {
126 observer_list_
.RemoveObserver(observer
);