| Flutter Windows Embedder |

text_editing_delta.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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 FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
7
8 #include <string>
9
10 #include "flutter/fml/string_conversion.h"
11 #include "flutter/shell/platform/common/text_range.h"
12
13 namespace flutter {
14
15 /// A change in the state of an input field.
16 struct TextEditingDelta {
17 TextEditingDelta(const std::u16string& text_before_change,
18 const TextRange& range,
19 const std::u16string& text);
20
21 TextEditingDelta(const std::string& text_before_change,
22 const TextRange& range,
23 const std::string& text);
24
25 explicit TextEditingDelta(const std::u16string& text);
26
27 explicit TextEditingDelta(const std::string& text);
28
29 virtual ~TextEditingDelta() = default;
30
31 /// Get the old_text_ value.
32 ///
33 /// All strings are stored as UTF16 but converted to UTF8 when accessed.
34 std::string old_text() const { return fml::Utf16ToUtf8(old_text_); }
35
36 /// Get the delta_text value.
37 ///
38 /// All strings are stored as UTF16 but converted to UTF8 when accessed.
39 std::string delta_text() const { return fml::Utf16ToUtf8(delta_text_); }
40
41 /// Get the delta_start_ value.
42 int delta_start() const { return delta_start_; }
43
44 /// Get the delta_end_ value.
45 int delta_end() const { return delta_end_; }
46
47 bool operator==(const TextEditingDelta& rhs) const {
48 return old_text_ == rhs.old_text_ && delta_text_ == rhs.delta_text_ &&
49 delta_start_ == rhs.delta_start_ && delta_end_ == rhs.delta_end_;
50 }
51
52 bool operator!=(const TextEditingDelta& rhs) const { return !(*this == rhs); }
53
54 TextEditingDelta(const TextEditingDelta& other) = default;
55
56 TextEditingDelta& operator=(const TextEditingDelta& other) = default;
57
58 private:
59 std::u16string old_text_;
60 std::u16string delta_text_;
61 int delta_start_;
62 int delta_end_;
63
64 void set_old_text(const std::u16string& old_text) { old_text_ = old_text; }
65
66 void set_delta_text(const std::u16string& delta_text) {
67 delta_text_ = delta_text;
68 }
69
70 void set_delta_start(int delta_start) { delta_start_ = delta_start; }
71
72 void set_delta_end(int delta_end) { delta_end_ = delta_end; }
73 };
74
75 } // namespace flutter
76
77 #endif // FLUTTER_SHELL_PLATFORM_COMMON_TEXT_EDITING_DELTA_H_
flutter::TextRange
Definition: text_range.h:19
text
std::u16string text
Definition: keyboard_unittests.cc:332
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::TextEditingDelta
A change in the state of an input field.
Definition: text_editing_delta.h:16
flutter::TextEditingDelta::operator==
bool operator==(const TextEditingDelta &rhs) const
Definition: text_editing_delta.h:47
flutter::TextEditingDelta::delta_text
std::string delta_text() const
Definition: text_editing_delta.h:39
flutter::TextEditingDelta::delta_start
int delta_start() const
Get the delta_start_ value.
Definition: text_editing_delta.h:42
flutter::TextEditingDelta::~TextEditingDelta
virtual ~TextEditingDelta()=default
flutter::TextEditingDelta::TextEditingDelta
TextEditingDelta(const std::u16string &text_before_change, const TextRange &range, const std::u16string &text)
Definition: text_editing_delta.cc:11
flutter::TextEditingDelta::delta_end
int delta_end() const
Get the delta_end_ value.
Definition: text_editing_delta.h:45
flutter::TextEditingDelta::operator=
TextEditingDelta & operator=(const TextEditingDelta &other)=default
flutter::TextEditingDelta::operator!=
bool operator!=(const TextEditingDelta &rhs) const
Definition: text_editing_delta.h:52
flutter::TextEditingDelta::TextEditingDelta
TextEditingDelta(const TextEditingDelta &other)=default
flutter::TextEditingDelta::old_text
std::string old_text() const
Definition: text_editing_delta.h:34
text_range.h