1 // Copyright (c) 2011 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 #ifndef UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
6 #define UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "ui/base/ime/composition_text.h"
13 #include "ui/views/ime/input_method_base.h"
14 #include "ui/views/view.h"
18 // A mock InputMethod implementation for testing purpose.
19 class VIEWS_EXPORT MockInputMethod
: public InputMethodBase
{
22 explicit MockInputMethod(internal::InputMethodDelegate
* delegate
);
23 ~MockInputMethod() override
;
25 // Overridden from InputMethod:
26 void OnFocus() override
;
27 void OnBlur() override
;
28 bool OnUntranslatedIMEMessage(const base::NativeEvent
& event
,
29 NativeEventResult
* result
) override
;
30 void DispatchKeyEvent(const ui::KeyEvent
& key
) override
;
31 void OnTextInputTypeChanged(View
* view
) override
;
32 void OnCaretBoundsChanged(View
* view
) override
;
33 void CancelComposition(View
* view
) override
;
34 void OnInputLocaleChanged() override
;
35 std::string
GetInputLocale() override
;
36 bool IsActive() override
;
37 bool IsCandidatePopupOpen() const override
;
38 void ShowImeIfNeeded() override
;
40 bool untranslated_ime_message_called() const {
41 return untranslated_ime_message_called_
;
43 bool text_input_type_changed() const { return text_input_type_changed_
; }
44 bool cancel_composition_called() const { return cancel_composition_called_
; }
46 // Clears all internal states and result.
49 void SetCompositionTextForNextKey(const ui::CompositionText
& composition
);
50 void SetResultTextForNextKey(const base::string16
& result
);
53 // Overridden from InputMethodBase.
54 void OnWillChangeFocus(View
* focused_before
, View
* focused
) override
;
56 // Clears boolean states defined below.
59 // Whether a mock composition or result is scheduled for the next key event.
60 bool HasComposition();
62 // Clears only composition information and result text.
63 void ClearComposition();
65 // Composition information for the next key event. It'll be cleared
66 // automatically after dispatching the next key event.
67 ui::CompositionText composition_
;
69 // Result text for the next key event. It'll be cleared automatically after
70 // dispatching the next key event.
71 base::string16 result_text_
;
73 // Record call state of corresponding methods. They will be set to false
74 // automatically before dispatching a key event.
75 bool untranslated_ime_message_called_
;
76 bool text_input_type_changed_
;
77 bool cancel_composition_called_
;
79 DISALLOW_COPY_AND_ASSIGN(MockInputMethod
);
84 #endif // UI_VIEWS_IME_MOCK_INPUT_METHOD_H_