Flutter Windows Embedder
window_manager.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_WINDOW_MANAGER_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
7 
8 #include <windows.h>
9 #include <functional>
10 #include <optional>
11 #include <unordered_map>
12 #include <vector>
13 
15 
16 #include "flutter/fml/macros.h"
18 #include "flutter/shell/platform/embedder/embedder.h"
19 
20 namespace flutter {
21 
22 class FlutterWindowsEngine;
23 class HostWindow;
24 
25 // Specifies a preferred content size for the window.
30 };
31 
32 // Specifies a preferred constraint on the window.
34  bool has_view_constraints = false;
39 };
40 
41 // Sent by the framework to request a new window be created.
45  LPCWSTR title;
46 };
47 
51  LPCWSTR title;
53 };
54 
57  HWND hwnd;
58  UINT message;
59  WPARAM wParam;
60  LPARAM lParam;
61  LRESULT result;
62  bool handled;
63 };
64 
67 };
68 
69 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
70 // This represents the current content size of the window.
72  double width;
73  double height;
74 };
75 
77  bool fullscreen;
79  FlutterEngineDisplayId display_id;
80 };
81 
82 // A manager class for managing |HostWindow| instances.
83 // A unique instance of this class is owned by |FlutterWindowsEngine|.
85  public:
86  explicit WindowManager(FlutterWindowsEngine* engine);
87  virtual ~WindowManager() = default;
88 
89  void Initialize(const WindowingInitRequest* request);
90 
92  const RegularWindowCreationRequest* request);
93 
95 
96  // Message handler called by |HostWindow::WndProc| to process window
97  // messages before delegating them to the host window. This allows the
98  // manager to process messages that affect the state of other host windows.
99  std::optional<LRESULT> HandleMessage(HWND hwnd,
100  UINT message,
101  WPARAM wparam,
102  LPARAM lparam);
103 
104  void OnEngineShutdown();
105 
106  private:
107  // The Flutter engine that owns this manager.
108  FlutterWindowsEngine* const engine_;
109 
110  // Callback that relays windows messages to the isolate. Set
111  // during Initialize().
112  std::function<void(WindowsMessage*)> on_message_;
113 
114  // Isolate that runs the Dart code. Set during Initialize().
115  std::optional<Isolate> isolate_;
116 
117  // A map of active windows. Used to destroy remaining windows on engine
118  // shutdown.
119  std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
120 
121  FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
122 };
123 
124 } // namespace flutter
125 
126 extern "C" {
127 
130  int64_t engine_id,
131  const flutter::WindowingInitRequest* request);
132 
135  int64_t engine_id,
137 
140  int64_t engine_id,
141  const flutter::DialogWindowCreationRequest* request);
142 
143 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
144 // NULL if the HWND cannot be found
147  int64_t engine_id,
148  FlutterViewId view_id);
149 
153 
156  HWND hwnd,
157  const flutter::WindowSizeRequest* size);
158 
161  HWND hwnd,
162  const flutter::WindowConstraints* constraints);
163 
166  HWND hwnd,
167  const flutter::FullscreenRequest* request);
168 
171 }
172 
173 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest *request)
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
FlutterViewId CreateRegularWindow(const RegularWindowCreationRequest *request)
void Initialize(const WindowingInitRequest *request)
WindowManager(FlutterWindowsEngine *engine)
virtual ~WindowManager()=default
#define FLUTTER_EXPORT
Win32Message message
int64_t FlutterViewId
FlutterEngineDisplayId display_id
void(* on_message)(WindowsMessage *)
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)