• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 namespace ui {
11 
MockInputMethod(internal::InputMethodDelegate * delegate)12 MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate)
13     : text_input_client_(NULL) {
14 }
15 
~MockInputMethod()16 MockInputMethod::~MockInputMethod() {
17 }
18 
SetDelegate(internal::InputMethodDelegate * delegate)19 void MockInputMethod::SetDelegate(internal::InputMethodDelegate* delegate) {
20 }
21 
SetFocusedTextInputClient(TextInputClient * client)22 void 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 
DetachTextInputClient(TextInputClient * client)33 void MockInputMethod::DetachTextInputClient(TextInputClient* client) {
34   if (text_input_client_ == client) {
35     text_input_client_ = NULL;
36   }
37 }
38 
GetTextInputClient() const39 TextInputClient* MockInputMethod::GetTextInputClient() const {
40   if (switches::IsTextInputFocusManagerEnabled())
41     return TextInputFocusManager::GetInstance()->GetFocusedTextInputClient();
42 
43   return text_input_client_;
44 }
45 
DispatchKeyEvent(const ui::KeyEvent & event)46 bool MockInputMethod::DispatchKeyEvent(const ui::KeyEvent& event) {
47   return false;
48 }
49 
Init(bool focused)50 void MockInputMethod::Init(bool focused) {
51 }
52 
OnFocus()53 void MockInputMethod::OnFocus() {
54   FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnFocus());
55 }
56 
OnBlur()57 void MockInputMethod::OnBlur() {
58   FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnBlur());
59 }
60 
OnUntranslatedIMEMessage(const base::NativeEvent & event,NativeEventResult * result)61 bool MockInputMethod::OnUntranslatedIMEMessage(const base::NativeEvent& event,
62                                                NativeEventResult* result) {
63   if (result)
64     *result = NativeEventResult();
65   return false;
66 }
67 
OnTextInputTypeChanged(const TextInputClient * client)68 void 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 
OnCaretBoundsChanged(const TextInputClient * client)77 void MockInputMethod::OnCaretBoundsChanged(const TextInputClient* client) {
78   FOR_EACH_OBSERVER(InputMethodObserver,
79                     observer_list_,
80                     OnCaretBoundsChanged(client));
81 }
82 
CancelComposition(const TextInputClient * client)83 void MockInputMethod::CancelComposition(const TextInputClient* client) {
84 }
85 
OnInputLocaleChanged()86 void MockInputMethod::OnInputLocaleChanged() {
87 }
88 
GetInputLocale()89 std::string MockInputMethod::GetInputLocale() {
90   return "";
91 }
92 
IsActive()93 bool MockInputMethod::IsActive() {
94   return true;
95 }
96 
GetTextInputType() const97 TextInputType MockInputMethod::GetTextInputType() const {
98   return TEXT_INPUT_TYPE_NONE;
99 }
100 
GetTextInputMode() const101 TextInputMode MockInputMethod::GetTextInputMode() const {
102   return TEXT_INPUT_MODE_DEFAULT;
103 }
104 
CanComposeInline() const105 bool MockInputMethod::CanComposeInline() const {
106   return true;
107 }
108 
IsCandidatePopupOpen() const109 bool MockInputMethod::IsCandidatePopupOpen() const {
110   return false;
111 }
112 
ShowImeIfNeeded()113 void MockInputMethod::ShowImeIfNeeded() {
114   FOR_EACH_OBSERVER(InputMethodObserver, observer_list_, OnShowImeIfNeeded());
115 }
116 
AddObserver(InputMethodObserver * observer)117 void MockInputMethod::AddObserver(InputMethodObserver* observer) {
118   observer_list_.AddObserver(observer);
119 }
120 
RemoveObserver(InputMethodObserver * observer)121 void MockInputMethod::RemoveObserver(InputMethodObserver* observer) {
122   observer_list_.RemoveObserver(observer);
123 }
124 
125 }  // namespace ui
126