Flutter Engine
 
Loading...
Searching...
No Matches
window_manager.cc
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
6
7#include <dwmapi.h>
8#include <optional>
9#include <vector>
10
11#include "embedder.h"
16#include "fml/logging.h"
20
21namespace flutter {
22
24
26 on_message_ = request->on_message;
27 isolate_ = Isolate::Current();
28}
29
31 const RegularWindowCreationRequest* request) {
33 this, engine_, request->preferred_size, request->preferred_constraints,
34 request->title);
35 if (!window || !window->GetWindowHandle()) {
36 FML_LOG(ERROR) << "Failed to create host window";
37 return -1;
38 }
39 FlutterViewId const view_id = window->view_controller_->view()->view_id();
40 active_windows_[window->GetWindowHandle()] = std::move(window);
41 return view_id;
42}
43
45 const DialogWindowCreationRequest* request) {
47 this, engine_, request->preferred_size, request->preferred_constraints,
48 request->title, request->parent_or_null);
49 if (!window || !window->GetWindowHandle()) {
50 FML_LOG(ERROR) << "Failed to create host window";
51 return -1;
52 }
53 FlutterViewId const view_id = window->view_controller_->view()->view_id();
54 active_windows_[window->GetWindowHandle()] = std::move(window);
55 return view_id;
56}
57
59 // Don't send any more messages to isolate.
60 on_message_ = nullptr;
61 std::vector<HWND> active_handles;
62 active_handles.reserve(active_windows_.size());
63 for (auto& [hwnd, window] : active_windows_) {
64 active_handles.push_back(hwnd);
65 }
66 for (auto hwnd : active_handles) {
67 // This will destroy the window, which will in turn remove the
68 // HostWindow from map when handling WM_NCDESTROY inside
69 // HandleMessage.
70 DestroyWindow(hwnd);
71 }
72}
73
74std::optional<LRESULT> WindowManager::HandleMessage(HWND hwnd,
76 WPARAM wparam,
77 LPARAM lparam) {
78 if (message == WM_NCDESTROY) {
79 active_windows_.erase(hwnd);
80 }
81
83 if (!view) {
84 FML_LOG(WARNING) << "Received message for unknown view";
85 return std::nullopt;
86 }
87
88 WindowsMessage message_struct = {.view_id = view->view_id(),
89 .hwnd = hwnd,
90 .message = message,
91 .wParam = wparam,
92 .lParam = lparam,
93 .result = 0,
94 .handled = false};
95
96 // Not initialized yet.
97 if (!isolate_) {
98 return std::nullopt;
99 }
100
101 IsolateScope scope(*isolate_);
102 on_message_(&message_struct);
103 if (message_struct.handled) {
104 return message_struct.result;
105 } else {
106 return std::nullopt;
107 }
108}
109
110} // namespace flutter
111
113 int64_t engine_id,
114 const flutter::WindowingInitRequest* request) {
117 engine->window_manager()->Initialize(request);
118}
119
121 int64_t engine_id,
125 return engine->window_manager()->CreateRegularWindow(request);
126}
127
130 int64_t engine_id,
134 return engine->window_manager()->CreateDialogWindow(request);
135}
136
138 int64_t engine_id,
143 if (view == nullptr) {
144 return nullptr;
145 } else {
146 return GetAncestor(view->GetWindowHandle(), GA_ROOT);
147 }
148}
149
154
156 HWND hwnd,
157 const flutter::WindowSizeRequest* size) {
159 if (window) {
160 window->SetContentSize(*size);
161 }
162}
163
165 HWND hwnd,
166 const flutter::WindowConstraints* constraints) {
168 if (window) {
169 window->SetConstraints(*constraints);
170 }
171}
172
174 HWND hwnd,
175 const flutter::FullscreenRequest* request) {
177 const std::optional<FlutterEngineDisplayId> display_id =
178 request->has_display_id
179 ? std::optional<FlutterEngineDisplayId>(request->display_id)
180 : std::nullopt;
181 if (window) {
182 window->SetFullscreen(request->fullscreen, display_id);
183 }
184}
185
188 if (window) {
189 return window->GetFullscreen();
190 }
191
192 return false;
193}
static FlutterWindowsEngine * GetEngineForId(int64_t engine_id)
FlutterWindowsView * GetViewFromTopLevelWindow(HWND hwnd) const
static ActualWindowSize GetWindowContentSize(HWND hwnd)
static HostWindow * GetThisFromHandle(HWND hwnd)
static std::unique_ptr< HostWindow > CreateDialogWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, HWND parent)
static std::unique_ptr< HostWindow > CreateRegularWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title)
static Isolate Current()
FlutterViewId CreateDialogWindow(const DialogWindowCreationRequest *request)
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
FlutterViewId CreateRegularWindow(const RegularWindowCreationRequest *request)
void Initialize(const WindowingInitRequest *request)
WindowManager(FlutterWindowsEngine *engine)
int64_t FlutterViewId
Definition embedder.h:386
GLFWwindow * window
Definition main.cc:60
FlutterEngine engine
Definition main.cc:84
FlView * view
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
#define FLUTTER_EXPORT
#define FML_LOG(severity)
Definition logging.h:101
int64_t FlutterViewId
FlutterEngineDisplayId display_id
void(* on_message)(WindowsMessage *)
void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::RegularWindowCreationRequest *request)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateDialogWindow(int64_t engine_id, const flutter::DialogWindowCreationRequest *request)
void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)
unsigned int UINT
LONG_PTR LPARAM
UINT_PTR WPARAM