Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
host_window.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_HOST_WINDOW_H_
6#define FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
7
8#include <shobjidl.h>
9#include <windows.h>
10#include <wrl/client.h>
11#include <memory>
12#include <optional>
13#include <string>
14
15#include "flutter/fml/macros.h"
19
20namespace flutter {
21
22class WindowManager;
23class WindowsProcTable;
24class FlutterWindowsView;
25class FlutterWindowsViewSizingDelegate;
26class FlutterWindowsViewController;
27
28// A Win32 window that hosts a |FlutterWindow| in its client area.
30 public:
31 virtual ~HostWindow();
32
33 // Creates a regular Win32 window with a child view confined to its client
34 // area. |window_manager| is a pointer to the window manager that manages the
35 // |HostWindow|. |engine| is a pointer to the engine that manages
36 // the window manager. |preferred_size| is the preferred size of the window.
37 // |preferred_constraints| are the constraints set on the window's size.
38 // |title| is the title of the window.
39 //
40 // On success, a valid window handle can be retrieved
41 // via |HostWindow::GetWindowHandle|. |nullptr| will be returned
42 // on failure.
43 static std::unique_ptr<HostWindow> CreateRegularWindow(
44 WindowManager* window_manager,
46 const WindowSizeRequest& preferred_size,
47 const WindowConstraints& preferred_constraints,
48 LPCWSTR title);
49
50 // Creates a dialog Win32 window with a child view confined to its client
51 // area. |window_manager| is a pointer to the window manager that manages the
52 // |HostWindow|. |engine| is a pointer to the engine that manages
53 // the window manager. |preferred_size| is the preferred size of the window.
54 // |preferred_constraints| are the constraints set on the window's size.
55 // |title| is the title of the window. |parent| is the parent of this dialog,
56 // which can be `nullptr`.
57 //
58 // On success, a valid window handle can be retrieved
59 // via |HostWindow::GetWindowHandle|. `nullptr` will be returned
60 // on failure.
61 static std::unique_ptr<HostWindow> CreateDialogWindow(
62 WindowManager* window_manager,
64 const WindowSizeRequest& preferred_size,
65 const WindowConstraints& preferred_constraints,
66 LPCWSTR title,
67 HWND parent);
68
69 // Creates a tooltip Win32 window with a child view confined to its client
70 // area. |window_manager| is a pointer to the window manager that manages the
71 // |HostWindow|. |engine| is a pointer to the engine that manages
72 // the window manager. |preferred_constraints| are the constraints set on
73 // the window's size. |get_position_callback| is a callback
74 // that determines the position of the tooltip window. It is invoked on the
75 // platform thread whenever the rendered content size of the tooltip changes,
76 // including after the initial frame is rendered and on any subsequent content
77 // resize. It is not called in response to parent window movement or other
78 // Win32 window messages. |parent| is the parent of this tooltip, which must
79 // be non-null.
80 static std::unique_ptr<HostWindow> CreateTooltipWindow(
81 WindowManager* window_manager,
83 const WindowConstraints& preferred_constraints,
84 GetWindowPositionCallback get_position_callback,
85 HWND parent);
86
87 // Creates a popup Win32 window with a child view confined to its client
88 // area. |window_manager| is a pointer to the window manager that manages the
89 // |HostWindow|. |engine| is a pointer to the engine that manages
90 // the window manager. |preferred_constraints| are the constraints set on
91 // the window's size. |get_position_callback| is a callback that determines
92 // the position of the popup window. It is invoked on the platform thread
93 // whenever the rendered content size of the popup changes, including after
94 // the initial frame is rendered and on any subsequent content resize. It is
95 // not called in response to parent window movement or other Win32 window
96 // messages. |parent| is the parent of this popup, which must be non-null.
97 static std::unique_ptr<HostWindow> CreatePopupWindow(
98 WindowManager* window_manager,
100 const WindowConstraints& preferred_constraints,
101 GetWindowPositionCallback get_position_callback,
102 HWND parent);
103
104 // Returns the instance pointer for |hwnd| or nullptr if invalid.
105 static HostWindow* GetThisFromHandle(HWND hwnd);
106
107 // Returns the backing window handle, or nullptr if the native window is not
108 // created or has already been destroyed.
109 HWND GetWindowHandle() const;
110
111 // Returns the HWND of the FlutterView hosted in this window.
112 HWND GetFlutterViewWindowHandle() const;
113
114 // Resizes the window to accommodate a client area of the given
115 // |size|. If the size does not satisfy the constraints, the window will be
116 // resized to the minimum or maximum size as appropriate.
118
119 // Sets the constaints on the client area of the window.
120 // If the current window size does not satisfy the new constraints,
121 // the window will be resized to satisy thew new constraints.
122 void SetConstraints(const WindowConstraints& constraints);
123
124 // Set the fullscreen state. |display_id| indicates the display where
125 // the window should be shown fullscreen; std::nullopt indicates
126 // that no display was specified, so the current display may be used.
127 virtual void SetFullscreen(bool fullscreen,
128 std::optional<FlutterEngineDisplayId> display_id);
129
130 // Returns |true| if this window is fullscreen, otherwise |false|.
131 virtual bool GetFullscreen() const;
132
133 // Given a window identifier, returns the window content size of the
134 // window.
135 static ActualWindowSize GetWindowContentSize(HWND hwnd);
136
137 // Returns the owner window, or nullptr if none.
138 HostWindow* GetOwnerWindow() const;
139
140 // This method is called when a dialog is created or destroyed.
141 // It walks the path of child windows to make sure that the right
142 // windows are enabled or disabled.
144
145 protected:
158
159 // Initialize the underlying native window and the Flutter view.
160 //
161 // See:
162 // - https://learn.microsoft.com/windows/win32/winmsg/window-styles
163 // - https://learn.microsoft.com/windows/win32/winmsg/extended-window-styles
165
167
168 // Information saved before going into fullscreen mode, used to restore the
169 // window afterwards.
179
180 // Construct a host window.
181 //
182 // Derived classes should call InitializeFlutterView() after construction to
183 // set up the native window and the Flutter view.
185
186 // Calculates the required window size, in physical coordinates, to
187 // accommodate the given |client_size|, in logical coordinates, constrained by
188 // optional |smallest| and |biggest|, for a window with the specified
189 // |window_style| and |extended_window_style|. If |owner_hwnd| is not null,
190 // the DPI of the display with the largest area of intersection with
191 // |owner_hwnd| is used for the calculation; otherwise, the primary display's
192 // DPI is used. The resulting size includes window borders, non-client areas,
193 // and drop shadows. On error, returns std::nullopt and logs an error message.
194 static std::optional<Size> GetWindowSizeForClientSize(
195 WindowsProcTable const& win32,
196 Size const& client_size,
197 std::optional<Size> smallest,
198 std::optional<Size> biggest,
199 DWORD window_style,
200 DWORD extended_window_style,
201 std::optional<HWND> const& owner_hwnd);
202
203 // Processes and routes salient window messages for mouse handling,
204 // size change and DPI. Delegates handling of these to member overloads that
205 // inheriting classes can handle.
206 virtual LRESULT HandleMessage(HWND hwnd,
208 WPARAM wparam,
209 LPARAM lparam);
210
211 // Sets the focus to the child view window of |window|.
212 static void FocusRootViewOf(HostWindow* window);
213
214 // Enables or disables mouse and keyboard input to this window and all its
215 // descendants.
216 void EnableRecursively(bool enable);
217
218 // Returns the first enabled descendant window. If the current window itself
219 // is enabled, returns the current window. If no window is enabled, returns
220 // `nullptr`.
222
223 // Returns the archetype of this window.
225
226 // Returns windows owned by this window.
227 std::vector<HostWindow*> GetOwnedWindows() const;
228
229 // Disables mouse and keyboard input to the window and all its descendants.
230 void DisableRecursively();
231
232 // OS callback called by message pump. Handles the WM_NCCREATE message which
233 // is passed when the non-client area is being created and enables automatic
234 // non-client DPI scaling so that the non-client area automatically
235 // responds to changes in DPI. Delegates other messages to the controller.
236 static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
237
238 // Controller for this window.
240
241 // The Flutter engine that owns this window.
243
244 // Controller for the view hosted in this window. Value-initialized if the
245 // window is created from an existing top-level native window created by the
246 // runner.
247 std::unique_ptr<FlutterWindowsViewController> view_controller_;
248
249 // The window archetype.
251
252 // Backing handle for this window.
254
255 // The constraints on the window's client area.
257
258 // True while handling WM_DESTROY; used to detect in-progress destruction.
260
261 // Whether or not the window is currently in a fullscreen state.
262 bool is_fullscreen_ = false;
263
264 // Saved window information from before entering fullscreen mode.
266
267 // Used to mark a window as fullscreen.
268 Microsoft::WRL::ComPtr<ITaskbarList2> task_bar_list_;
269
271};
272
273} // namespace flutter
274
275#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
Microsoft::WRL::ComPtr< ITaskbarList2 > task_bar_list_
HWND GetWindowHandle() const
BoxConstraints box_constraints_
static std::unique_ptr< HostWindow > CreatePopupWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
WindowArchetype archetype_
void InitializeFlutterView(HostWindowInitializationParams const &params)
SavedWindowInfo saved_window_info_
FML_DISALLOW_COPY_AND_ASSIGN(HostWindow)
std::unique_ptr< FlutterWindowsViewController > view_controller_
static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
HostWindow * GetOwnerWindow() const
static std::unique_ptr< HostWindow > CreateTooltipWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
static ActualWindowSize GetWindowContentSize(HWND hwnd)
void EnableRecursively(bool enable)
void SetContentSize(const WindowSizeRequest &size)
static void FocusRootViewOf(HostWindow *window)
HWND GetFlutterViewWindowHandle() const
FlutterWindowsEngine * engine_
static HostWindow * GetThisFromHandle(HWND hwnd)
std::vector< HostWindow * > GetOwnedWindows() const
WindowArchetype GetArchetype() const
virtual bool GetFullscreen() const
void SetConstraints(const WindowConstraints &constraints)
virtual void SetFullscreen(bool fullscreen, std::optional< FlutterEngineDisplayId > display_id)
virtual LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
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::optional< Size > GetWindowSizeForClientSize(WindowsProcTable const &win32, Size const &client_size, std::optional< Size > smallest, std::optional< Size > biggest, DWORD window_style, DWORD extended_window_style, std::optional< HWND > const &owner_hwnd)
static std::unique_ptr< HostWindow > CreateRegularWindow(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title)
HostWindow * FindFirstEnabledDescendant() const
WindowManager *const window_manager_
const EmbeddedViewParams * params
GLFWwindow * window
Definition main.cc:60
FlutterEngine engine
Definition main.cc:84
const char * message
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
WindowRect *(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &output_rect)
WindowArchetype
Definition windowing.h:11
FlutterWindowsViewSizingDelegate * sizing_delegate
long LONG
LONG_PTR LRESULT
unsigned int UINT
LONG_PTR LPARAM
UINT_PTR WPARAM
unsigned long DWORD