1 // Copyright 2013 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 #include "ui/base/ime/dummy_text_input_client.h"
6
7 #if defined(OS_WIN)
8 #include <vector>
9 #endif
10
11 #include "base/strings/string_util.h"
12 #include "build/build_config.h"
13 #include "ui/events/event.h"
14 #include "ui/gfx/geometry/rect.h"
15
16 namespace ui {
17
DummyTextInputClient()18 DummyTextInputClient::DummyTextInputClient()
19 : DummyTextInputClient(TEXT_INPUT_TYPE_NONE) {}
20
DummyTextInputClient(TextInputType text_input_type)21 DummyTextInputClient::DummyTextInputClient(TextInputType text_input_type)
22 : DummyTextInputClient(text_input_type, TEXT_INPUT_MODE_DEFAULT) {}
23
DummyTextInputClient(TextInputType text_input_type,TextInputMode text_input_mode)24 DummyTextInputClient::DummyTextInputClient(TextInputType text_input_type,
25 TextInputMode text_input_mode)
26 : text_input_type_(text_input_type),
27 text_input_mode_(text_input_mode),
28 insert_char_count_(0) {}
29
~DummyTextInputClient()30 DummyTextInputClient::~DummyTextInputClient() {
31 }
32
SetCompositionText(const CompositionText & composition)33 void DummyTextInputClient::SetCompositionText(
34 const CompositionText& composition) {
35 composition_history_.push_back(composition);
36 }
37
ConfirmCompositionText(bool keep_selection)38 uint32_t DummyTextInputClient::ConfirmCompositionText(bool keep_selection) {
39 return UINT32_MAX;
40 }
41
ClearCompositionText()42 void DummyTextInputClient::ClearCompositionText() {
43 SetCompositionText(CompositionText());
44 }
45
InsertText(const base::string16 & text)46 void DummyTextInputClient::InsertText(const base::string16& text) {
47 insert_text_history_.push_back(text);
48 }
49
InsertChar(const KeyEvent & event)50 void DummyTextInputClient::InsertChar(const KeyEvent& event) {
51 ++insert_char_count_;
52 last_insert_char_ = event.GetCharacter();
53 }
54
GetTextInputType() const55 TextInputType DummyTextInputClient::GetTextInputType() const {
56 return text_input_type_;
57 }
58
GetTextInputMode() const59 TextInputMode DummyTextInputClient::GetTextInputMode() const {
60 return text_input_mode_;
61 }
62
GetTextDirection() const63 base::i18n::TextDirection DummyTextInputClient::GetTextDirection() const {
64 return base::i18n::UNKNOWN_DIRECTION;
65 }
66
GetTextInputFlags() const67 int DummyTextInputClient::GetTextInputFlags() const {
68 return 0;
69 }
70
CanComposeInline() const71 bool DummyTextInputClient::CanComposeInline() const {
72 return false;
73 }
74
GetCaretBounds() const75 gfx::Rect DummyTextInputClient::GetCaretBounds() const {
76 return gfx::Rect();
77 }
78
GetCompositionCharacterBounds(uint32_t index,gfx::Rect * rect) const79 bool DummyTextInputClient::GetCompositionCharacterBounds(
80 uint32_t index,
81 gfx::Rect* rect) const {
82 return false;
83 }
84
HasCompositionText() const85 bool DummyTextInputClient::HasCompositionText() const {
86 return false;
87 }
88
GetFocusReason() const89 ui::TextInputClient::FocusReason DummyTextInputClient::GetFocusReason() const {
90 return ui::TextInputClient::FOCUS_REASON_OTHER;
91 }
92
GetTextRange(gfx::Range * range) const93 bool DummyTextInputClient::GetTextRange(gfx::Range* range) const {
94 return false;
95 }
96
GetCompositionTextRange(gfx::Range * range) const97 bool DummyTextInputClient::GetCompositionTextRange(gfx::Range* range) const {
98 return false;
99 }
100
GetEditableSelectionRange(gfx::Range * range) const101 bool DummyTextInputClient::GetEditableSelectionRange(gfx::Range* range) const {
102 return false;
103 }
104
SetEditableSelectionRange(const gfx::Range & range)105 bool DummyTextInputClient::SetEditableSelectionRange(const gfx::Range& range) {
106 selection_history_.push_back(range);
107 return false;
108 }
109
DeleteRange(const gfx::Range & range)110 bool DummyTextInputClient::DeleteRange(const gfx::Range& range) {
111 return false;
112 }
113
GetTextFromRange(const gfx::Range & range,base::string16 * text) const114 bool DummyTextInputClient::GetTextFromRange(const gfx::Range& range,
115 base::string16* text) const {
116 return false;
117 }
118
OnInputMethodChanged()119 void DummyTextInputClient::OnInputMethodChanged() {
120 }
121
ChangeTextDirectionAndLayoutAlignment(base::i18n::TextDirection direction)122 bool DummyTextInputClient::ChangeTextDirectionAndLayoutAlignment(
123 base::i18n::TextDirection direction) {
124 return false;
125 }
126
ExtendSelectionAndDelete(size_t before,size_t after)127 void DummyTextInputClient::ExtendSelectionAndDelete(size_t before,
128 size_t after) {
129 }
130
EnsureCaretNotInRect(const gfx::Rect & rect)131 void DummyTextInputClient::EnsureCaretNotInRect(const gfx::Rect& rect) {}
132
IsTextEditCommandEnabled(TextEditCommand command) const133 bool DummyTextInputClient::IsTextEditCommandEnabled(
134 TextEditCommand command) const {
135 return false;
136 }
137
SetTextEditCommandForNextKeyEvent(TextEditCommand command)138 void DummyTextInputClient::SetTextEditCommandForNextKeyEvent(
139 TextEditCommand command) {}
140
GetClientSourceForMetrics() const141 ukm::SourceId DummyTextInputClient::GetClientSourceForMetrics() const {
142 return ukm::SourceId{};
143 }
144
ShouldDoLearning()145 bool DummyTextInputClient::ShouldDoLearning() {
146 return false;
147 }
148
149 #if defined(OS_WIN) || defined(OS_CHROMEOS)
SetCompositionFromExistingText(const gfx::Range & range,const std::vector<ui::ImeTextSpan> & ui_ime_text_spans)150 bool DummyTextInputClient::SetCompositionFromExistingText(
151 const gfx::Range& range,
152 const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
153 return false;
154 }
155 #endif
156
157 #if defined(OS_CHROMEOS)
GetAutocorrectRange() const158 gfx::Range DummyTextInputClient::GetAutocorrectRange() const {
159 return autocorrect_range_;
160 }
GetAutocorrectCharacterBounds() const161 gfx::Rect DummyTextInputClient::GetAutocorrectCharacterBounds() const {
162 return gfx::Rect();
163 }
164
SetAutocorrectRange(const base::string16 & autocorrect_text,const gfx::Range & range)165 bool DummyTextInputClient::SetAutocorrectRange(
166 const base::string16& autocorrect_text,
167 const gfx::Range& range) {
168 // Clears autocorrect range if text is empty.
169 // autocorrect_text content is ignored.
170 if (autocorrect_text.empty()) {
171 autocorrect_range_ = gfx::Range();
172 } else {
173 autocorrect_range_ = range;
174 }
175 return true;
176 }
177
ClearAutocorrectRange()178 void DummyTextInputClient::ClearAutocorrectRange() {}
179
180 #endif
181
182 #if defined(OS_WIN)
GetActiveTextInputControlLayoutBounds(base::Optional<gfx::Rect> * control_bounds,base::Optional<gfx::Rect> * selection_bounds)183 void DummyTextInputClient::GetActiveTextInputControlLayoutBounds(
184 base::Optional<gfx::Rect>* control_bounds,
185 base::Optional<gfx::Rect>* selection_bounds) {}
186
SetActiveCompositionForAccessibility(const gfx::Range & range,const base::string16 & active_composition_text,bool is_composition_committed)187 void DummyTextInputClient::SetActiveCompositionForAccessibility(
188 const gfx::Range& range,
189 const base::string16& active_composition_text,
190 bool is_composition_committed) {}
191 #endif
192
193 } // namespace ui
194