| 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 HWND parent;
76 GetWindowPositionCallback get_position_callback;
77 };
78
79 struct WindowsMessage {
80 FlutterViewId view_id;
81 HWND hwnd;
82 UINT message;
83 WPARAM wParam;
84 LPARAM lParam;
85 LRESULT result;
86 bool handled;
87 };
88
89 struct WindowingInitRequest {
90 void (*on_message)(WindowsMessage*);
91 };
92
93 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
94 // This represents the current content size of the window.
95 struct ActualWindowSize {
96 double width;
97 double height;
98 };
99
100 struct FullscreenRequest {
101 bool fullscreen;
102 bool has_display_id;
103 FlutterEngineDisplayId display_id;
104 };
105
106 // A manager class for managing |HostWindow| instances.
107 // A unique instance of this class is owned by |FlutterWindowsEngine|.
108 class WindowManager {
109 public:
110 explicit WindowManager(FlutterWindowsEngine* engine);
111 virtual ~WindowManager() = default;
112
113 void Initialize(const WindowingInitRequest* request);
114
115 FlutterViewId CreateRegularWindow(
116 const RegularWindowCreationRequest* request);
117
118 FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest* request);
119
120 FlutterViewId CreateTooltipWindow(
121 const TooltipWindowCreationRequest* request);
122
123 // Message handler called by |HostWindow::WndProc| to process window
124 // messages before delegating them to the host window. This allows the
125 // manager to process messages that affect the state of other host windows.
126 std::optional<LRESULT> HandleMessage(HWND hwnd,
127 UINT message,
128 WPARAM wparam,
129 LPARAM lparam);
130
131 void OnEngineShutdown();
132
133 private:
134 // The Flutter engine that owns this manager.
135 FlutterWindowsEngine* const engine_;
136
137 // Callback that relays windows messages to the isolate. Set
138 // during Initialize().
139 std::function<void(WindowsMessage*)> on_message_;
140
141 // Isolate that runs the Dart code. Set during Initialize().
142 std::optional<Isolate> isolate_;
143
144 // A map of active windows. Used to destroy remaining windows on engine
145 // shutdown.
146 std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
147
148 FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
149 };
150
151 } // namespace flutter
152
153 extern "C" {
154
155 FLUTTER_EXPORT
156 void InternalFlutterWindows_WindowManager_Initialize(
157 int64_t engine_id,
158 const flutter::WindowingInitRequest* request);
159
160 FLUTTER_EXPORT
161 FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(
162 int64_t engine_id,
163 const flutter::RegularWindowCreationRequest* request);
164
165 FLUTTER_EXPORT
166 FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(
167 int64_t engine_id,
168 const flutter::DialogWindowCreationRequest* request);
169
170 FLUTTER_EXPORT
171 FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(
172 int64_t engine_id,
173 const flutter::TooltipWindowCreationRequest* request);
174
175 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
176 // NULL if the HWND cannot be found
177 FLUTTER_EXPORT
178 HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
179 int64_t engine_id,
180 FlutterViewId view_id);
181
182 FLUTTER_EXPORT
183 flutter::ActualWindowSize
184 InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd);
185
186 FLUTTER_EXPORT
187 void InternalFlutterWindows_WindowManager_SetWindowSize(
188 HWND hwnd,
189 const flutter::WindowSizeRequest* size);
190
191 FLUTTER_EXPORT
192 void InternalFlutterWindows_WindowManager_SetWindowConstraints(
193 HWND hwnd,
194 const flutter::WindowConstraints* constraints);
195
196 FLUTTER_EXPORT
197 void InternalFlutterWindows_WindowManager_SetFullscreen(
198 HWND hwnd,
199 const flutter::FullscreenRequest* request);
200
201 // Invoked by the framework when the host window receives WM_DESTROY.
202 FLUTTER_EXPORT
203 void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd);
204
205 FLUTTER_EXPORT
206 bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd);
207
208 FLUTTER_EXPORT
209 void InternalFlutterWindows_WindowManager_UpdateTooltipPosition(HWND hwnd);
210 }
211
212 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:92
flutter::WindowManager
Definition: window_manager.h:108
flutter::WindowManager::OnEngineShutdown
void OnEngineShutdown()
Definition: window_manager.cc:73
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:89
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:95
flutter::ActualWindowSize::width
double width
Definition: window_manager.h:96
flutter::ActualWindowSize::height
double height
Definition: window_manager.h:97
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:100
flutter::FullscreenRequest::has_display_id
bool has_display_id
Definition: window_manager.h:102
flutter::FullscreenRequest::fullscreen
bool fullscreen
Definition: window_manager.h:101
flutter::FullscreenRequest::display_id
FlutterEngineDisplayId display_id
Definition: window_manager.h:103
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::parent
HWND parent
Definition: window_manager.h:75
flutter::TooltipWindowCreationRequest::get_position_callback
GetWindowPositionCallback get_position_callback
Definition: window_manager.h:76
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:89
flutter::WindowingInitRequest::on_message
void(* on_message)(WindowsMessage *)
Definition: window_manager.h:90
flutter::WindowsMessage
Definition: window_manager.h:79
flutter::WindowsMessage::hwnd
HWND hwnd
Definition: window_manager.h:81
flutter::WindowsMessage::wParam
WPARAM wParam
Definition: window_manager.h:83
flutter::WindowsMessage::message
UINT message
Definition: window_manager.h:82
flutter::WindowsMessage::result
LRESULT result
Definition: window_manager.h:85
flutter::WindowsMessage::view_id
FlutterViewId view_id
Definition: window_manager.h:80
flutter::WindowsMessage::lParam
LPARAM lParam
Definition: window_manager.h:84
flutter::WindowsMessage::handled
bool handled
Definition: window_manager.h:86
InternalFlutterWindows_WindowManager_GetFullscreen
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
Definition: window_manager.cc:234
InternalFlutterWindows_WindowManager_UpdateTooltipPosition
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_UpdateTooltipPosition(HWND hwnd)
Definition: window_manager.cc:244
InternalFlutterWindows_WindowManager_SetWindowSize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
Definition: window_manager.cc:183
InternalFlutterWindows_WindowManager_GetWindowContentSize
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:179
InternalFlutterWindows_WindowManager_SetWindowConstraints
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
Definition: window_manager.cc:212
InternalFlutterWindows_WindowManager_CreateDialogWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
Definition: window_manager.cc:148
InternalFlutterWindows_WindowManager_SetFullscreen
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
Definition: window_manager.cc:221
InternalFlutterWindows_WindowManager_CreateRegularWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
Definition: window_manager.cc:139
InternalFlutterWindows_WindowManager_Initialize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:131
InternalFlutterWindows_WindowManager_CreateTooltipWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateTooltipWindow(int64_t engine_id, const flutter::TooltipWindowCreationRequest *request)
Definition: window_manager.cc:157
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:165
InternalFlutterWindows_WindowManager_OnDestroyWindow
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd)
Definition: window_manager.cc:192