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"
21
22namespace flutter {
23
24class FlutterWindowsEngine;
25
26// Implements a text input plugin.
27//
28// Specifically handles window events within windows.
29class TextInputPlugin {
30 public:
32 FlutterWindowsEngine* engine);
33
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.
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(
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
140};
141
142} // namespace flutter
143
144#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:84
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
std::u16string text
int64_t FlutterViewId
A change in the state of an input field.