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/input_method_delegate.h"
8 #include "ui/events/event.h"
12 MockInputMethod::MockInputMethod(internal::InputMethodDelegate
* delegate
)
13 : text_input_client_(NULL
), delegate_(delegate
) {
16 MockInputMethod::~MockInputMethod() {
17 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
,
18 OnInputMethodDestroyed(this));
21 void MockInputMethod::SetDelegate(internal::InputMethodDelegate
* delegate
) {
25 void MockInputMethod::SetFocusedTextInputClient(TextInputClient
* client
) {
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 return text_input_client_
;
43 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent
& event
) {
44 return delegate_
->DispatchKeyEventPostIME(event
);
47 void MockInputMethod::OnFocus() {
48 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnFocus());
51 void MockInputMethod::OnBlur() {
52 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnBlur());
55 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent
& event
,
56 NativeEventResult
* result
) {
58 *result
= NativeEventResult();
62 void MockInputMethod::OnTextInputTypeChanged(const TextInputClient
* client
) {
63 FOR_EACH_OBSERVER(InputMethodObserver
,
65 OnTextInputTypeChanged(client
));
66 FOR_EACH_OBSERVER(InputMethodObserver
,
68 OnTextInputStateChanged(client
));
71 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient
* client
) {
72 FOR_EACH_OBSERVER(InputMethodObserver
,
74 OnCaretBoundsChanged(client
));
77 void MockInputMethod::CancelComposition(const TextInputClient
* client
) {
80 void MockInputMethod::OnInputLocaleChanged() {
83 std::string
MockInputMethod::GetInputLocale() {
87 TextInputType
MockInputMethod::GetTextInputType() const {
88 return TEXT_INPUT_TYPE_NONE
;
91 TextInputMode
MockInputMethod::GetTextInputMode() const {
92 return TEXT_INPUT_MODE_DEFAULT
;
95 int MockInputMethod::GetTextInputFlags() const {
99 bool MockInputMethod::CanComposeInline() const {
103 bool MockInputMethod::IsCandidatePopupOpen() const {
107 void MockInputMethod::ShowImeIfNeeded() {
108 FOR_EACH_OBSERVER(InputMethodObserver
, observer_list_
, OnShowImeIfNeeded());
111 void MockInputMethod::AddObserver(InputMethodObserver
* observer
) {
112 observer_list_
.AddObserver(observer
);
115 void MockInputMethod::RemoveObserver(InputMethodObserver
* observer
) {
116 observer_list_
.RemoveObserver(observer
);