| 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 struct WindowingInitRequest;
25
26 struct WindowsMessage {
27 FlutterViewId view_id;
28 HWND hwnd;
29 UINT message;
30 WPARAM wParam;
31 LPARAM lParam;
32 LRESULT result;
33 bool handled;
34 };
35
36 struct WindowSizing {
37 bool has_preferred_view_size;
38 double preferred_view_width;
39 double preferred_view_height;
40 bool has_view_constraints;
41 double view_min_width;
42 double view_min_height;
43 double view_max_width;
44 double view_max_height;
45 };
46
47 struct WindowingInitRequest {
48 void (*on_message)(WindowsMessage*);
49 };
50
51 struct WindowCreationRequest {
52 WindowSizing content_size;
53 };
54
55 // A manager class for managing |HostWindow| instances.
56 // A unique instance of this class is owned by |FlutterWindowsEngine|.
57 class WindowManager {
58 public:
59 explicit WindowManager(FlutterWindowsEngine* engine);
60 virtual ~WindowManager() = default;
61
62 void Initialize(const WindowingInitRequest* request);
63
64 bool HasTopLevelWindows() const;
65
66 FlutterViewId CreateRegularWindow(const WindowCreationRequest* request);
67
68 // Message handler called by |HostWindow::WndProc| to process window
69 // messages before delegating them to the host window. This allows the
70 // manager to process messages that affect the state of other host windows.
71 std::optional<LRESULT> HandleMessage(HWND hwnd,
72 UINT message,
73 WPARAM wparam,
74 LPARAM lparam);
75
76 void OnEngineShutdown();
77
78 private:
79 // The Flutter engine that owns this manager.
80 FlutterWindowsEngine* const engine_;
81
82 // Callback that relays windows messages to the isolate. Set
83 // during Initialize().
84 std::function<void(WindowsMessage*)> on_message_;
85
86 // Isolate that runs the Dart code. Set during Initialize().
87 std::optional<Isolate> isolate_;
88
89 // A map of active windows. Used to destroy remaining windows on engine
90 // shutdown.
91 std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
92
93 FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
94 };
95
96 } // namespace flutter
97
98 extern "C" {
99
100 FLUTTER_EXPORT
101 void InternalFlutterWindows_WindowManager_Initialize(
102 int64_t engine_id,
103 const flutter::WindowingInitRequest* request);
104
105 FLUTTER_EXPORT
106 bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id);
107
108 FLUTTER_EXPORT
109 FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(
110 int64_t engine_id,
111 const flutter::WindowCreationRequest* request);
112
113 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
114 // NULL if the HWND cannot be found
115 FLUTTER_EXPORT
116 HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(
117 int64_t engine_id,
118 FlutterViewId view_id);
119
120 struct FlutterWindowSize {
121 double width;
122 double height;
123 };
124
125 FLUTTER_EXPORT
126 FlutterWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(
127 HWND hwnd);
128
129 FLUTTER_EXPORT
130 void InternalFlutterWindows_WindowManager_SetWindowContentSize(
131 HWND hwnd,
132 const flutter::WindowSizing* size);
133 }
134
135 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
flutter::FlutterWindowsEngine
Definition: flutter_windows_engine.h:92
flutter::WindowManager
Definition: window_manager.h:57
flutter::WindowManager::OnEngineShutdown
void OnEngineShutdown()
Definition: window_manager.cc:47
flutter::WindowManager::HandleMessage
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
Definition: window_manager.cc:63
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
FlutterWindowSize
Definition: window_manager.h:120
FlutterWindowSize::height
double height
Definition: window_manager.h:122
FlutterWindowSize::width
double width
Definition: window_manager.h:121
flutter::WindowCreationRequest
Definition: window_manager.h:51
flutter::WindowCreationRequest::content_size
WindowSizing content_size
Definition: window_manager.h:52
flutter::WindowSizing
Definition: window_manager.h:36
flutter::WindowSizing::preferred_view_width
double preferred_view_width
Definition: window_manager.h:38
flutter::WindowSizing::has_view_constraints
bool has_view_constraints
Definition: window_manager.h:40
flutter::WindowSizing::view_min_width
double view_min_width
Definition: window_manager.h:41
flutter::WindowSizing::has_preferred_view_size
bool has_preferred_view_size
Definition: window_manager.h:37
flutter::WindowSizing::preferred_view_height
double preferred_view_height
Definition: window_manager.h:39
flutter::WindowSizing::view_min_height
double view_min_height
Definition: window_manager.h:42
flutter::WindowSizing::view_max_width
double view_max_width
Definition: window_manager.h:43
flutter::WindowSizing::view_max_height
double view_max_height
Definition: window_manager.h:44
flutter::WindowingInitRequest
Definition: window_manager.h:47
flutter::WindowingInitRequest::on_message
void(* on_message)(WindowsMessage *)
Definition: window_manager.h:48
flutter::WindowsMessage
Definition: window_manager.h:26
flutter::WindowsMessage::hwnd
HWND hwnd
Definition: window_manager.h:28
flutter::WindowsMessage::wParam
WPARAM wParam
Definition: window_manager.h:30
flutter::WindowsMessage::message
UINT message
Definition: window_manager.h:29
flutter::WindowsMessage::result
LRESULT result
Definition: window_manager.h:32
flutter::WindowsMessage::view_id
FlutterViewId view_id
Definition: window_manager.h:27
flutter::WindowsMessage::lParam
LPARAM lParam
Definition: window_manager.h:31
flutter::WindowsMessage::handled
bool handled
Definition: window_manager.h:33
InternalFlutterWindows_WindowManager_HasTopLevelWindows
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id)
Definition: window_manager.cc:109
InternalFlutterWindows_WindowManager_GetWindowContentSize
FLUTTER_EXPORT FlutterWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
Definition: window_manager.cc:137
InternalFlutterWindows_WindowManager_SetWindowContentSize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowContentSize(HWND hwnd, const flutter::WindowSizing *size)
Definition: window_manager.cc:151
InternalFlutterWindows_WindowManager_CreateRegularWindow
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::WindowCreationRequest *request)
Definition: window_manager.cc:116
InternalFlutterWindows_WindowManager_Initialize
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
Definition: window_manager.cc:101
InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
Definition: window_manager.cc:124