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)
 
bool HasTopLevelWindows () const
 
FlutterViewId CreateRegularWindow (const WindowCreationRequest *request)
 
std::optional< LRESULT > HandleMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 
void OnEngineShutdown ()
 

Detailed Description

Definition at line 57 of file window_manager.h.

Constructor & Destructor Documentation

◆ WindowManager()

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

Definition at line 23 of file window_manager.cc.

23 : engine_(engine) {}

◆ ~WindowManager()

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

Member Function Documentation

◆ CreateRegularWindow()

FlutterViewId flutter::WindowManager::CreateRegularWindow ( const WindowCreationRequest request)

Definition at line 34 of file window_manager.cc.

35  {
36  auto window =
37  HostWindow::CreateRegularWindow(this, engine_, request->content_size);
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 *controller, FlutterWindowsEngine *engine, const WindowSizing &content_size)
Definition: host_window.cc:200
int64_t FlutterViewId
Definition: flutter_view.h:13

References flutter::WindowCreationRequest::content_size, and flutter::HostWindow::CreateRegularWindow().

Referenced by InternalFlutterWindows_WindowManager_CreateRegularWindow().

◆ HandleMessage()

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

Definition at line 63 of file window_manager.cc.

66  {
67  if (message == WM_NCDESTROY) {
68  active_windows_.erase(hwnd);
69  }
70 
71  FlutterWindowsView* view = engine_->GetViewFromTopLevelWindow(hwnd);
72  if (!view) {
73  FML_LOG(WARNING) << "Received message for unknown view";
74  return std::nullopt;
75  }
76 
77  WindowsMessage message_struct = {.view_id = view->view_id(),
78  .hwnd = hwnd,
79  .message = message,
80  .wParam = wparam,
81  .lParam = lparam,
82  .result = 0,
83  .handled = false};
84 
85  // Not initialized yet.
86  if (!isolate_) {
87  return std::nullopt;
88  }
89 
90  IsolateScope scope(*isolate_);
91  on_message_(&message_struct);
92  if (message_struct.handled) {
93  return message_struct.result;
94  } else {
95  return std::nullopt;
96  }
97 }
FlutterWindowsView * GetViewFromTopLevelWindow(HWND hwnd) const
Win32Message message

References flutter::FlutterWindowsEngine::GetViewFromTopLevelWindow(), flutter::WindowsMessage::handled, message, flutter::WindowsMessage::result, flutter::FlutterWindowsView::view_id(), and flutter::WindowsMessage::view_id.

◆ HasTopLevelWindows()

bool flutter::WindowManager::HasTopLevelWindows ( ) const

Definition at line 30 of file window_manager.cc.

30  {
31  return !active_windows_.empty();
32 }

Referenced by InternalFlutterWindows_WindowManager_HasTopLevelWindows().

◆ Initialize()

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

Definition at line 25 of file window_manager.cc.

25  {
26  on_message_ = request->on_message;
27  isolate_ = Isolate::Current();
28 }
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 47 of file window_manager.cc.

47  {
48  // Don't send any more messages to isolate.
49  on_message_ = nullptr;
50  std::vector<HWND> active_handles;
51  active_handles.reserve(active_windows_.size());
52  for (auto& [hwnd, window] : active_windows_) {
53  active_handles.push_back(hwnd);
54  }
55  for (auto hwnd : active_handles) {
56  // This will destroy the window, which will in turn remove the
57  // HostWindow from map when handling WM_NCDESTROY inside
58  // HandleMessage.
59  DestroyWindow(hwnd);
60  }
61 }

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