Flutter Engine
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 <map>
9 #include <memory>
10 
11 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
12 #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h"
13 #include "flutter/shell/platform/common/cpp/json_method_codec.h"
14 #include "flutter/shell/platform/common/cpp/text_input_model.h"
15 #include "flutter/shell/platform/windows/keyboard_hook_handler.h"
16 #include "flutter/shell/platform/windows/public/flutter_windows.h"
17 
18 namespace flutter {
19 
20 class FlutterWindowsView;
21 
22 // Implements a text input plugin.
23 //
24 // Specifically handles window events within windows.
25 class TextInputPlugin : public KeyboardHookHandler {
26  public:
27  explicit TextInputPlugin(flutter::BinaryMessenger* messenger);
28 
29  virtual ~TextInputPlugin();
30 
31  // |KeyboardHookHandler|
32  void KeyboardHook(FlutterWindowsView* view,
33  int key,
34  int scancode,
35  int action,
36  char32_t character) override;
37 
38  // |KeyboardHookHandler|
39  void TextHook(FlutterWindowsView* view, const std::u16string& text) override;
40 
41  private:
42  // Sends the current state of the given model to the Flutter engine.
43  void SendStateUpdate(const TextInputModel& model);
44 
45  // Sends an action triggered by the Enter key to the Flutter engine.
46  void EnterPressed(TextInputModel* model);
47 
48  // Called when a method is called on |channel_|;
49  void HandleMethodCall(
51  std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result);
52 
53  // The MethodChannel used for communication with the Flutter engine.
54  std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
55 
56  // The active client id.
57  int client_id_;
58 
59  // The active model. nullptr if not set.
60  std::unique_ptr<TextInputModel> active_model_;
61 
62  // Keyboard type of the client. See available options:
63  // https://docs.flutter.io/flutter/services/TextInputType-class.html
64  std::string input_type_;
65 
66  // An action requested by the user on the input client. See available options:
67  // https://docs.flutter.io/flutter/services/TextInputAction-class.html
68  std::string input_action_;
69 };
70 
71 } // namespace flutter
72 
73 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_
G_BEGIN_DECLS FlMethodCall * method_call
SemanticsAction action
void KeyboardHook(GLFWwindow *window, int key, int scancode, int action, int mods) override
void TextHook(FlutterWindowsView *view, const std::u16string &text) override
TextInputPlugin(flutter::BinaryMessenger *messenger)