forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_text_input_client.cc
207 lines (159 loc) · 5.72 KB
/
fake_text_input_client.cc
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright 2020 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.
#include "ui/base/ime/fake_text_input_client.h"
#include "base/check_op.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/geometry/rect.h"
namespace ui {
FakeTextInputClient::FakeTextInputClient(TextInputType text_input_type)
: text_input_type_(text_input_type) {}
FakeTextInputClient::~FakeTextInputClient() = default;
void FakeTextInputClient::set_text_input_type(TextInputType text_input_type) {
text_input_type_ = text_input_type;
}
void FakeTextInputClient::set_source_id(ukm::SourceId source_id) {
source_id_ = source_id;
}
void FakeTextInputClient::SetTextAndSelection(const std::u16string& text,
gfx::Range selection) {
DCHECK_LE(selection_.end(), text.length());
text_ = text;
selection_ = selection;
}
void FakeTextInputClient::SetCompositionText(
const CompositionText& composition) {
text_.insert(selection_.start(), composition.text);
const size_t new_cursor = selection_.start() + composition.text.length();
composition_range_ = gfx::Range(selection_.start(), new_cursor);
selection_ = gfx::Range(new_cursor, new_cursor);
}
size_t FakeTextInputClient::ConfirmCompositionText(bool keep_selection) {
return std::numeric_limits<size_t>::max();
}
void FakeTextInputClient::ClearCompositionText() {}
void FakeTextInputClient::InsertText(
const std::u16string& text,
TextInputClient::InsertTextCursorBehavior cursor_behavior) {
const gfx::Range replacement_range =
composition_range_.is_empty() ? selection_ : composition_range_;
text_.replace(replacement_range.start(), replacement_range.length(), text);
if (cursor_behavior ==
TextInputClient::InsertTextCursorBehavior::kMoveCursorAfterText) {
selection_ = gfx::Range(replacement_range.start() + text.length(),
replacement_range.start() + text.length());
}
composition_range_ = gfx::Range();
}
void FakeTextInputClient::InsertChar(const KeyEvent& event) {}
TextInputType FakeTextInputClient::GetTextInputType() const {
return text_input_type_;
}
TextInputMode FakeTextInputClient::GetTextInputMode() const {
return TEXT_INPUT_MODE_NONE;
}
base::i18n::TextDirection FakeTextInputClient::GetTextDirection() const {
return base::i18n::UNKNOWN_DIRECTION;
}
int FakeTextInputClient::GetTextInputFlags() const {
return EF_NONE;
}
bool FakeTextInputClient::CanComposeInline() const {
return false;
}
gfx::Rect FakeTextInputClient::GetCaretBounds() const {
return {};
}
gfx::Rect FakeTextInputClient::GetSelectionBoundingBox() const {
return {};
}
bool FakeTextInputClient::GetCompositionCharacterBounds(size_t index,
gfx::Rect* rect) const {
return false;
}
bool FakeTextInputClient::HasCompositionText() const {
return !composition_range_.is_empty();
}
ui::TextInputClient::FocusReason FakeTextInputClient::GetFocusReason() const {
return ui::TextInputClient::FOCUS_REASON_MOUSE;
}
bool FakeTextInputClient::GetTextRange(gfx::Range* range) const {
*range = gfx::Range(0, text_.length());
return true;
}
bool FakeTextInputClient::GetCompositionTextRange(gfx::Range* range) const {
return false;
}
bool FakeTextInputClient::GetEditableSelectionRange(gfx::Range* range) const {
*range = selection_;
return true;
}
bool FakeTextInputClient::SetEditableSelectionRange(const gfx::Range& range) {
return false;
}
#if BUILDFLAG(IS_MAC)
bool FakeTextInputClient::DeleteRange(const gfx::Range& range) {
return false;
}
#endif
bool FakeTextInputClient::GetTextFromRange(const gfx::Range& range,
std::u16string* text) const {
return false;
}
void FakeTextInputClient::OnInputMethodChanged() {}
bool FakeTextInputClient::ChangeTextDirectionAndLayoutAlignment(
base::i18n::TextDirection direction) {
return false;
}
void FakeTextInputClient::ExtendSelectionAndDelete(size_t before,
size_t after) {}
void FakeTextInputClient::EnsureCaretNotInRect(const gfx::Rect& rect) {}
bool FakeTextInputClient::IsTextEditCommandEnabled(
TextEditCommand command) const {
return false;
}
void FakeTextInputClient::SetTextEditCommandForNextKeyEvent(
TextEditCommand command) {}
ukm::SourceId FakeTextInputClient::GetClientSourceForMetrics() const {
return source_id_;
}
bool FakeTextInputClient::ShouldDoLearning() {
return false;
}
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
bool FakeTextInputClient::SetCompositionFromExistingText(
const gfx::Range& range,
const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
if (range.start() < 0 || range.end() > text_.length())
return false;
composition_range_ = range;
ime_text_spans_ = ui_ime_text_spans;
return true;
}
#endif
#if BUILDFLAG(IS_CHROMEOS)
gfx::Range FakeTextInputClient::GetAutocorrectRange() const {
return autocorrect_range_;
}
gfx::Rect FakeTextInputClient::GetAutocorrectCharacterBounds() const {
return {};
}
bool FakeTextInputClient::SetAutocorrectRange(const gfx::Range& range) {
autocorrect_range_ = range;
return true;
}
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
void FakeTextInputClient::GetActiveTextInputControlLayoutBounds(
absl::optional<gfx::Rect>* control_bounds,
absl::optional<gfx::Rect>* selection_bounds) {}
#endif
#if BUILDFLAG(IS_WIN)
void FakeTextInputClient::SetActiveCompositionForAccessibility(
const gfx::Range& range,
const std::u16string& active_composition_text,
bool is_composition_committed) {}
#endif
} // namespace ui