| 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 // Sent by the framework to request a new window be created.
42 struct RegularWindowCreationRequest {
43 WindowSizeRequest preferred_size;
44 WindowConstraints preferred_constraints;
45 LPCWSTR title;
46 };
47
48 struct DialogWindowCreationRequest {
49 WindowSizeRequest preferred_size;
50 WindowConstraints preferred_constraints;
51 LPCWSTR title;
52 HWND parent_or_null;
53 };
54
55 struct WindowsMessage {
56 FlutterViewId view_id;
57 HWND hwnd;
58 UINT message;
59 WPARAM wParam;
60 LPARAM lParam;
61 LRESULT result;
62 bool handled;
63 };
64
65 struct WindowingInitRequest {
66 void (*on_message)(WindowsMessage*);
67 };
68
69 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
70 // This represents the current content size of the window.
71 struct ActualWindowSize {
72 double width;
73 double height;
74 };
75
76 struct FullscreenRequest {
77 bool fullscreen;
78 bool has_display_id;
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|.
84 class WindowManager {
85 public:
86 explicit WindowManager(FlutterWindowsEngine* engine);
87 virtual ~WindowManager() = default;
88
89 void Initialize(const WindowingInitRequest* request);
90
91 FlutterViewId CreateRegularWindow(
92 const RegularWindowCreationRequest* request);
93
94 FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest* request);
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
128 FLUTTER_EXPORT
129 void InternalFlutterWindows_WindowManager_Initialize(
130 int64_t engine_id,
131 const flutter::WindowingInitRequest* request);
132
133 FLUTTER_EXPORT
134 FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(
135 int64_t engine_id,
136 const flutter::RegularWindowCreationRequest* request);
137
138 FLUTTER_EXPORT
139 FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(
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
145 FLUTTER_EXPORT
146 HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
147 int64_t engine_id,
148 FlutterViewId view_id);
149
150 FLUTTER_EXPORT
151 flutter::ActualWindowSize
152 InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd);
153
154 FLUTTER_EXPORT
155 void InternalFlutterWindows_WindowManager_SetWindowSize(
156 HWND hwnd,
157 const flutter::WindowSizeRequest* size);
158
159 FLUTTER_EXPORT
160 void InternalFlutterWindows_WindowManager_SetWindowConstraints(
161 HWND hwnd,
162 const flutter::WindowConstraints* constraints);
163
164 FLUTTER_EXPORT
165 void InternalFlutterWindows_WindowManager_SetFullscreen(
166 HWND hwnd,
167 const flutter::FullscreenRequest* request);
168
169 FLUTTER_EXPORT
170 bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd);
171 }
172
173 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:92
flutter::WindowManager
Definition: window_manager.h:84
flutter::WindowManager::OnEngineShutdown
void OnEngineShutdown()
Definition: window_manager.cc:58
flutter::WindowManager::CreateDialogWindow
FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest *request)
Definition: window_manager.cc:44
flutter::WindowManager::HandleMessage
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: window_manager.cc:74
flutter::WindowManager::CreateRegularWindow
FlutterViewId CreateRegularWindow(const RegularWindowCreationRequest *request)
Definition: window_manager.cc:30
flutter::WindowManager::Initialize
void Initialize(const WindowingInitRequest *request)
Definition: window_manager.cc:25
flutter::WindowManager::WindowManager
WindowManager(FlutterWindowsEngine *engine)
Definition: window_manager.cc:23
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::FlutterViewId
int64_t FlutterViewId
Definition: accessibility_plugin.h:15
flutter::ActualWindowSize
Definition: window_manager.h:71
flutter::ActualWindowSize::width
double width
Definition: window_manager.h:72
flutter::ActualWindowSize::height
double height
Definition: window_manager.h:73
flutter::DialogWindowCreationRequest
Definition: window_manager.h:48
flutter::DialogWindowCreationRequest::title
LPCWSTR title
Definition: window_manager.h:51
flutter::DialogWindowCreationRequest::preferred_size
WindowSizeRequest preferred_size
Definition: window_manager.h:49
flutter::DialogWindowCreationRequest::parent_or_null
HWND parent_or_null
Definition: window_manager.h:52
flutter::DialogWindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:50
flutter::FullscreenRequest
Definition: window_manager.h:76
flutter::FullscreenRequest::has_display_id
bool has_display_id
Definition: window_manager.h:78
flutter::FullscreenRequest::fullscreen
bool fullscreen
Definition: window_manager.h:77
flutter::FullscreenRequest::display_id
FlutterEngineDisplayId display_id
Definition: window_manager.h:79
flutter::RegularWindowCreationRequest
Definition: window_manager.h:42
flutter::RegularWindowCreationRequest::preferred_size
WindowSizeRequest preferred_size
Definition: window_manager.h:43
flutter::RegularWindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:44
flutter::RegularWindowCreationRequest::title
LPCWSTR title
Definition: window_manager.h:45
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::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:65
flutter::WindowingInitRequest::on_message
void(* on_message)(WindowsMessage *)
Definition: window_manager.h:66
flutter::WindowsMessage
Definition: window_manager.h:55
flutter::WindowsMessage::hwnd
HWND hwnd
Definition: window_manager.h:57
flutter::WindowsMessage::wParam
WPARAM wParam
Definition: window_manager.h:59
flutter::WindowsMessage::message
UINT message
Definition: window_manager.h:58
flutter::WindowsMessage::result
LRESULT result
Definition: window_manager.h:61
flutter::WindowsMessage::view_id
FlutterViewId view_id
Definition: window_manager.h:56
flutter::WindowsMessage::lParam
LPARAM lParam
Definition: window_manager.h:60
flutter::WindowsMessage::handled
bool handled
Definition: window_manager.h:62
InternalFlutterWindows_WindowManager_GetFullscreen
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
Definition: window_manager.cc:186
InternalFlutterWindows_WindowManager_SetWindowSize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
Definition: window_manager.cc:155
InternalFlutterWindows_WindowManager_GetWindowContentSize
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:151
InternalFlutterWindows_WindowManager_SetWindowConstraints
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
Definition: window_manager.cc:164
InternalFlutterWindows_WindowManager_CreateDialogWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
Definition: window_manager.cc:129
InternalFlutterWindows_WindowManager_SetFullscreen
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
Definition: window_manager.cc:173
InternalFlutterWindows_WindowManager_CreateRegularWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
Definition: window_manager.cc:120
InternalFlutterWindows_WindowManager_Initialize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:112
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:137