Flutter Engine
flutter_view_controller.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_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_CONTROLLER_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_CONTROLLER_H_
7 
8 #include <flutter_windows.h>
9 #include <windows.h>
10 
11 #include <memory>
12 #include <optional>
13 
14 #include "dart_project.h"
15 #include "flutter_engine.h"
16 #include "flutter_view.h"
17 #include "plugin_registrar.h"
18 #include "plugin_registry.h"
19 
20 namespace flutter {
21 
22 // A controller for a view displaying Flutter content.
23 //
24 // This is the primary wrapper class for the desktop C API.
25 // If you use this class, you should not call any of the setup or teardown
26 // methods in the C API directly, as this class will do that internally.
28  public:
29  // Creates a FlutterView that can be parented into a Windows View hierarchy
30  // either using HWNDs or in the future into a CoreWindow, or using compositor.
31  //
32  // |dart_project| will be used to configure the engine backing this view.
33  explicit FlutterViewController(int width,
34  int height,
35  const DartProject& project);
36 
37  virtual ~FlutterViewController();
38 
39  // Prevent copying.
42 
43  // Returns the engine running Flutter content in this view.
44  FlutterEngine* engine() { return engine_.get(); }
45 
46  // Returns the view managed by this controller.
47  FlutterView* view() { return view_.get(); }
48 
49  // Allows the Flutter engine and any interested plugins an opportunity to
50  // handle the given message.
51  //
52  // If a result is returned, then the message was handled in such a way that
53  // further handling should not be done.
54  std::optional<LRESULT> HandleTopLevelWindowProc(HWND hwnd,
55  UINT message,
56  WPARAM wparam,
57  LPARAM lparam);
58 
59  private:
60  // Handle for interacting with the C API's view controller, if any.
61  FlutterDesktopViewControllerRef controller_ = nullptr;
62 
63  // The backing engine
64  std::unique_ptr<FlutterEngine> engine_;
65 
66  // The owned FlutterView.
67  std::unique_ptr<FlutterView> view_;
68 };
69 
70 } // namespace flutter
71 
72 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_FLUTTER_VIEW_CONTROLLER_H_
FlutterViewController(int width, int height, const DartProject &project)
std::optional< LRESULT > HandleTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
int32_t height
int32_t width
FlutterViewController & operator=(FlutterViewController const &)=delete