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"
20 
21 namespace flutter {
22 
23 class FlutterWindowsEngine;
24 
25 // Implements a text input plugin.
26 //
27 // Specifically handles window events within windows.
29  public:
31  FlutterWindowsEngine* engine);
32 
33  virtual ~TextInputPlugin();
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(
86  std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result);
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 
132  FML_DISALLOW_COPY_AND_ASSIGN(TextInputPlugin);
133 };
134 
135 } // namespace flutter
136 
137 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_
flutter::TextInputPlugin::ComposeBeginHook
virtual void ComposeBeginHook()
Definition: text_input_plugin.cc:125
flutter::TextInputPlugin::ComposeChangeHook
virtual void ComposeChangeHook(const std::u16string &text, int cursor_pos)
Definition: text_input_plugin.cc:192
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
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:90
character
char32_t character
Definition: keyboard_key_handler_unittests.cc:117
flutter::TextInputPlugin::ComposeEndHook
virtual void ComposeEndHook()
Definition: text_input_plugin.cc:175
json_method_codec.h
flutter::TextInputPlugin::~TextInputPlugin
virtual ~TextInputPlugin()
flutter::TextInputPlugin::ComposeCommitHook
virtual void ComposeCommitHook()
Definition: text_input_plugin.cc:140
flutter::Rect
Definition: geometry.h:56
binary_messenger.h
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:67
flutter::MethodCall
Definition: method_call.h:18
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::TextInputPlugin::TextInputPlugin
TextInputPlugin(flutter::BinaryMessenger *messenger, FlutterWindowsEngine *engine)
Definition: text_input_plugin.cc:107
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:85
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