| 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
14 #include "flutter/shell/platform/common/public/flutter_export.h"
15
16 #include "flutter/fml/macros.h"
17 #include "flutter/shell/platform/common/isolate_scope.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.
26 struct WindowSizeRequest {
27 bool has_preferred_view_size = false;
28 double preferred_view_width;
29 double preferred_view_height;
30 };
31
32 // Specifies a preferred constraint on the window.
33 struct WindowConstraints {
34 bool has_view_constraints = false;
35 double view_min_width;
36 double view_min_height;
37 double view_max_width;
38 double view_max_height;
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.
56 struct RegularWindowCreationRequest {
57 WindowSizeRequest preferred_size;
58 WindowConstraints preferred_constraints;
59 LPCWSTR title;
60 };
61
62 struct DialogWindowCreationRequest {
63 WindowSizeRequest preferred_size;
64 WindowConstraints preferred_constraints;
65 LPCWSTR title;
66 HWND parent_or_null;
67 };
68
69 typedef WindowRect* (*GetWindowPositionCallback)(const WindowSize& child_size,
70 const WindowRect& parent_rect,
71 const WindowRect& output_rect);
72
73 struct TooltipWindowCreationRequest {
74 WindowConstraints preferred_constraints;
75 bool is_sized_to_content;
76 HWND parent;
77 GetWindowPositionCallback get_position_callback;
78 };
79
80 struct WindowsMessage {
81 FlutterViewId view_id;
82 HWND hwnd;
83 UINT message;
84 WPARAM wParam;
85 LPARAM lParam;
86 LRESULT result;
87 bool handled;
88 };
89
90 struct WindowingInitRequest {
91 void (*on_message)(WindowsMessage*);
92 };
93
94 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
95 // This represents the current content size of the window.
96 struct ActualWindowSize {
97 double width;
98 double height;
99 };
100
101 struct FullscreenRequest {
102 bool fullscreen;
103 bool has_display_id;
104 FlutterEngineDisplayId display_id;
105 };
106
107 // A manager class for managing |HostWindow| instances.
108 // A unique instance of this class is owned by |FlutterWindowsEngine|.
109 class WindowManager {
110 public:
111 explicit WindowManager(FlutterWindowsEngine* engine);
112 virtual ~WindowManager() = default;
113
114 void Initialize(const WindowingInitRequest* request);
115
116 FlutterViewId CreateRegularWindow(
117 const RegularWindowCreationRequest* request);
118
119 FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest* request);
120
121 FlutterViewId CreateTooltipWindow(
122 const TooltipWindowCreationRequest* request);
123
124 // Message handler called by |HostWindow::WndProc| to process window
125 // messages before delegating them to the host window. This allows the
126 // manager to process messages that affect the state of other host windows.
127 std::optional<LRESULT> HandleMessage(HWND hwnd,
128 UINT message,
129 WPARAM wparam,
130 LPARAM lparam);
131
132 void OnEngineShutdown();
133
134 private:
135 // The Flutter engine that owns this manager.
136 FlutterWindowsEngine* const engine_;
137
138 // Callback that relays windows messages to the isolate. Set
139 // during Initialize().
140 std::function<void(WindowsMessage*)> on_message_;
141
142 // Isolate that runs the Dart code. Set during Initialize().
143 std::optional<Isolate> isolate_;
144
145 // A map of active windows. Used to destroy remaining windows on engine
146 // shutdown.
147 std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
148
149 FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
150 };
151
152 } // namespace flutter
153
154 extern "C" {
155
156 FLUTTER_EXPORT
157 void InternalFlutterWindows_WindowManager_Initialize(
158 int64_t engine_id,
159 const flutter::WindowingInitRequest* request);
160
161 FLUTTER_EXPORT
162 FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(
163 int64_t engine_id,
164 const flutter::RegularWindowCreationRequest* request);
165
166 FLUTTER_EXPORT
167 FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(
168 int64_t engine_id,
169 const flutter::DialogWindowCreationRequest* request);
170
171 FLUTTER_EXPORT
172 FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(
173 int64_t engine_id,
174 const flutter::TooltipWindowCreationRequest* request);
175
176 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
177 // NULL if the HWND cannot be found
178 FLUTTER_EXPORT
179 HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
180 int64_t engine_id,
181 FlutterViewId view_id);
182
183 FLUTTER_EXPORT
184 flutter::ActualWindowSize
185 InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd);
186
187 FLUTTER_EXPORT
188 void InternalFlutterWindows_WindowManager_SetWindowSize(
189 HWND hwnd,
190 const flutter::WindowSizeRequest* size);
191
192 FLUTTER_EXPORT
193 void InternalFlutterWindows_WindowManager_SetWindowConstraints(
194 HWND hwnd,
195 const flutter::WindowConstraints* constraints);
196
197 FLUTTER_EXPORT
198 void InternalFlutterWindows_WindowManager_SetFullscreen(
199 HWND hwnd,
200 const flutter::FullscreenRequest* request);
201
202 // Invoked by the framework when the host window receives WM_DESTROY.
203 FLUTTER_EXPORT
204 void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd);
205
206 FLUTTER_EXPORT
207 bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd);
208
209 FLUTTER_EXPORT
210 void InternalFlutterWindows_WindowManager_UpdateTooltipPosition(HWND hwnd);
211 }
212
213 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:92
flutter::WindowManager
Definition: window_manager.h:109
flutter::WindowManager::OnEngineShutdown
void OnEngineShutdown()
Definition: window_manager.cc:74
flutter::WindowManager::CreateDialogWindow
FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest *request)
Definition: window_manager.cc:45
flutter::WindowManager::HandleMessage
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: window_manager.cc:90
flutter::WindowManager::CreateRegularWindow
FlutterViewId CreateRegularWindow(const RegularWindowCreationRequest *request)
Definition: window_manager.cc:31
flutter::WindowManager::Initialize
void Initialize(const WindowingInitRequest *request)
Definition: window_manager.cc:26
flutter::WindowManager::WindowManager
WindowManager(FlutterWindowsEngine *engine)
Definition: window_manager.cc:24
flutter::WindowManager::CreateTooltipWindow
FlutterViewId CreateTooltipWindow(const TooltipWindowCreationRequest *request)
Definition: window_manager.cc:59
flutter::WindowManager::~WindowManager
virtual ~WindowManager()=default
flutter_export.h
FLUTTER_EXPORT
#define FLUTTER_EXPORT
Definition: flutter_export.h:23
isolate_scope.h
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::GetWindowPositionCallback
WindowRect *(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &output_rect)
Definition: window_manager.h:69
flutter::FlutterViewId
int64_t FlutterViewId
Definition: accessibility_plugin.h:15
flutter::ActualWindowSize
Definition: window_manager.h:96
flutter::ActualWindowSize::width
double width
Definition: window_manager.h:97
flutter::ActualWindowSize::height
double height
Definition: window_manager.h:98
flutter::DialogWindowCreationRequest
Definition: window_manager.h:62
flutter::DialogWindowCreationRequest::title
LPCWSTR title
Definition: window_manager.h:65
flutter::DialogWindowCreationRequest::preferred_size
WindowSizeRequest preferred_size
Definition: window_manager.h:63
flutter::DialogWindowCreationRequest::parent_or_null
HWND parent_or_null
Definition: window_manager.h:66
flutter::DialogWindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:64
flutter::FullscreenRequest
Definition: window_manager.h:101
flutter::FullscreenRequest::has_display_id
bool has_display_id
Definition: window_manager.h:103
flutter::FullscreenRequest::fullscreen
bool fullscreen
Definition: window_manager.h:102
flutter::FullscreenRequest::display_id
FlutterEngineDisplayId display_id
Definition: window_manager.h:104
flutter::RegularWindowCreationRequest
Definition: window_manager.h:56
flutter::RegularWindowCreationRequest::preferred_size
WindowSizeRequest preferred_size
Definition: window_manager.h:57
flutter::RegularWindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:58
flutter::RegularWindowCreationRequest::title
LPCWSTR title
Definition: window_manager.h:59
flutter::TooltipWindowCreationRequest
Definition: window_manager.h:73
flutter::TooltipWindowCreationRequest::is_sized_to_content
bool is_sized_to_content
Definition: window_manager.h:75
flutter::TooltipWindowCreationRequest::parent
HWND parent
Definition: window_manager.h:76
flutter::TooltipWindowCreationRequest::get_position_callback
GetWindowPositionCallback get_position_callback
Definition: window_manager.h:77
flutter::TooltipWindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:74
flutter::WindowConstraints
Definition: window_manager.h:33
flutter::WindowConstraints::view_max_width
double view_max_width
Definition: window_manager.h:37
flutter::WindowConstraints::view_min_width
double view_min_width
Definition: window_manager.h:35
flutter::WindowConstraints::has_view_constraints
bool has_view_constraints
Definition: window_manager.h:34
flutter::WindowConstraints::view_max_height
double view_max_height
Definition: window_manager.h:38
flutter::WindowConstraints::view_min_height
double view_min_height
Definition: window_manager.h:36
flutter::WindowRect
Definition: window_manager.h:42
flutter::WindowRect::left
int32_t left
Definition: window_manager.h:43
flutter::WindowRect::height
int32_t height
Definition: window_manager.h:46
flutter::WindowRect::top
int32_t top
Definition: window_manager.h:44
flutter::WindowRect::width
int32_t width
Definition: window_manager.h:45
flutter::WindowSize
Definition: window_manager.h:50
flutter::WindowSize::width
int32_t width
Definition: window_manager.h:51
flutter::WindowSize::height
int32_t height
Definition: window_manager.h:52
flutter::WindowSizeRequest
Definition: window_manager.h:26
flutter::WindowSizeRequest::preferred_view_height
double preferred_view_height
Definition: window_manager.h:29
flutter::WindowSizeRequest::preferred_view_width
double preferred_view_width
Definition: window_manager.h:28
flutter::WindowSizeRequest::has_preferred_view_size
bool has_preferred_view_size
Definition: window_manager.h:27
flutter::WindowingInitRequest
Definition: window_manager.h:90
flutter::WindowingInitRequest::on_message
void(* on_message)(WindowsMessage *)
Definition: window_manager.h:91
flutter::WindowsMessage
Definition: window_manager.h:80
flutter::WindowsMessage::hwnd
HWND hwnd
Definition: window_manager.h:82
flutter::WindowsMessage::wParam
WPARAM wParam
Definition: window_manager.h:84
flutter::WindowsMessage::message
UINT message
Definition: window_manager.h:83
flutter::WindowsMessage::result
LRESULT result
Definition: window_manager.h:86
flutter::WindowsMessage::view_id
FlutterViewId view_id
Definition: window_manager.h:81
flutter::WindowsMessage::lParam
LPARAM lParam
Definition: window_manager.h:85
flutter::WindowsMessage::handled
bool handled
Definition: window_manager.h:87
InternalFlutterWindows_WindowManager_GetFullscreen
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
Definition: window_manager.cc:235
InternalFlutterWindows_WindowManager_UpdateTooltipPosition
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_UpdateTooltipPosition(HWND hwnd)
Definition: window_manager.cc:245
InternalFlutterWindows_WindowManager_SetWindowSize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
Definition: window_manager.cc:184
InternalFlutterWindows_WindowManager_GetWindowContentSize
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:180
InternalFlutterWindows_WindowManager_SetWindowConstraints
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
Definition: window_manager.cc:213
InternalFlutterWindows_WindowManager_CreateDialogWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
Definition: window_manager.cc:149
InternalFlutterWindows_WindowManager_SetFullscreen
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
Definition: window_manager.cc:222
InternalFlutterWindows_WindowManager_CreateRegularWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
Definition: window_manager.cc:140
InternalFlutterWindows_WindowManager_Initialize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:132
InternalFlutterWindows_WindowManager_CreateTooltipWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(int64_t engine_id, const flutter::TooltipWindowCreationRequest *request)
Definition: window_manager.cc:158
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:166
InternalFlutterWindows_WindowManager_OnDestroyWindow
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd)
Definition: window_manager.cc:193