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 class HostWindowSatellite;
25 
26 // Specifies a preferred content size for the window.
31 };
32 
33 // Specifies a preferred constraint on the window.
35  bool has_view_constraints = false;
40 };
41 
42 // Coordinates are in physical pixels.
43 struct WindowRect {
44  int32_t left;
45  int32_t top;
46  int32_t width;
47  int32_t height;
48 };
49 
50 // Sizes are in physical pixels.
51 struct WindowSize {
52  int32_t width;
53  int32_t height;
54 };
55 
56 // Sent by the framework to request a new window be created.
60  LPCWSTR title;
61  bool sized_to_content = false;
62  bool resizable = true;
63 };
64 
68  LPCWSTR title;
70  bool sized_to_content = false;
71  bool resizable = true;
72 };
73 
74 typedef void (*GetWindowPositionCallback)(const WindowSize& child_size,
75  const WindowRect& parent_rect,
76  const WindowRect& display_rect,
77  WindowRect& output_rect);
78 
81  HWND parent;
83 };
84 
87  HWND parent;
89 };
90 
94  HWND parent;
96  LPCWSTR title;
97  bool sized_to_content = false;
98  bool resizable = true;
99 };
100 
103  HWND hwnd;
104  UINT message;
105  WPARAM wParam;
106  LPARAM lParam;
107  LRESULT result;
108  bool handled;
109 };
110 
113 };
114 
115 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
116 // This represents the current content size of the window.
118  double width;
119  double height;
120 };
121 
125  FlutterEngineDisplayId display_id;
126 };
127 
128 // A manager class for managing |HostWindow| instances.
129 // A unique instance of this class is owned by |FlutterWindowsEngine|.
131  public:
132  explicit WindowManager(FlutterWindowsEngine* engine);
133  virtual ~WindowManager() = default;
134 
135  void Initialize(const WindowingInitRequest* request);
136 
138  const RegularWindowCreationRequest* request);
139 
141 
143  const TooltipWindowCreationRequest* request);
144 
146 
148  const SatelliteWindowCreationRequest* request);
149 
150  // Returns the satellite window hosted by |hwnd|, or nullptr if |hwnd| does
151  // not host a satellite window.
153 
154  // Message handler called by |HostWindow::WndProc| to process window
155  // messages before delegating them to the host window. This allows the
156  // manager to process messages that affect the state of other host windows.
157  std::optional<LRESULT> HandleMessage(HWND hwnd,
158  UINT message,
159  WPARAM wparam,
160  LPARAM lparam);
161 
162  void OnPreEngineRestart();
163 
164  void OnEngineShutdown();
165 
166  private:
167  // The Flutter engine that owns this manager.
168  FlutterWindowsEngine* const engine_;
169 
170  // Callback that relays windows messages to the isolate. Set
171  // during Initialize().
172  std::function<void(WindowsMessage*)> on_message_;
173 
174  // Isolate that runs the Dart code. Set during Initialize().
175  std::optional<Isolate> isolate_;
176 
177  // A map of active windows. Used to destroy remaining windows on engine
178  // shutdown.
179  std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
180 
181  FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
182 };
183 
184 } // namespace flutter
185 
186 extern "C" {
187 
190  int64_t engine_id,
191  const flutter::WindowingInitRequest* request);
192 
195  int64_t engine_id,
197 
200  int64_t engine_id,
201  const flutter::DialogWindowCreationRequest* request);
202 
205  int64_t engine_id,
207 
210  int64_t engine_id,
211  const flutter::PopupWindowCreationRequest* request);
212 
213 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
214 // NULL if the HWND cannot be found
217  int64_t engine_id,
218  FlutterViewId view_id);
219 
223 
226  HWND hwnd,
227  const flutter::WindowSizeRequest* size);
228 
231  HWND hwnd,
232  const flutter::WindowConstraints* constraints);
233 
236  HWND hwnd,
237  const flutter::FullscreenRequest* request);
238 
239 // Invoked by the framework when the host window receives WM_DESTROY.
242 
245 
248 
251 
254  int64_t engine_id,
256 
257 // Re-anchors the satellite window |satellite_hwnd| to |new_parent|. The
258 // satellite keeps its current screen position.
261  HWND satellite_hwnd,
262  HWND new_parent);
263 }
264 
265 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
static HostWindowSatellite * GetSatelliteWindowFromHandle(HWND hwnd)
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)
FlutterViewId CreatePopupWindow(const PopupWindowCreationRequest *request)
FlutterViewId CreateSatelliteWindow(const SatelliteWindowCreationRequest *request)
FlutterViewId CreateTooltipWindow(const TooltipWindowCreationRequest *request)
virtual ~WindowManager()=default
#define FLUTTER_EXPORT
Win32Message message
void(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &display_rect, WindowRect &output_rect)
int64_t FlutterViewId
FlutterEngineDisplayId display_id
GetWindowPositionCallback get_position_callback
GetWindowPositionCallback get_position_callback
GetWindowPositionCallback get_position_callback
void(* on_message)(WindowsMessage *)
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_UpdateTooltipPosition(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_UpdatePopupPosition(HWND hwnd)
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 FlutterViewId InternalFlutterWindows_WindowManager_CreateSatelliteWindow(int64_t engine_id, const flutter::SatelliteWindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetSatelliteParent(HWND satellite_hwnd, HWND new_parent)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(int64_t engine_id, const flutter::TooltipWindowCreationRequest *request)
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreatePopupWindow(int64_t engine_id, const flutter::PopupWindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd)