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 
25 // Specifies a preferred content size for the window.
30 };
31 
32 // Specifies a preferred constraint on the window.
34  bool has_view_constraints = false;
39 };
40 
41 // Sent by the framework to request a new window be created.
45  LPCWSTR title;
46 };
47 
50  HWND hwnd;
51  UINT message;
52  WPARAM wParam;
53  LPARAM lParam;
54  LRESULT result;
55  bool handled;
56 };
57 
60 };
61 
62 // Returned from |InternalFlutterWindows_WindowManager_GetWindowContentSize|.
63 // This represents the current content size of the window.
65  double width;
66  double height;
67 };
68 
70  bool fullscreen;
72  FlutterEngineDisplayId display_id;
73 };
74 
75 // A manager class for managing |HostWindow| instances.
76 // A unique instance of this class is owned by |FlutterWindowsEngine|.
78  public:
79  explicit WindowManager(FlutterWindowsEngine* engine);
80  virtual ~WindowManager() = default;
81 
82  void Initialize(const WindowingInitRequest* request);
83 
84  bool HasTopLevelWindows() const;
85 
87 
88  // Message handler called by |HostWindow::WndProc| to process window
89  // messages before delegating them to the host window. This allows the
90  // manager to process messages that affect the state of other host windows.
91  std::optional<LRESULT> HandleMessage(HWND hwnd,
92  UINT message,
93  WPARAM wparam,
94  LPARAM lparam);
95 
96  void OnEngineShutdown();
97 
98  private:
99  // The Flutter engine that owns this manager.
100  FlutterWindowsEngine* const engine_;
101 
102  // Callback that relays windows messages to the isolate. Set
103  // during Initialize().
104  std::function<void(WindowsMessage*)> on_message_;
105 
106  // Isolate that runs the Dart code. Set during Initialize().
107  std::optional<Isolate> isolate_;
108 
109  // A map of active windows. Used to destroy remaining windows on engine
110  // shutdown.
111  std::unordered_map<HWND, std::unique_ptr<HostWindow>> active_windows_;
112 
113  FML_DISALLOW_COPY_AND_ASSIGN(WindowManager);
114 };
115 
116 } // namespace flutter
117 
118 extern "C" {
119 
122  int64_t engine_id,
123  const flutter::WindowingInitRequest* request);
124 
127 
130  int64_t engine_id,
131  const flutter::WindowCreationRequest* request);
132 
133 // Retrives the HWND associated with this |engine_id| and |view_id|. Returns
134 // NULL if the HWND cannot be found
137  int64_t engine_id,
138  FlutterViewId view_id);
139 
143 
146  HWND hwnd,
147  const flutter::WindowSizeRequest* size);
148 
151  HWND hwnd,
152  const flutter::WindowConstraints* constraints);
153 
156  HWND hwnd,
157  const flutter::FullscreenRequest* request);
158 
161 }
162 
163 #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
FlutterEngineDisplayId display_id
WindowConstraints preferred_constraints
WindowSizeRequest preferred_size
void(* on_message)(WindowsMessage *)
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_HasTopLevelWindows(int64_t engine_id)
FLUTTER_EXPORT bool InternalFlutterWindows_WindowManager_GetFullscreen(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowSize(HWND hwnd, const flutter::WindowSizeRequest *size)
FLUTTER_EXPORT flutter::ActualWindowSize InternalFlutterWindows_WindowManager_GetWindowContentSize(HWND hwnd)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetWindowConstraints(HWND hwnd, const flutter::WindowConstraints *constraints)
FLUTTER_EXPORT void InternalFlutterWindows_WindowManager_SetFullscreen(HWND hwnd, const flutter::FullscreenRequest *request)
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)