| Flutter Windows Embedder |

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