Flutter Engine
 
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
14#include "flutter/fml/macros.h"
18
19namespace flutter {
20
21class WindowManager;
22class WindowsProcTable;
23class FlutterWindowsView;
24class FlutterWindowsViewController;
25
26// A Win32 window that hosts a |FlutterWindow| in its client area.
28 public:
29 virtual ~HostWindow();
30
31 // Creates a regular Win32 window with a child view confined to its client
32 // area. |window_manager| is a pointer to the window manager that manages the
33 // |HostWindow|. |engine| is a pointer to the engine that manages
34 // the window manager. |preferred_size| is the preferred size of the window.
35 // |preferred_constraints| are the constraints set on the window's size.
36 // |title| is the title of the window.
37 //
38 // On success, a valid window handle can be retrieved
39 // via |HostWindow::GetWindowHandle|. |nullptr| will be returned
40 // on failure.
41 static std::unique_ptr<HostWindow> CreateRegularWindow(
42 WindowManager* window_manager,
44 const WindowSizeRequest& preferred_size,
45 const WindowConstraints& preferred_constraints,
46 LPCWSTR title);
47
48 // Creates a dialog Win32 window with a child view confined to its client
49 // area. |window_manager| is a pointer to the window manager that manages the
50 // |HostWindow|. |engine| is a pointer to the engine that manages
51 // the window manager. |preferred_size| is the preferred size of the window.
52 // |preferred_constraints| are the constraints set on the window's size.
53 // |title| is the title of the window. |parent| is the parent of this dialog,
54 // which can be `nullptr`.
55 //
56 // On success, a valid window handle can be retrieved
57 // via |HostWindow::GetWindowHandle|. `nullptr` will be returned
58 // on failure.
59 static std::unique_ptr<HostWindow> CreateDialogWindow(
60 WindowManager* window_manager,
62 const WindowSizeRequest& preferred_size,
63 const WindowConstraints& preferred_constraints,
64 LPCWSTR title,
65 HWND parent);
66
67 // Returns the instance pointer for |hwnd| or nullptr if invalid.
68 static HostWindow* GetThisFromHandle(HWND hwnd);
69
70 // Returns the backing window handle, or nullptr if the native window is not
71 // created or has already been destroyed.
72 HWND GetWindowHandle() const;
73
74 // Resizes the window to accommodate a client area of the given
75 // |size|. If the size does not satisfy the constraints, the window will be
76 // resized to the minimum or maximum size as appropriate.
78
79 // Sets the constaints on the client area of the window.
80 // If the current window size does not satisfy the new constraints,
81 // the window will be resized to satisy thew new constraints.
82 void SetConstraints(const WindowConstraints& constraints);
83
84 // Set the fullscreen state. |display_id| indicates the display where
85 // the window should be shown fullscreen; std::nullopt indicates
86 // that no display was specified, so the current display may be used.
87 virtual void SetFullscreen(bool fullscreen,
88 std::optional<FlutterEngineDisplayId> display_id);
89
90 // Returns |true| if this window is fullscreen, otherwise |false|.
91 virtual bool GetFullscreen() const;
92
93 // Given a window identifier, returns the window content size of the
94 // window.
95 static ActualWindowSize GetWindowContentSize(HWND hwnd);
96
97 // Returns the owner window, or nullptr if none.
99
100 // This method is called when a dialog is created or destroyed.
101 // It walks the path of child windows to make sure that the right
102 // windows are enabled or disabled.
104
105 protected:
107
108 // Information saved before going into fullscreen mode, used to restore the
109 // window afterwards.
119
120 // Construct a host window.
121 //
122 // See:
123 // - https://learn.microsoft.com/windows/win32/winmsg/window-styles
124 // - https://learn.microsoft.com/windows/win32/winmsg/extended-window-styles
125 HostWindow(WindowManager* window_manager,
127 WindowArchetype archetype,
128 DWORD window_style,
129 DWORD extended_window_style,
130 const BoxConstraints& box_constraints,
131 Rect const initial_window_rect,
132 LPCWSTR title,
133 std::optional<HWND> const& owner_window);
134
135 // Calculates the required window size, in physical coordinates, to
136 // accommodate the given |client_size|, in logical coordinates, constrained by
137 // optional |smallest| and |biggest|, for a window with the specified
138 // |window_style| and |extended_window_style|. If |owner_hwnd| is not null,
139 // the DPI of the display with the largest area of intersection with
140 // |owner_hwnd| is used for the calculation; otherwise, the primary display's
141 // DPI is used. The resulting size includes window borders, non-client areas,
142 // and drop shadows. On error, returns std::nullopt and logs an error message.
143 static std::optional<Size> GetWindowSizeForClientSize(
144 WindowsProcTable const& win32,
145 Size const& client_size,
146 std::optional<Size> smallest,
147 std::optional<Size> biggest,
148 DWORD window_style,
149 DWORD extended_window_style,
150 std::optional<HWND> const& owner_hwnd);
151
152 // Processes and routes salient window messages for mouse handling,
153 // size change and DPI. Delegates handling of these to member overloads that
154 // inheriting classes can handle.
155 virtual LRESULT HandleMessage(HWND hwnd,
157 WPARAM wparam,
158 LPARAM lparam);
159
160 // Sets the focus to the child view window of |window|.
161 static void FocusRootViewOf(HostWindow* window);
162
163 // Enables or disables mouse and keyboard input to this window and all its
164 // descendants.
165 void EnableRecursively(bool enable);
166
167 // Returns the first enabled descendant window. If the current window itself
168 // is enabled, returns the current window. If no window is enabled, returns
169 // `nullptr`.
171
172 // Returns windows owned by this window.
173 std::vector<HostWindow*> GetOwnedWindows() const;
174
175 // Disables mouse and keyboard input to the window and all its descendants.
176 void DisableRecursively();
177
178 // OS callback called by message pump. Handles the WM_NCCREATE message which
179 // is passed when the non-client area is being created and enables automatic
180 // non-client DPI scaling so that the non-client area automatically
181 // responds to changes in DPI. Delegates other messages to the controller.
182 static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
183
184 // Controller for this window.
186
187 // The Flutter engine that owns this window.
189
190 // Controller for the view hosted in this window. Value-initialized if the
191 // window is created from an existing top-level native window created by the
192 // runner.
193 std::unique_ptr<FlutterWindowsViewController> view_controller_;
194
195 // The window archetype.
197
198 // Backing handle for this window.
200
201 // The constraints on the window's client area.
203
204 // True while handling WM_DESTROY; used to detect in-progress destruction.
206
207 // Whether or not the window is currently in a fullscreen state.
208 bool is_fullscreen_ = false;
209
210 // Saved window information from before entering fullscreen mode.
212
213 // Used to mark a window as fullscreen.
214 Microsoft::WRL::ComPtr<ITaskbarList2> task_bar_list_;
215
217};
218
219} // namespace flutter
220
221#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_HOST_WINDOW_H_
Microsoft::WRL::ComPtr< ITaskbarList2 > task_bar_list_
HWND GetWindowHandle() const
BoxConstraints box_constraints_
WindowArchetype archetype_
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 ActualWindowSize GetWindowContentSize(HWND hwnd)
void EnableRecursively(bool enable)
void SetContentSize(const WindowSizeRequest &size)
static void FocusRootViewOf(HostWindow *window)
FlutterWindowsEngine * engine_
static HostWindow * GetThisFromHandle(HWND hwnd)
std::vector< HostWindow * > GetOwnedWindows() 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_
GLFWwindow * window
Definition main.cc:60
FlutterEngine engine
Definition main.cc:84
G_BEGIN_DECLS GBytes * 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
WindowArchetype
Definition windowing.h:11
long LONG
LONG_PTR LRESULT
unsigned int UINT
LONG_PTR LPARAM
UINT_PTR WPARAM
unsigned long DWORD