Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
text_input_plugin.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_WINDOWS_TEXT_INPUT_PLUGIN_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_
7
8#include <array>
9#include <map>
10#include <memory>
11
12#include "flutter/fml/macros.h"
13#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
14#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
15#include "flutter/shell/platform/common/geometry.h"
16#include "flutter/shell/platform/common/json_method_codec.h"
17#include "flutter/shell/platform/common/text_editing_delta.h"
18#include "flutter/shell/platform/common/text_input_model.h"
19#include "flutter/shell/platform/windows/keyboard_handler_base.h"
20
21namespace flutter {
22
23class FlutterWindowsEngine;
24
25// Implements a text input plugin.
26//
27// Specifically handles window events within windows.
28class TextInputPlugin {
29 public:
31 FlutterWindowsEngine* engine);
32
34
35 // Called when the Flutter engine receives a raw keyboard message.
36 virtual void KeyboardHook(int key,
37 int scancode,
38 int action,
39 char32_t character,
40 bool extended,
41 bool was_down);
42
43 // Called when the Flutter engine receives a keyboard character.
44 virtual void TextHook(const std::u16string& text);
45
46 // Called on an IME compose begin event.
47 //
48 // Triggered when the user begins editing composing text using a multi-step
49 // input method such as in CJK text input.
50 virtual void ComposeBeginHook();
51
52 // Called on an IME compose commit event.
53 //
54 // Triggered when the user triggers a commit of the current composing text
55 // while using a multi-step input method such as in CJK text input. Composing
56 // continues with the next keypress.
57 virtual void ComposeCommitHook();
58
59 // Called on an IME compose end event.
60 //
61 // Triggered when the composing ends, for example when the user presses
62 // ESC or when the user triggers a commit of the composing text while using a
63 // multi-step input method such as in CJK text input.
64 virtual void ComposeEndHook();
65
66 // Called on an IME composing region change event.
67 //
68 // Triggered when the user edits the composing text while using a multi-step
69 // input method such as in CJK text input.
70 virtual void ComposeChangeHook(const std::u16string& text, int cursor_pos);
71
72 private:
73 // Sends the current state of the given model to the Flutter engine.
74 void SendStateUpdate(const TextInputModel& model);
75
76 // Sends the current state of the given model to the Flutter engine.
77 void SendStateUpdateWithDelta(const TextInputModel& model,
78 const TextEditingDelta*);
79
80 // Sends an action triggered by the Enter key to the Flutter engine.
81 void EnterPressed(TextInputModel* model);
82
83 // Called when a method is called on |channel_|;
84 void HandleMethodCall(
87
88 // Returns the composing rect, or if IME composing mode is not active, the
89 // cursor rect in the PipelineOwner root coordinate system.
90 Rect GetCursorRect() const;
91
92 // The MethodChannel used for communication with the Flutter engine.
93 std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
94
95 // The associated |FlutterWindowsEngine|.
96 FlutterWindowsEngine* engine_;
97
98 // The active client id.
99 int client_id_;
100
101 // The active model. nullptr if not set.
102 std::unique_ptr<TextInputModel> active_model_;
103
104 // Whether to enable that the engine sends text input updates to the framework
105 // as TextEditingDeltas or as one TextEditingValue.
106 // For more information on the delta model, see:
107 // https://master-api.flutter.dev/flutter/services/TextInputConfiguration/enableDeltaModel.html
108 bool enable_delta_model = false;
109
110 // Keyboard type of the client. See available options:
111 // https://api.flutter.dev/flutter/services/TextInputType-class.html
112 std::string input_type_;
113
114 // An action requested by the user on the input client. See available options:
115 // https://api.flutter.dev/flutter/services/TextInputAction-class.html
116 std::string input_action_;
117
118 // The smallest rect, in local coordinates, of the text in the composing
119 // range, or of the caret in the case where there is no current composing
120 // range. This value is updated via `TextInput.setMarkedTextRect` messages
121 // over the text input channel.
122 Rect composing_rect_;
123
124 // A 4x4 matrix that maps from `EditableText` local coordinates to the
125 // coordinate system of `PipelineOwner.rootNode`.
126 std::array<std::array<double, 4>, 4> editabletext_transform_ = {
127 0.0, 0.0, 0.0, 0.0, //
128 0.0, 0.0, 0.0, 0.0, //
129 0.0, 0.0, 0.0, 0.0, //
130 0.0, 0.0, 0.0, 0.0};
131
133};
134
135} // namespace flutter
136
137#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_
void KeyboardHook(GLFWwindow *window, int key, int scancode, int action, int mods) override
TextInputPlugin(flutter::BinaryMessenger *messenger)
virtual void ComposeChangeHook(const std::u16string &text, int cursor_pos)
virtual void TextHook(const std::u16string &text)
FlutterEngine engine
Definition main.cc:68
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
GAsyncResult * result
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::u16string text
A change in the state of an input field.