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_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_ 6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_ 7 8 #include <flutter_windows.h> 9 10 #include <string> 11 #include <vector> 12 13 #include "flutter_window.h" 14 #include "plugin_registrar.h" 15 16 namespace flutter { 17 18 // A controller for a window displaying Flutter content. 19 // 20 // This is the primary wrapper class for the desktop C API. 21 // If you use this class, you should not call any of the setup or teardown 22 // methods in the C API directly, as this class will do that internally. 23 // 24 // Note: This is an early implementation which 25 // requires control of the application's event loop, and is thus useful 26 // primarily for building a simple one-window shell hosting a Flutter 27 // application. The final implementation and API will be very different. 28 class FlutterWindowController { 29 public: 30 // There must be only one instance of this class in an application at any 31 // given time, as Flutter does not support multiple engines in one process, 32 // or multiple views in one engine. 33 explicit FlutterWindowController(const std::string& icu_data_path); 34 35 ~FlutterWindowController(); 36 37 // Prevent copying. 38 FlutterWindowController(FlutterWindowController const&) = delete; 39 FlutterWindowController& operator=(FlutterWindowController const&) = delete; 40 41 // Creates and displays a window for displaying Flutter content. 42 // 43 // The |assets_path| is the path to the flutter_assets folder for the Flutter 44 // application to be run. |icu_data_path| is the path to the icudtl.dat file 45 // for the version of Flutter you are using. 46 // 47 // The |arguments| are passed to the Flutter engine. See: 48 // https://github.com/flutter/engine/blob/master/shell/common/switches.h for 49 // for details. Not all arguments will apply to desktop. 50 // 51 // Only one Flutter window can exist at a time; see constructor comment. 52 bool CreateWindow(int width, 53 int height, 54 const std::string& title, 55 const std::string& assets_path, 56 const std::vector<std::string>& arguments); 57 58 // Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the 59 // given name. 60 // 61 // The name must be unique across the application. 62 FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( 63 const std::string& plugin_name); 64 65 // The FlutterWindow managed by this controller, if any. Returns nullptr 66 // before CreateWindow is called, and after RunEventLoop returns; window()67 FlutterWindow* window() { return window_.get(); } 68 69 // Loops on Flutter window events until the window closes. 70 void RunEventLoop(); 71 72 private: 73 // The path to the ICU data file. Set at creation time since it is the same 74 // for any window created. 75 std::string icu_data_path_; 76 77 // Whether or not FlutterDesktopInit succeeded at creation time. 78 bool init_succeeded_ = false; 79 80 // The owned FlutterWindow, if any. 81 std::unique_ptr<FlutterWindow> window_; 82 83 // Handle for interacting with the C API's window controller, if any. 84 FlutterDesktopWindowControllerRef controller_ = nullptr; 85 }; 86 87 } // namespace flutter 88 89 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_WINDOW_CONTROLLER_H_ 90