| 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/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
21 namespace flutter {
22
23 class TextInputPluginDelegate;
24
25 // Implements a text input plugin.
26 //
27 // Specifically handles window events within windows.
28 class TextInputPlugin {
29 public:
30 explicit TextInputPlugin(flutter::BinaryMessenger* messenger,
31 TextInputPluginDelegate* delegate);
32
33 virtual ~TextInputPlugin();
34
35 virtual void KeyboardHook(int key,
36 int scancode,
37 int action,
38 char32_t character,
39 bool extended,
40 bool was_down);
41
42 virtual void TextHook(const std::u16string& text);
43
44 virtual void ComposeBeginHook();
45
46 virtual void ComposeCommitHook();
47
48 virtual void ComposeEndHook();
49
50 virtual void ComposeChangeHook(const std::u16string& text, int cursor_pos);
51
52 private:
53 // Sends the current state of the given model to the Flutter engine.
54 void SendStateUpdate(const TextInputModel& model);
55
56 // Sends the current state of the given model to the Flutter engine.
57 void SendStateUpdateWithDelta(const TextInputModel& model,
58 const TextEditingDelta*);
59
60 // Sends an action triggered by the Enter key to the Flutter engine.
61 void EnterPressed(TextInputModel* model);
62
63 // Called when a method is called on |channel_|;
64 void HandleMethodCall(
65 const flutter::MethodCall<rapidjson::Document>& method_call,
66 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result);
67
68 // Returns the composing rect, or if IME composing mode is not active, the
69 // cursor rect in the PipelineOwner root coordinate system.
70 Rect GetCursorRect() const;
71
72 // The MethodChannel used for communication with the Flutter engine.
73 std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
74
75 // The associated |TextInputPluginDelegate|.
76 TextInputPluginDelegate* delegate_;
77
78 // The active client id.
79 int client_id_;
80
81 // The active model. nullptr if not set.
82 std::unique_ptr<TextInputModel> active_model_;
83
84 // Whether to enable that the engine sends text input updates to the framework
85 // as TextEditingDeltas or as one TextEditingValue.
86 // For more information on the delta model, see:
87 // https://master-api.flutter.dev/flutter/services/TextInputConfiguration/enableDeltaModel.html
88 bool enable_delta_model;
89
90 // Keyboard type of the client. See available options:
91 // https://api.flutter.dev/flutter/services/TextInputType-class.html
92 std::string input_type_;
93
94 // An action requested by the user on the input client. See available options:
95 // https://api.flutter.dev/flutter/services/TextInputAction-class.html
96 std::string input_action_;
97
98 // The smallest rect, in local coordinates, of the text in the composing
99 // range, or of the caret in the case where there is no current composing
100 // range. This value is updated via `TextInput.setMarkedTextRect` messages
101 // over the text input channel.
102 Rect composing_rect_;
103
104 // A 4x4 matrix that maps from `EditableText` local coordinates to the
105 // coordinate system of `PipelineOwner.rootNode`.
106 std::array<std::array<double, 4>, 4> editabletext_transform_ = {
107 0.0, 0.0, 0.0, 0.0, //
108 0.0, 0.0, 0.0, 0.0, //
109 0.0, 0.0, 0.0, 0.0, //
110 0.0, 0.0, 0.0, 0.0};
111
112 FML_DISALLOW_COPY_AND_ASSIGN(TextInputPlugin);
113 };
114
115 } // namespace flutter
116
117 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_
flutter::TextInputPlugin::ComposeBeginHook
virtual void ComposeBeginHook()
Definition: text_input_plugin.cc:124
flutter::TextInputPlugin::ComposeChangeHook
virtual void ComposeChangeHook(const std::u16string &text, int cursor_pos)
Definition: text_input_plugin.cc:191
flutter::TextInputPlugin::TextInputPlugin
TextInputPlugin(flutter::BinaryMessenger *messenger, TextInputPluginDelegate *delegate)
Definition: text_input_plugin.cc:106
scancode
int scancode
Definition: keyboard_key_handler_unittests.cc:115
geometry.h
was_down
bool was_down
Definition: keyboard_key_handler_unittests.cc:119
extended
bool extended
Definition: keyboard_key_handler_unittests.cc:118
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
flutter::TextInputPlugin::ComposeEndHook
virtual void ComposeEndHook()
Definition: text_input_plugin.cc:174
json_method_codec.h
flutter::TextInputPlugin::~TextInputPlugin
virtual ~TextInputPlugin()
flutter::TextInputPlugin::ComposeCommitHook
virtual void ComposeCommitHook()
Definition: text_input_plugin.cc:139
flutter::Rect
Definition: geometry.h:56
binary_messenger.h
flutter::TextInputPluginDelegate
Definition: text_input_plugin_delegate.h:13
text_input_model.h
flutter::BinaryMessenger
Definition: binary_messenger.h:28
text
std::u16string text
Definition: keyboard_unittests.cc:332
flutter::TextInputPlugin::TextHook
virtual void TextHook(const std::u16string &text)
Definition: text_input_plugin.cc:66
flutter::MethodCall
Definition: method_call.h:18
flutter
Definition: accessibility_bridge_windows.cc:11
keyboard_handler_base.h
flutter::TextInputPlugin
Definition: text_input_plugin.h:28
flutter::MethodResult
Definition: method_result.h:17
method_channel.h
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:84
flutter::TextInputModel
Definition: text_input_model.h:18
action
int action
Definition: keyboard_key_handler_unittests.cc:116
text_editing_delta.h
key
int key
Definition: keyboard_key_handler_unittests.cc:114
flutter::TextEditingDelta
A change in the state of an input field.
Definition: text_editing_delta.h:16