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 // Coordinates are in physical pixels.
42 struct WindowRect {
43  int32_t left;
44  int32_t top;
45  int32_t width;
46  int32_t height;
47 };
48 
49 // Sizes are in physical pixels.
50 struct WindowSize {
51  int32_t width;
52  int32_t height;
53 };
54 
55 // Sent by the framework to request a new window be created.
59  LPCWSTR title;
60  bool sized_to_content = false;
61  bool resizable = true;
62 };
63 
67  LPCWSTR title;
69  bool sized_to_content = false;
70  bool resizable = true;
71 };
72 
73 typedef WindowRect* (*GetWindowPositionCallback)(const WindowSize& child_size,
74  const WindowRect& parent_rect,
75  const WindowRect& output_rect);
76 
79  HWND parent;
81 };
82 
85  HWND parent;
87 };
88 
91  HWND hwnd;
92  UINT message;
93  WPARAM wParam;
94  LPARAM lParam;
95  LRESULT result;
96  bool handled;
97 };
98 
101 };
102 
103 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
104 // This represents the current content size of the window.
106  double width;
107  double height;
108 };
109 
113  FlutterEngineDisplayId display_id;
114 };
115 
116 // A manager class for managing |HostWindow| instances.
117 // A unique instance of this class is owned by |FlutterWindowsEngine|.
119  public:
120  explicit WindowManager(FlutterWindowsEngine* engine);
121  virtual ~WindowManager() = default;
122 
123  void Initialize(const WindowingInitRequest* request);
124 
126  const RegularWindowCreationRequest* request);
127 
129 
131  const TooltipWindowCreationRequest* request);
132 
134 
135  // Message handler called by |HostWindow::WndProc| to process window
136  // messages before delegating them to the host window. This allows the
137  // manager to process messages that affect the state of other host windows.
138  std::optional<LRESULT> HandleMessage(HWND hwnd,
139  UINT message,
140  WPARAM wparam,
141  LPARAM lparam);
142 
143  void OnEngineShutdown();
144 
145  private:
146  // The Flutter engine that owns this manager.
147  FlutterWindowsEngine* const engine_;
148 
149  // Callback that relays windows messages to the isolate. Set
150  // during Initialize().
151  std::function<void(WindowsMessage*)> on_message_;
152 
153  // Isolate that runs the Dart code. Set during Initialize().
154  std::optional<Isolate> isolate_;
155 
156  // A map of active windows. Used to destroy remaining windows on engine
157  // shutdown.
158  std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
159 
160  FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
161 };
162 
163 } // namespace flutter
164 
165 extern "C" {
166 
169  int64_t engine_id,
170  const flutter::WindowingInitRequest* request);
171 
174  int64_t engine_id,
176 
179  int64_t engine_id,
180  const flutter::DialogWindowCreationRequest* request);
181 
184  int64_t engine_id,
186 
189  int64_t engine_id,
190  const flutter::PopupWindowCreationRequest* request);
191 
192 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
193 // NULL if the HWND cannot be found
196  int64_t engine_id,
197  FlutterViewId view_id);
198 
202 
205  HWND hwnd,
206  const flutter::WindowSizeRequest* size);
207 
210  HWND hwnd,
211  const flutter::WindowConstraints* constraints);
212 
215  HWND hwnd,
216  const flutter::FullscreenRequest* request);
217 
218 // Invoked by the framework when the host window receives WM_DESTROY.
221 
224 
227 
230 }
231 
232 #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)
FlutterViewId CreatePopupWindow(const PopupWindowCreationRequest *request)
FlutterViewId CreateTooltipWindow(const TooltipWindowCreationRequest *request)
virtual ~WindowManager()=default
#define FLUTTER_EXPORT
Win32Message message
WindowRect *(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &output_rect)
int64_t FlutterViewId
FlutterEngineDisplayId display_id
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 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)