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 #ifndef UI_BASE_IME_MOCK_INPUT_METHOD_H_ 6 #define UI_BASE_IME_MOCK_INPUT_METHOD_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/observer_list.h" 13 #include "ui/base/ime/input_method.h" 14 #include "ui/base/ime/input_method_observer.h" 15 #include "ui/base/ui_export.h" 16 17 namespace ui { 18 19 class KeyEvent; 20 class TextInputClient; 21 22 // A mock ui::InputMethod implementation for testing. You can get the instance 23 // of this class as the global input method with calling 24 // SetUpInputMethodFactoryForTesting() which is declared in 25 // ui/base/ime/input_method_factory.h 26 class UI_EXPORT MockInputMethod : NON_EXPORTED_BASE(public InputMethod) { 27 public: 28 class Observer : public InputMethodObserver { 29 public: 30 virtual void OnTextInputTypeChanged(const TextInputClient* client) = 0; 31 virtual void OnFocus() = 0; 32 virtual void OnBlur() = 0; 33 virtual void OnUntranslatedIMEMessage(const base::NativeEvent& event) = 0; 34 virtual void OnCaretBoundsChanged(const TextInputClient* client) = 0; 35 virtual void OnInputLocaleChanged() = 0; 36 37 // InputMethodObserver overrides 38 virtual void OnTextInputStateChanged(const TextInputClient* client) = 0; 39 virtual void OnInputMethodDestroyed(const InputMethod* input_method) = 0; 40 }; 41 explicit MockInputMethod(internal::InputMethodDelegate* delegate); 42 virtual ~MockInputMethod(); 43 44 // Overriden from InputMethod. 45 virtual void SetDelegate(internal::InputMethodDelegate* delegate) OVERRIDE; 46 virtual void Init(bool focused) OVERRIDE; 47 virtual void OnFocus() OVERRIDE; 48 virtual void OnBlur() OVERRIDE; 49 virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event, 50 NativeEventResult* result) OVERRIDE; 51 virtual void SetFocusedTextInputClient(TextInputClient* client) OVERRIDE; 52 virtual TextInputClient* GetTextInputClient() const OVERRIDE; 53 virtual bool DispatchKeyEvent(const base::NativeEvent& native_event) OVERRIDE; 54 virtual bool DispatchFabricatedKeyEvent(const ui::KeyEvent& event) OVERRIDE; 55 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE; 56 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE; 57 virtual void CancelComposition(const TextInputClient* client) OVERRIDE; 58 virtual void OnInputLocaleChanged() OVERRIDE; 59 virtual std::string GetInputLocale() OVERRIDE; 60 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; 61 virtual bool IsActive() OVERRIDE; 62 virtual TextInputType GetTextInputType() const OVERRIDE; 63 virtual bool CanComposeInline() const OVERRIDE; 64 virtual bool IsCandidatePopupOpen() const OVERRIDE; 65 virtual void AddObserver(InputMethodObserver* observer) OVERRIDE; 66 virtual void RemoveObserver(InputMethodObserver* observer) OVERRIDE; 67 68 private: 69 TextInputClient* text_input_client_; 70 ObserverList<Observer> observer_list_; 71 72 DISALLOW_COPY_AND_ASSIGN(MockInputMethod); 73 }; 74 75 } // namespace ui 76 77 #endif // UI_BASE_IME_MOCK_INPUT_METHOD_H_ 78