5#include "flutter/shell/platform/glfw/text_input_plugin.h"
10#include "flutter/shell/platform/common/json_method_codec.h"
21 "TextInputClient.updateEditingState";
40 "Internal Consistency Error";
45 if (active_model_ ==
nullptr) {
48 active_model_->AddCodePoint(code_point);
49 SendStateUpdate(*active_model_);
57 if (active_model_ ==
nullptr) {
63 if (active_model_->MoveCursorBack()) {
64 SendStateUpdate(*active_model_);
68 if (active_model_->MoveCursorForward()) {
69 SendStateUpdate(*active_model_);
73 active_model_->MoveCursorToEnd();
74 SendStateUpdate(*active_model_);
77 active_model_->MoveCursorToBeginning();
78 SendStateUpdate(*active_model_);
80 case GLFW_KEY_BACKSPACE:
81 if (active_model_->Backspace()) {
82 SendStateUpdate(*active_model_);
86 if (active_model_->Delete()) {
87 SendStateUpdate(*active_model_);
91 EnterPressed(active_model_.get());
104 active_model_(nullptr) {
105 channel_->SetMethodCallHandler(
115void TextInputPlugin::HandleMethodCall(
118 const std::string& method =
method_call.method_name();
123 active_model_ =
nullptr;
133 const rapidjson::Value& client_id_json =
args[0];
134 const rapidjson::Value& client_config =
args[1];
135 if (client_id_json.IsNull()) {
139 if (client_config.IsNull()) {
141 "Could not set client, missing arguments.");
144 client_id_ = client_id_json.GetInt();
147 if (input_action_json != client_config.MemberEnd() &&
148 input_action_json->value.IsString()) {
149 input_action_ = input_action_json->value.GetString();
152 auto input_type_info_json = client_config.FindMember(
kTextInputType);
153 if (input_type_info_json != client_config.MemberEnd() &&
154 input_type_info_json->value.IsObject()) {
155 auto input_type_json =
157 if (input_type_json != input_type_info_json->value.MemberEnd() &&
158 input_type_json->value.IsString()) {
159 input_type_ = input_type_json->value.GetString();
162 active_model_ = std::make_unique<TextInputModel>();
170 if (active_model_ ==
nullptr) {
173 "Set editing state has been invoked, but no client is set.");
179 "Set editing state has been invoked, but without text.");
184 if (selection_base ==
args.MemberEnd() || selection_base->value.IsNull() ||
185 selection_extent ==
args.MemberEnd() ||
186 selection_extent->value.IsNull()) {
188 "Selection base/extent values invalid.");
192 int base = selection_base->value.GetInt();
193 int extent = selection_extent->value.GetInt();
194 if (
base == -1 && extent == -1) {
197 active_model_->SetText(
text->value.GetString());
208void TextInputPlugin::SendStateUpdate(
const TextInputModel& model) {
209 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
210 auto& allocator =
args->GetAllocator();
211 args->PushBack(client_id_, allocator);
214 rapidjson::Value editing_state(rapidjson::kObjectType);
222 editing_state.AddMember(
223 kTextKey, rapidjson::Value(model.GetText(), allocator).Move(), allocator);
224 args->PushBack(editing_state, allocator);
229void TextInputPlugin::EnterPressed(TextInputModel* model) {
231 model->AddCodePoint(
'\n');
232 SendStateUpdate(*model);
234 auto args = std::make_unique<rapidjson::Document>(rapidjson::kArrayType);
235 auto& allocator =
args->GetAllocator();
236 args->PushBack(client_id_, allocator);
237 args->PushBack(rapidjson::Value(input_action_, allocator).Move(), allocator);
void KeyboardHook(GLFWwindow *window, int key, int scancode, int action, int mods) override
TextInputPlugin(flutter::BinaryMessenger *messenger)
virtual ~TextInputPlugin()
void CharHook(GLFWwindow *window, unsigned int code_point) override
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
static constexpr char kClearClientMethod[]
static constexpr char kSelectionIsDirectionalKey[]
static constexpr char kHideMethod[]
static constexpr char kMultilineInputType[]
static constexpr char kSetEditingStateMethod[]
static constexpr char kSelectionExtentKey[]
static constexpr char kTextInputType[]
static constexpr char kChannelName[]
static constexpr char kInternalConsistencyError[]
static constexpr char kBadArgumentError[]
static constexpr char kSetClientMethod[]
static constexpr char kUpdateEditingStateMethod[]
static constexpr char kPerformActionMethod[]
static constexpr char kShowMethod[]
static constexpr char kComposingExtentKey[]
static constexpr char kTextInputAction[]
static constexpr char kComposingBaseKey[]
static constexpr char kTextInputTypeName[]
static constexpr char kAffinityDownstream[]
static constexpr char kSelectionAffinityKey[]
static constexpr char kTextKey[]
static constexpr char kSelectionBaseKey[]
SkRange< size_t > TextRange