blob: fad5315d5fbb196586b346de484af66aa45e8d98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
#define UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/base/ime/composition_text.h"
#include "ui/views/ime/input_method_base.h"
#include "ui/views/view.h"
namespace views {
// A mock InputMethod implementation for testing purpose.
class VIEWS_EXPORT MockInputMethod : public InputMethodBase {
public:
MockInputMethod();
explicit MockInputMethod(internal::InputMethodDelegate* delegate);
virtual ~MockInputMethod();
// Overridden from InputMethod:
virtual void Init(Widget* widget) OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void OnBlur() OVERRIDE;
virtual bool OnUntranslatedIMEMessage(const base::NativeEvent& event,
NativeEventResult* result) OVERRIDE;
virtual void DispatchKeyEvent(const ui::KeyEvent& key) OVERRIDE;
virtual void OnTextInputTypeChanged(View* view) OVERRIDE;
virtual void OnCaretBoundsChanged(View* view) OVERRIDE;
virtual void CancelComposition(View* view) OVERRIDE;
virtual void OnInputLocaleChanged() OVERRIDE;
virtual std::string GetInputLocale() OVERRIDE;
virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
virtual bool IsActive() OVERRIDE;
virtual bool IsCandidatePopupOpen() const OVERRIDE;
virtual bool IsMock() const OVERRIDE;
bool focus_changed() const { return focus_changed_; }
bool untranslated_ime_message_called() const {
return untranslated_ime_message_called_;
}
bool text_input_type_changed() const { return text_input_type_changed_; }
bool caret_bounds_changed() const { return caret_bounds_changed_; }
bool cancel_composition_called() const { return cancel_composition_called_; }
bool input_locale_changed() const { return input_locale_changed_; }
// Clears all internal states and result.
void Clear();
void SetCompositionTextForNextKey(const ui::CompositionText& composition);
void SetResultTextForNextKey(const string16& result);
void SetInputLocale(const std::string& locale);
void SetInputTextDirection(base::i18n::TextDirection direction);
void SetActive(bool active);
private:
// Overridden from InputMethodBase.
virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE;
// Clears boolean states defined below.
void ClearStates();
// Clears only composition information and result text.
void ClearResult();
// Composition information for the next key event. It'll be cleared
// automatically after dispatching the next key event.
ui::CompositionText composition_;
bool composition_changed_;
// Result text for the next key event. It'll be cleared automatically after
// dispatching the next key event.
string16 result_text_;
// Record call state of corresponding methods. They will be set to false
// automatically before dispatching a key event.
bool focus_changed_;
bool untranslated_ime_message_called_;
bool text_input_type_changed_;
bool caret_bounds_changed_;
bool cancel_composition_called_;
bool input_locale_changed_;
// To mock corresponding input method prooperties.
std::string locale_;
base::i18n::TextDirection direction_;
bool active_;
DISALLOW_COPY_AND_ASSIGN(MockInputMethod);
};
} // namespace views
#endif // UI_VIEWS_IME_MOCK_INPUT_METHOD_H_
|