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 
15 
16 #include "flutter/fml/macros.h"
18 #include "flutter/shell/platform/embedder/embedder.h"
19 
20 namespace flutter {
21 
22 class FlutterWindowsEngine;
23 class HostWindow;
24 struct WindowingInitRequest;
25 
28  HWND hwnd;
29  UINT message;
30  WPARAM wParam;
31  LPARAM lParam;
32  LRESULT result;
33  bool handled;
34 };
35 
36 struct WindowSizing {
45 };
46 
49 };
50 
53 };
54 
55 // A manager class for managing |HostWindow| instances.
56 // A unique instance of this class is owned by |FlutterWindowsEngine|.
58  public:
59  explicit WindowManager(FlutterWindowsEngine* engine);
60  virtual ~WindowManager() = default;
61 
62  void Initialize(const WindowingInitRequest* request);
63 
64  bool HasTopLevelWindows() const;
65 
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 
102  int64_t engine_id,
103  const flutter::WindowingInitRequest* request);
104 
107 
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
117  int64_t engine_id,
118  FlutterViewId view_id);
119 
121  double width;
122  double height;
123 };
124 
127  HWND hwnd);
128 
131  HWND hwnd,
132  const flutter::WindowSizing* size);
133 }
134 
135 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_WINDOW_MANAGER_H_
std::optional< LRESULT > HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
void Initialize(const WindowingInitRequest *request)
WindowManager(FlutterWindowsEngine *engine)
FlutterViewId CreateRegularWindow(const WindowCreationRequest *request)
bool HasTopLevelWindows() const
virtual ~WindowManager()=default
#define FLUTTER_EXPORT
Win32Message message
int64_t FlutterViewId
Definition: flutter_view.h:13
void(* on_message)(WindowsMessage *)
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id)
FLUTTER_EXPORT FlutterWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowContentSize(HWND hwnd, const flutter::WindowSizing *size)
FLUTTER_EXPORT FlutterViewId InternalFlutterWindows_WindowManager_CreateRegularWindow(int64_t engine_id, const flutter::WindowCreationRequest *request)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_Initialize(int64_t engine_id, const flutter::WindowingInitRequest *request)
FLUTTER_EXPORT HWND InternalFlutterWindows_WindowManager_GetTopLevelWindowHandle(int64_t engine_id, FlutterViewId view_id)