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 VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
6 #define VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "ui/base/ime/composition_text.h" | |
14 #include "views/ime/input_method_base.h" | |
15 #include "views/view.h" | |
16 | |
17 namespace views { | |
18 | |
19 // A mock InputMethod implementation for testing purpose. | |
20 class VIEWS_EXPORT MockInputMethod : public InputMethodBase { | |
21 public: | |
22 MockInputMethod(); | |
23 explicit MockInputMethod(internal::InputMethodDelegate* delegate); | |
24 virtual ~MockInputMethod(); | |
25 | |
26 // Overridden from InputMethod: | |
27 virtual void Init(Widget* widget) OVERRIDE; | |
28 virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE; | |
29 virtual void OnTextInputTypeChanged(View* view) OVERRIDE; | |
30 virtual void OnCaretBoundsChanged(View* view) OVERRIDE; | |
31 virtual void CancelComposition(View* view) OVERRIDE; | |
32 virtual std::string GetInputLocale() OVERRIDE; | |
33 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; | |
34 virtual bool IsActive() OVERRIDE; | |
35 virtual bool IsMock() const OVERRIDE; | |
36 | |
37 bool focus_changed() const { return focus_changed_; } | |
38 bool text_input_type_changed() const { return text_input_type_changed_; } | |
39 bool caret_bounds_changed() const { return caret_bounds_changed_; } | |
40 bool cancel_composition_called() const { return cancel_composition_called_; } | |
41 | |
42 // Clears all internal states and result. | |
43 void Clear(); | |
44 | |
45 void SetCompositionTextForNextKey(const ui::CompositionText& composition); | |
46 void SetResultTextForNextKey(const string16& result); | |
47 | |
48 void SetInputLocale(const std::string& locale); | |
49 void SetInputTextDirection(base::i18n::TextDirection direction); | |
50 void SetActive(bool active); | |
51 | |
52 private: | |
53 // Overridden from InputMethodBase. | |
54 virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; | |
55 | |
56 // Clears boolean states defined below. | |
57 void ClearStates(); | |
58 | |
59 // Clears only composition information and result text. | |
60 void ClearResult(); | |
61 | |
62 // Composition information for the next key event. It'll be cleared | |
63 // automatically after dispatching the next key event. | |
64 ui::CompositionText composition_; | |
65 bool composition_changed_; | |
66 | |
67 // Result text for the next key event. It'll be cleared automatically after | |
68 // dispatching the next key event. | |
69 string16 result_text_; | |
70 | |
71 // Record call state of corresponding methods. They will be set to false | |
72 // automatically before dispatching a key event. | |
73 bool focus_changed_; | |
74 bool text_input_type_changed_; | |
75 bool caret_bounds_changed_; | |
76 bool cancel_composition_called_; | |
77 | |
78 // To mock corresponding input method prooperties. | |
79 std::string locale_; | |
80 base::i18n::TextDirection direction_; | |
81 bool active_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(MockInputMethod); | |
84 }; | |
85 | |
86 } // namespace views | |
87 | |
88 #endif // VIEWS_IME_MOCK_INPUT_METHOD_H_ | |
OLD | NEW |