Flutter Windows Embedder
flutter::WindowManager Class Reference

#include <window_manager.h>

Public Member Functions

 WindowManager (FlutterWindowsEngine *engine)
 
virtual ~WindowManager ()=default
 
void Initialize (const WindowingInitRequest *request)
 
FlutterViewId CreateRegularWindow (const RegularWindowCreationRequest *request)
 
FlutterViewId CreateDialogWindow (const DialogWindowCreationRequest *request)
 
FlutterViewId CreateTooltipWindow (const TooltipWindowCreationRequest *request)
 
FlutterViewId CreatePopupWindow (const PopupWindowCreationRequest *request)
 
FlutterViewId CreateSatelliteWindow (const SatelliteWindowCreationRequest *request)
 
std::optional< LRESULT > HandleMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 
void OnPreEngineRestart ()
 
void OnEngineShutdown ()
 

Static Public Member Functions

static HostWindowSatellite * GetSatelliteWindowFromHandle (HWND hwnd)
 

Detailed Description

Definition at line 130 of file window_manager.h.

Constructor & Destructor Documentation

◆ WindowManager()

flutter::WindowManager::WindowManager ( FlutterWindowsEngine *  engine)
explicit

Definition at line 26 of file window_manager.cc.

26 : engine_(engine) {}

◆ ~WindowManager()

virtual flutter::WindowManager::~WindowManager ( )
virtualdefault

Member Function Documentation

◆ CreateDialogWindow()

FlutterViewId flutter::WindowManager::CreateDialogWindow ( const DialogWindowCreationRequest *  request)

Definition at line 47 of file window_manager.cc.

48  {
49  auto window = HostWindow::CreateDialogWindow(
50  this, engine_, request->preferred_size, request->preferred_constraints,
51  request->title, request->parent_or_null, request->sized_to_content,
52  request->resizable);
53  if (!window || !window->GetWindowHandle()) {
54  FML_LOG(ERROR) << "Failed to create host window";
55  return -1;
56  }
57  FlutterViewId const view_id = window->view_controller_->view()->view_id();
58  active_windows_[window->GetWindowHandle()] = std::move(window);
59  return view_id;
60 }
static std::unique_ptr< HostWindow > CreateDialogWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, HWND parent, bool sized_to_content, bool resizable)
Definition: host_window.cc:192
int64_t FlutterViewId

References flutter::HostWindow::CreateDialogWindow(), flutter::DialogWindowCreationRequest::parent_or_null, flutter::DialogWindowCreationRequest::preferred_constraints, flutter::DialogWindowCreationRequest::preferred_size, flutter::DialogWindowCreationRequest::resizable, flutter::DialogWindowCreationRequest::sized_to_content, and flutter::DialogWindowCreationRequest::title.

Referenced by InternalFlutterWindows_WindowManager_CreateDialogWindow().

◆ CreatePopupWindow()

FlutterViewId flutter::WindowManager::CreatePopupWindow ( const PopupWindowCreationRequest *  request)

Definition at line 76 of file window_manager.cc.

77  {
78  auto window = HostWindow::CreatePopupWindow(
79  this, engine_, request->preferred_constraints,
80  request->get_position_callback, request->parent);
81  if (!window || !window->GetWindowHandle()) {
82  FML_LOG(ERROR) << "Failed to create host window";
83  return -1;
84  }
85  FlutterViewId const view_id = window->view_controller_->view()->view_id();
86  active_windows_[window->GetWindowHandle()] = std::move(window);
87  return view_id;
88 }
static std::unique_ptr< HostWindow > CreatePopupWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
Definition: host_window.cc:218

References flutter::HostWindow::CreatePopupWindow(), flutter::PopupWindowCreationRequest::get_position_callback, flutter::PopupWindowCreationRequest::parent, and flutter::PopupWindowCreationRequest::preferred_constraints.

Referenced by InternalFlutterWindows_WindowManager_CreatePopupWindow().

◆ CreateRegularWindow()

FlutterViewId flutter::WindowManager::CreateRegularWindow ( const RegularWindowCreationRequest *  request)

Definition at line 33 of file window_manager.cc.

34  {
35  auto window = HostWindow::CreateRegularWindow(
36  this, engine_, request->preferred_size, request->preferred_constraints,
37  request->title, request->sized_to_content, request->resizable);
38  if (!window || !window->GetWindowHandle()) {
39  FML_LOG(ERROR) << "Failed to create host window";
40  return -1;
41  }
42  FlutterViewId const view_id = window->view_controller_->view()->view_id();
43  active_windows_[window->GetWindowHandle()] = std::move(window);
44  return view_id;
45 }
static std::unique_ptr< HostWindow > CreateRegularWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, bool sized_to_content, bool resizable)
Definition: host_window.cc:178

References flutter::HostWindow::CreateRegularWindow(), flutter::RegularWindowCreationRequest::preferred_constraints, flutter::RegularWindowCreationRequest::preferred_size, flutter::RegularWindowCreationRequest::resizable, flutter::RegularWindowCreationRequest::sized_to_content, and flutter::RegularWindowCreationRequest::title.

Referenced by InternalFlutterWindows_WindowManager_CreateRegularWindow().

◆ CreateSatelliteWindow()

FlutterViewId flutter::WindowManager::CreateSatelliteWindow ( const SatelliteWindowCreationRequest *  request)

Definition at line 90 of file window_manager.cc.

91  {
93  this, engine_, request->preferred_size, request->preferred_constraints,
94  request->get_position_callback, request->parent, request->title,
95  request->sized_to_content, request->resizable);
96  if (!window || !window->GetWindowHandle()) {
97  FML_LOG(ERROR) << "Failed to create host window";
98  return -1;
99  }
100  FlutterViewId const view_id = window->view_controller_->view()->view_id();
101  active_windows_[window->GetWindowHandle()] = std::move(window);
102  return view_id;
103 }
static std::unique_ptr< HostWindow > CreateSatelliteWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent, LPCWSTR title, bool sized_to_content, bool resizable)
Definition: host_window.cc:229

References flutter::HostWindow::CreateSatelliteWindow(), flutter::SatelliteWindowCreationRequest::get_position_callback, flutter::SatelliteWindowCreationRequest::parent, flutter::SatelliteWindowCreationRequest::preferred_constraints, flutter::SatelliteWindowCreationRequest::preferred_size, flutter::SatelliteWindowCreationRequest::resizable, flutter::SatelliteWindowCreationRequest::sized_to_content, and flutter::SatelliteWindowCreationRequest::title.

Referenced by InternalFlutterWindows_WindowManager_CreateSatelliteWindow().

◆ CreateTooltipWindow()

FlutterViewId flutter::WindowManager::CreateTooltipWindow ( const TooltipWindowCreationRequest *  request)

Definition at line 62 of file window_manager.cc.

63  {
64  auto window = HostWindow::CreateTooltipWindow(
65  this, engine_, request->preferred_constraints,
66  request->get_position_callback, request->parent);
67  if (!window || !window->GetWindowHandle()) {
68  FML_LOG(ERROR) << "Failed to create host window";
69  return -1;
70  }
71  FlutterViewId const view_id = window->view_controller_->view()->view_id();
72  active_windows_[window->GetWindowHandle()] = std::move(window);
73  return view_id;
74 }
static std::unique_ptr< HostWindow > CreateTooltipWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
Definition: host_window.cc:207

References flutter::HostWindow::CreateTooltipWindow(), flutter::TooltipWindowCreationRequest::get_position_callback, flutter::TooltipWindowCreationRequest::parent, and flutter::TooltipWindowCreationRequest::preferred_constraints.

Referenced by InternalFlutterWindows_WindowManager_CreateTooltipWindow().

◆ GetSatelliteWindowFromHandle()

HostWindowSatellite * flutter::WindowManager::GetSatelliteWindowFromHandle ( HWND  hwnd)
static

Definition at line 105 of file window_manager.cc.

105  {
106  HostWindow* window = HostWindow::GetThisFromHandle(hwnd);
107  if (!window || window->GetArchetype() != WindowArchetype::kSatellite) {
108  return nullptr;
109  }
110  return static_cast<HostWindowSatellite*>(window);
111 }
static HostWindow * GetThisFromHandle(HWND hwnd)
Definition: host_window.cc:362

References flutter::HostWindow::GetArchetype(), flutter::HostWindow::GetThisFromHandle(), and flutter::kSatellite.

Referenced by InternalFlutterWindows_WindowManager_SetSatelliteParent().

◆ HandleMessage()

std::optional< LRESULT > flutter::WindowManager::HandleMessage ( HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)

Definition at line 142 of file window_manager.cc.

145  {
146  if (message == WM_DESTROY) {
147  // Destroying parent HWND will transitively destroy child HWND, including
148  // the FlutterView HWND. That causes a problem because the raster thread
149  // may require the Flutterview HWND to be alive until Engine RemoveView
150  // completes. To ensure that the FlutterView HWND is removed from the
151  // parent window. The FlutterView HWND will be destroyed later inside
152  // FlutterWindow::Destroy.
153  HostWindow* window = HostWindow::GetThisFromHandle(hwnd);
154  if (window) {
155  auto handle = window->GetFlutterViewWindowHandle();
156  ShowWindow(handle, SW_HIDE);
157  SetParent(handle, nullptr);
158  }
159  }
160 
161  if (message == WM_NCDESTROY) {
162  active_windows_.erase(hwnd);
163  return std::nullopt;
164  }
165 
166  HostWindow* host_window = HostWindow::GetThisFromHandle(hwnd);
167  FlutterWindowsView* view =
168  host_window ? host_window->view_controller_->view() : nullptr;
169 
170  if (!view) {
171  FML_LOG(WARNING) << "Received message for unknown view";
172  return std::nullopt;
173  }
174 
175  WindowsMessage message_struct = {.view_id = view->view_id(),
176  .hwnd = hwnd,
177  .message = message,
178  .wParam = wparam,
179  .lParam = lparam,
180  .result = 0,
181  .handled = false};
182 
183  // Not initialized yet.
184  if (!isolate_ || on_message_ == nullptr) {
185  return std::nullopt;
186  }
187 
188  IsolateScope scope(*isolate_);
189  on_message_(&message_struct);
190  if (message_struct.handled) {
191  return message_struct.result;
192  } else {
193  return std::nullopt;
194  }
195 }
Win32Message message

References flutter::HostWindow::GetFlutterViewWindowHandle(), flutter::HostWindow::GetThisFromHandle(), flutter::WindowsMessage::handled, message, flutter::WindowsMessage::result, flutter::HostWindow::view_controller_, flutter::FlutterWindowsView::view_id(), and flutter::WindowsMessage::view_id.

◆ Initialize()

void flutter::WindowManager::Initialize ( const WindowingInitRequest *  request)

Definition at line 28 of file window_manager.cc.

28  {
29  on_message_ = request->on_message;
30  isolate_ = Isolate::Current();
31 }
static Isolate Current()
Definition: isolate_scope.cc:9

References flutter::Isolate::Current(), and flutter::WindowingInitRequest::on_message.

Referenced by InternalFlutterWindows_WindowManager_Initialize().

◆ OnEngineShutdown()

void flutter::WindowManager::OnEngineShutdown ( )

Definition at line 122 of file window_manager.cc.

122  {
123  // Destroy the windows before clearing |on_message_| so the WM_DESTROY
124  // round-trip reaches the isolate. Otherwise per-view Dart controllers
125  // never observe destruction and may issue follow-up FFI calls (e.g.
126  // updatePosition) with stale handles after the engine is torn down.
127  //
128  // Destroying single window may result in removal of child entries from the
129  // map so this loop is safer than iterating over the map.
130  while (!active_windows_.empty()) {
131  auto it = active_windows_.begin();
132  // This will destroy the window, which will in turn remove the
133  // HostWindow from map when handling WM_NCDESTROY inside
134  // HandleMessage.
136  }
137 
138  // Don't send any more messages to isolate.
139  on_message_ = nullptr;
140 }
void InternalFlutterWindows_WindowManager_OnDestroyWindow(HWND hwnd)

References InternalFlutterWindows_WindowManager_OnDestroyWindow().

Referenced by OnPreEngineRestart().

◆ OnPreEngineRestart()

void flutter::WindowManager::OnPreEngineRestart ( )

Definition at line 113 of file window_manager.cc.

113  {
114  // The isolate state will be completely lost after a hot restart, so notifying
115  // the isolate about destroying windows does not have any benefits. On the
116  // contrary it can cause the old isolate to shut down the application because
117  // all windows will be destroyed.
118  on_message_ = nullptr;
120 }

References OnEngineShutdown().


The documentation for this class was generated from the following files: