| 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 WindowCreationRequest {
43 WindowSizeRequest preferred_size;
44 WindowConstraints preferred_constraints;
45 LPCWSTR title;
46 };
47
48 struct WindowsMessage {
49 FlutterViewId view_id;
50 HWND hwnd;
51 UINT message;
52 WPARAM wParam;
53 LPARAM lParam;
54 LRESULT result;
55 bool handled;
56 };
57
58 struct WindowingInitRequest {
59 void (*on_message)(WindowsMessage*);
60 };
61
62 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
63 // This represents the current content size of the window.
64 struct ActualWindowSize {
65 double width;
66 double height;
67 };
68
69 struct FullscreenRequest {
70 bool fullscreen;
71 bool has_display_id;
72 FlutterEngineDisplayId display_id;
73 };
74
75 // A manager class for managing |HostWindow| instances.
76 // A unique instance of this class is owned by |FlutterWindowsEngine|.
77 class WindowManager {
78 public:
79 explicit WindowManager(FlutterWindowsEngine* engine);
80 virtual ~WindowManager() = default;
81
82 void Initialize(const WindowingInitRequest* request);
83
84 bool HasTopLevelWindows() const;
85
86 FlutterViewId CreateRegularWindow(const WindowCreationRequest* request);
87
88 // Message handler called by |HostWindow::WndProc| to process window
89 // messages before delegating them to the host window. This allows the
90 // manager to process messages that affect the state of other host windows.
91 std::optional<LRESULT> HandleMessage(HWND hwnd,
92 UINT message,
93 WPARAM wparam,
94 LPARAM lparam);
95
96 void OnEngineShutdown();
97
98 private:
99 // The Flutter engine that owns this manager.
100 FlutterWindowsEngine* const engine_;
101
102 // Callback that relays windows messages to the isolate. Set
103 // during Initialize().
104 std::function<void(WindowsMessage*)> on_message_;
105
106 // Isolate that runs the Dart code. Set during Initialize().
107 std::optional<Isolate> isolate_;
108
109 // A map of active windows. Used to destroy remaining windows on engine
110 // shutdown.
111 std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
112
113 FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
114 };
115
116 } // namespace flutter
117
118 extern "C" {
119
120 FLUTTER_EXPORT
121 void InternalFlutterWindows_WindowManager_Initialize(
122 int64_t engine_id,
123 const flutter::WindowingInitRequest* request);
124
125 FLUTTER_EXPORT
126 bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id);
127
128 FLUTTER_EXPORT
129 FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(
130 int64_t engine_id,
131 const flutter::WindowCreationRequest* request);
132
133 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
134 // NULL if the HWND cannot be found
135 FLUTTER_EXPORT
136 HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
137 int64_t engine_id,
138 FlutterViewId view_id);
139
140 FLUTTER_EXPORT
141 flutter::ActualWindowSize
142 InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd);
143
144 FLUTTER_EXPORT
145 void InternalFlutterWindows_WindowManager_SetWindowSize(
146 HWND hwnd,
147 const flutter::WindowSizeRequest* size);
148
149 FLUTTER_EXPORT
150 void InternalFlutterWindows_WindowManager_SetWindowConstraints(
151 HWND hwnd,
152 const flutter::WindowConstraints* constraints);
153
154 FLUTTER_EXPORT
155 void InternalFlutterWindows_WindowManager_SetFullscreen(
156 HWND hwnd,
157 const flutter::FullscreenRequest* request);
158
159 FLUTTER_EXPORT
160 bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd);
161 }
162
163 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:92
flutter::WindowManager
Definition: window_manager.h:77
flutter::WindowManager::OnEngineShutdown
void OnEngineShutdown()
Definition: window_manager.cc:48
flutter::WindowManager::HandleMessage
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: window_manager.cc:64
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::CreateRegularWindow
FlutterViewId CreateRegularWindow(const WindowCreationRequest *request)
Definition: window_manager.cc:34
flutter::WindowManager::HasTopLevelWindows
bool HasTopLevelWindows() const
Definition: window_manager.cc:30
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: flutter_view.h:13
flutter::ActualWindowSize
Definition: window_manager.h:64
flutter::ActualWindowSize::width
double width
Definition: window_manager.h:65
flutter::ActualWindowSize::height
double height
Definition: window_manager.h:66
flutter::FullscreenRequest
Definition: window_manager.h:69
flutter::FullscreenRequest::has_display_id
bool has_display_id
Definition: window_manager.h:71
flutter::FullscreenRequest::fullscreen
bool fullscreen
Definition: window_manager.h:70
flutter::FullscreenRequest::display_id
FlutterEngineDisplayId display_id
Definition: window_manager.h:72
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::WindowCreationRequest
Definition: window_manager.h:42
flutter::WindowCreationRequest::preferred_constraints
WindowConstraints preferred_constraints
Definition: window_manager.h:44
flutter::WindowCreationRequest::preferred_size
WindowSizeRequest preferred_size
Definition: window_manager.h:43
flutter::WindowCreationRequest::title
LPCWSTR title
Definition: window_manager.h:45
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:58
flutter::WindowingInitRequest::on_message
void(* on_message)(WindowsMessage *)
Definition: window_manager.h:59
flutter::WindowsMessage
Definition: window_manager.h:48
flutter::WindowsMessage::hwnd
HWND hwnd
Definition: window_manager.h:50
flutter::WindowsMessage::wParam
WPARAM wParam
Definition: window_manager.h:52
flutter::WindowsMessage::message
UINT message
Definition: window_manager.h:51
flutter::WindowsMessage::result
LRESULT result
Definition: window_manager.h:54
flutter::WindowsMessage::view_id
FlutterViewId view_id
Definition: window_manager.h:49
flutter::WindowsMessage::lParam
LPARAM lParam
Definition: window_manager.h:53
flutter::WindowsMessage::handled
bool handled
Definition: window_manager.h:55
InternalFlutterWindows_WindowManager_HasTopLevelWindows
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id)
Definition: window_manager.cc:110
InternalFlutterWindows_WindowManager_GetFullscreen
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
Definition: window_manager.cc:174
InternalFlutterWindows_WindowManager_SetWindowSize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
Definition: window_manager.cc:143
InternalFlutterWindows_WindowManager_GetWindowContentSize
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:139
InternalFlutterWindows_WindowManager_SetWindowConstraints
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
Definition: window_manager.cc:152
InternalFlutterWindows_WindowManager_SetFullscreen
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
Definition: window_manager.cc:161
InternalFlutterWindows_WindowManager_CreateRegularWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::WindowCreationRequest *request)
Definition: window_manager.cc:117
InternalFlutterWindows_WindowManager_Initialize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:102
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:125