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/text_input_model.h" 14 #include "flutter/shell/platform/windows/keyboard_hook_handler.h" 15 #include "flutter/shell/platform/windows/public/flutter_windows.h" 16 17 namespace flutter { 18 19 class Win32FlutterWindow; 20 21 // Implements a text input plugin. 22 // 23 // Specifically handles window events within windows. 24 class TextInputPlugin : public KeyboardHookHandler { 25 public: 26 explicit TextInputPlugin(flutter::BinaryMessenger* messenger); 27 28 virtual ~TextInputPlugin(); 29 30 // |KeyboardHookHandler| 31 void KeyboardHook(Win32FlutterWindow* window, 32 int key, 33 int scancode, 34 int action, 35 int mods) override; 36 37 // |KeyboardHookHandler| 38 void CharHook(Win32FlutterWindow* window, unsigned int code_point) override; 39 40 private: 41 // Sends the current state of the given model to the Flutter engine. 42 void SendStateUpdate(const TextInputModel& model); 43 44 // Sends an action triggered by the Enter key to the Flutter engine. 45 void EnterPressed(TextInputModel* model); 46 47 // Called when a method is called on |channel_|; 48 void HandleMethodCall( 49 const flutter::MethodCall<rapidjson::Document>& method_call, 50 std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result); 51 52 // The MethodChannel used for communication with the Flutter engine. 53 std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_; 54 55 // Mapping of client IDs to text input models. 56 std::map<int, std::unique_ptr<TextInputModel>> input_models_; 57 58 // The active model. nullptr if not set. 59 TextInputModel* active_model_; 60 }; 61 62 } // namespace flutter 63 64 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_TEXT_INPUT_PLUGIN_H_ 65