File: dummy_text_input_client.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (238 lines) | stat: -rw-r--r-- 6,427 bytes parent folder | download | duplicates (3)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/ime/dummy_text_input_client.h"

#include "base/notreached.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/rect.h"

namespace ui {

DummyTextInputClient::DummyTextInputClient()
    : DummyTextInputClient(TEXT_INPUT_TYPE_NONE) {}

DummyTextInputClient::DummyTextInputClient(TextInputType text_input_type)
    : DummyTextInputClient(text_input_type, TEXT_INPUT_MODE_DEFAULT) {}

DummyTextInputClient::DummyTextInputClient(TextInputType text_input_type,
                                           TextInputMode text_input_mode)
    : text_input_type_(text_input_type),
      text_input_mode_(text_input_mode),
      insert_char_count_(0),
      autocorrect_enabled_(true) {}

DummyTextInputClient::~DummyTextInputClient() {
}

base::WeakPtr<ui::TextInputClient> DummyTextInputClient::AsWeakPtr() {
  return weak_ptr_factory_.GetWeakPtr();
}

void DummyTextInputClient::SetCompositionText(
    const CompositionText& composition) {
  composition_history_.push_back(composition);
}

size_t DummyTextInputClient::ConfirmCompositionText(bool keep_selection) {
  return std::numeric_limits<size_t>::max();
}

void DummyTextInputClient::ClearCompositionText() {
  SetCompositionText(CompositionText());
}

void DummyTextInputClient::InsertText(
    const std::u16string& text,
    InsertTextCursorBehavior cursor_behavior) {
  insert_text_history_.push_back(text);
}

void DummyTextInputClient::InsertChar(const KeyEvent& event) {
  ++insert_char_count_;
  last_insert_char_ = event.GetCharacter();
}

TextInputType DummyTextInputClient::GetTextInputType() const {
  return text_input_type_;
}

TextInputMode DummyTextInputClient::GetTextInputMode() const {
  return text_input_mode_;
}

base::i18n::TextDirection DummyTextInputClient::GetTextDirection() const {
  return base::i18n::UNKNOWN_DIRECTION;
}

int DummyTextInputClient::GetTextInputFlags() const {
  return 0;
}

bool DummyTextInputClient::CanComposeInline() const {
  return false;
}

gfx::Rect DummyTextInputClient::GetCaretBounds() const {
  return gfx::Rect();
}

gfx::Rect DummyTextInputClient::GetSelectionBoundingBox() const {
  NOTIMPLEMENTED_LOG_ONCE();
  return gfx::Rect();
}

#if BUILDFLAG(IS_WIN)
std::optional<gfx::Rect> DummyTextInputClient::GetProximateCharacterBounds(
    const gfx::Range& range) const {
  return std::nullopt;
}

std::optional<size_t> DummyTextInputClient::GetProximateCharacterIndexFromPoint(
    const gfx::Point& screen_point_in_dips,
    IndexFromPointFlags flags) const {
  return std::nullopt;
}
#endif  // BUILDFLAG(IS_WIN)

bool DummyTextInputClient::GetCompositionCharacterBounds(
    size_t index,
    gfx::Rect* rect) const {
  return false;
}

bool DummyTextInputClient::HasCompositionText() const {
  return false;
}

ui::TextInputClient::FocusReason DummyTextInputClient::GetFocusReason() const {
  return ui::TextInputClient::FOCUS_REASON_OTHER;
}

bool DummyTextInputClient::GetTextRange(gfx::Range* range) const {
  return false;
}

bool DummyTextInputClient::GetCompositionTextRange(gfx::Range* range) const {
  return false;
}

bool DummyTextInputClient::GetEditableSelectionRange(gfx::Range* range) const {
  if (!cursor_range_.IsValid())
    return false;
  range->set_start(cursor_range_.start());
  range->set_end(cursor_range_.end());
  return true;
}

bool DummyTextInputClient::SetEditableSelectionRange(const gfx::Range& range) {
  selection_history_.push_back(range);
  cursor_range_ = range;
  return true;
}

#if BUILDFLAG(IS_MAC)
bool DummyTextInputClient::DeleteRange(const gfx::Range& range) {
  return false;
}
#endif

bool DummyTextInputClient::GetTextFromRange(const gfx::Range& range,
                                            std::u16string* text) const {
  return false;
}

void DummyTextInputClient::OnInputMethodChanged() {
}

bool DummyTextInputClient::ChangeTextDirectionAndLayoutAlignment(
    base::i18n::TextDirection direction) {
  return false;
}

void DummyTextInputClient::ExtendSelectionAndDelete(size_t before,
                                                    size_t after) {
}

void DummyTextInputClient::EnsureCaretNotInRect(const gfx::Rect& rect) {}

bool DummyTextInputClient::IsTextEditCommandEnabled(
    TextEditCommand command) const {
  return false;
}

void DummyTextInputClient::SetTextEditCommandForNextKeyEvent(
    TextEditCommand command) {}

ukm::SourceId DummyTextInputClient::GetClientSourceForMetrics() const {
  return ukm::SourceId{};
}

bool DummyTextInputClient::ShouldDoLearning() {
  return false;
}

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
bool DummyTextInputClient::SetCompositionFromExistingText(
    const gfx::Range& range,
    const std::vector<ui::ImeTextSpan>& ui_ime_text_spans) {
  return false;
}
#endif

#if BUILDFLAG(IS_CHROMEOS)
gfx::Range DummyTextInputClient::GetAutocorrectRange() const {
  return autocorrect_range_;
}
gfx::Rect DummyTextInputClient::GetAutocorrectCharacterBounds() const {
  return gfx::Rect();
}

bool DummyTextInputClient::SetAutocorrectRange(
    const gfx::Range& range) {
  if (autocorrect_enabled_) {
    autocorrect_range_ = range;
  }
  return autocorrect_enabled_;
}

std::optional<GrammarFragment>
DummyTextInputClient::GetGrammarFragmentAtCursor() const {
  for (const auto& fragment : grammar_fragments_) {
    if (fragment.range.Contains(cursor_range_)) {
      return fragment;
    }
  }
  return std::nullopt;
}

bool DummyTextInputClient::ClearGrammarFragments(const gfx::Range& range) {
  grammar_fragments_.clear();
  return true;
}

bool DummyTextInputClient::AddGrammarFragments(
    const std::vector<GrammarFragment>& fragments) {
  grammar_fragments_.insert(grammar_fragments_.end(), fragments.begin(),
                            fragments.end());
  return true;
}
#endif

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
void DummyTextInputClient::GetActiveTextInputControlLayoutBounds(
    std::optional<gfx::Rect>* control_bounds,
    std::optional<gfx::Rect>* selection_bounds) {}
#endif

#if BUILDFLAG(IS_WIN)
void DummyTextInputClient::SetActiveCompositionForAccessibility(
    const gfx::Range& range,
    const std::u16string& active_composition_text,
    bool is_composition_committed) {}
#endif

}  // namespace ui