Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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 // Called when a view is removed from the engine.
74 //
75 // If the removed view is the currently active view for text input, resets
76 // the active model and view id to prevent stale references. The implicit
77 // view is excluded from this reset.
79
80 private:
81 // Allows modifying the TextInputPlugin in tests.
83
84 // Sends the current state of the given model to the Flutter engine.
85 void SendStateUpdate(const TextInputModel& model);
86
87 // Sends the current state of the given model to the Flutter engine.
88 void SendStateUpdateWithDelta(const TextInputModel& model,
89 const TextEditingDelta*);
90
91 // Sends an action triggered by the Enter key to the Flutter engine.
92 void EnterPressed(TextInputModel* model);
93
94 // Called when a method is called on |channel_|;
95 void HandleMethodCall(
97 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result);
98
99 // Returns the composing rect, or if IME composing mode is not active, the
100 // cursor rect in the PipelineOwner root coordinate system.
101 Rect GetCursorRect() const;
102
103 // The MethodChannel used for communication with the Flutter engine.
104 std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
105
106 // The associated |FlutterWindowsEngine|.
107 FlutterWindowsEngine* engine_;
108
109 // The active client id.
110 int client_id_;
111
112 // The active view id.
113 FlutterViewId view_id_ = 0;
114
115 // The active model. nullptr if not set.
116 std::unique_ptr<TextInputModel> active_model_;
117
118 // Whether to enable that the engine sends text input updates to the framework
119 // as TextEditingDeltas or as one TextEditingValue.
120 // For more information on the delta model, see:
121 // https://master-api.flutter.dev/flutter/services/TextInputConfiguration/enableDeltaModel.html
122 bool enable_delta_model = false;
123
124 // Keyboard type of the client. See available options:
125 // https://api.flutter.dev/flutter/services/TextInputType-class.html
126 std::string input_type_;
127
128 // An action requested by the user on the input client. See available options:
129 // https://api.flutter.dev/flutter/services/TextInputAction-class.html
130 std::string input_action_;
131
132 // The smallest rect, in local coordinates, of the text in the composing
133 // range, or of the caret in the case where there is no current composing
134 // range. This value is updated via `TextInput.setMarkedTextRect` messages
135 // over the text input channel.
136 Rect composing_rect_;
137
138 // A 4x4 matrix that maps from `EditableText` local coordinates to the
139 // coordinate system of `PipelineOwner.rootNode`.
140 std::array<std::array<double, 4>, 4> editabletext_transform_ = {
141 0.0, 0.0, 0.0, 0.0, //
142 0.0, 0.0, 0.0, 0.0, //
143 0.0, 0.0, 0.0, 0.0, //
144 0.0, 0.0, 0.0, 0.0};
145
147};
148
149} // namespace flutter
150
151#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)
void OnViewRemoved(FlutterViewId view_id)
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
G_BEGIN_DECLS FlutterViewId view_id
#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.