OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef UI_VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
6 #define UI_VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
7 | |
8 #include <string> | |
9 | |
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" | |
15 | |
16 namespace views { | |
17 | |
18 // A mock InputMethod implementation for testing purpose. | |
19 class VIEWS_EXPORT MockInputMethod : public InputMethodBase { | |
20 public: | |
21 MockInputMethod(); | |
22 explicit MockInputMethod(internal::InputMethodDelegate* delegate); | |
23 ~MockInputMethod() override; | |
24 | |
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; | |
39 | |
40 bool untranslated_ime_message_called() const { | |
41 return untranslated_ime_message_called_; | |
42 } | |
43 bool text_input_type_changed() const { return text_input_type_changed_; } | |
44 bool cancel_composition_called() const { return cancel_composition_called_; } | |
45 | |
46 // Clears all internal states and result. | |
47 void Clear(); | |
48 | |
49 void SetCompositionTextForNextKey(const ui::CompositionText& composition); | |
50 void SetResultTextForNextKey(const base::string16& result); | |
51 | |
52 private: | |
53 // Overridden from InputMethodBase. | |
54 void OnWillChangeFocus(View* focused_before, View* focused) override; | |
55 | |
56 // Clears boolean states defined below. | |
57 void ClearStates(); | |
58 | |
59 // Whether a mock composition or result is scheduled for the next key event. | |
60 bool HasComposition(); | |
61 | |
62 // Clears only composition information and result text. | |
63 void ClearComposition(); | |
64 | |
65 // Composition information for the next key event. It'll be cleared | |
66 // automatically after dispatching the next key event. | |
67 ui::CompositionText composition_; | |
68 | |
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_; | |
72 | |
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_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(MockInputMethod); | |
80 }; | |
81 | |
82 } // namespace views | |
83 | |
84 #endif // UI_VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
OLD | NEW |