Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::HostWindow Class Reference

#include <host_window.h>

Inheritance diagram for flutter::HostWindow:
flutter::HostWindowPopup flutter::HostWindowSized flutter::HostWindowTooltip flutter::HostWindowDialog flutter::HostWindowRegular

Classes

struct  HostWindowInitializationParams
 
struct  SavedWindowInfo
 

Public Member Functions

virtual ~HostWindow ()
 
HWND GetWindowHandle () const
 
HWND GetFlutterViewWindowHandle () const
 
void SetContentSize (const WindowSizeRequest &size)
 
void SetConstraints (const WindowConstraints &constraints)
 
virtual void SetFullscreen (bool fullscreen, std::optional< FlutterEngineDisplayId > display_id)
 
virtual bool GetFullscreen () const
 
HostWindowGetOwnerWindow () const
 
void UpdateModalStateLayer ()
 

Static Public Member Functions

static std::unique_ptr< HostWindowCreateRegularWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, bool sized_to_content, bool resizable)
 
static std::unique_ptr< HostWindowCreateDialogWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const WindowConstraints &preferred_constraints, LPCWSTR title, HWND parent, bool sized_to_content, bool resizable)
 
static std::unique_ptr< HostWindowCreateTooltipWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
 
static std::unique_ptr< HostWindowCreatePopupWindow (WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowConstraints &preferred_constraints, GetWindowPositionCallback get_position_callback, HWND parent)
 
static HostWindowGetThisFromHandle (HWND hwnd)
 
static ActualWindowSize GetWindowContentSize (HWND hwnd)
 

Protected Member Functions

void InitializeFlutterView (HostWindowInitializationParams const &params)
 
 HostWindow (WindowManager *window_manager, FlutterWindowsEngine *engine)
 
virtual LRESULT HandleMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 
void EnableRecursively (bool enable)
 
HostWindowFindFirstEnabledDescendant () const
 
WindowArchetype GetArchetype () const
 
std::vector< HostWindow * > GetOwnedWindows () const
 
void DisableRecursively ()
 
 FML_DISALLOW_COPY_AND_ASSIGN (HostWindow)
 

Static Protected Member Functions

static std::optional< SizeGetWindowSizeForClientSize (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 void FocusRootViewOf (HostWindow *window)
 
static LRESULT WndProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 

Protected Attributes

friend WindowManager
 
WindowManager *const window_manager_ = nullptr
 
FlutterWindowsEngineengine_
 
std::unique_ptr< FlutterWindowsViewControllerview_controller_
 
WindowArchetype archetype_ = WindowArchetype::kRegular
 
HWND window_handle_
 
BoxConstraints box_constraints_
 
bool is_being_destroyed_ = false
 
bool is_fullscreen_ = false
 
SavedWindowInfo saved_window_info_
 
Microsoft::WRL::ComPtr< ITaskbarList2 > task_bar_list_
 

Detailed Description

Definition at line 29 of file host_window.h.

Constructor & Destructor Documentation

◆ ~HostWindow()

flutter::HostWindow::~HostWindow ( )
virtual

Definition at line 315 of file host_window.cc.

315 {
316 if (view_controller_) {
317 // Unregister the window class. Fail silently if other windows are still
318 // using the class, as only the last window can successfully unregister it.
319 if (!UnregisterClass(kWindowClassName, GetModuleHandle(nullptr))) {
320 // Clear the error state after the failed unregistration.
322 }
323 }
324}
std::unique_ptr< FlutterWindowsViewController > view_controller_
WINBASEAPI VOID WINAPI SetLastError(_In_ DWORD dwErrCode)
#define ERROR_SUCCESS

References ERROR_SUCCESS, and SetLastError().

◆ HostWindow()

flutter::HostWindow::HostWindow ( WindowManager window_manager,
FlutterWindowsEngine engine 
)
protected

Definition at line 228 of file host_window.cc.

230 : window_manager_(window_manager), engine_(engine) {}
FlutterWindowsEngine * engine_
WindowManager *const window_manager_
FlutterEngine engine
Definition main.cc:84

Member Function Documentation

◆ CreateDialogWindow()

std::unique_ptr< HostWindow > flutter::HostWindow::CreateDialogWindow ( WindowManager window_manager,
FlutterWindowsEngine engine,
const WindowSizeRequest preferred_size,
const WindowConstraints preferred_constraints,
LPCWSTR  title,
HWND  parent,
bool  sized_to_content,
bool  resizable 
)
static

Definition at line 191 of file host_window.cc.

199 {
200 return std::unique_ptr<HostWindow>(new HostWindowDialog(
201 window_manager, engine, preferred_size,
202 FromWindowConstraints(preferred_constraints), title,
203 parent ? parent : std::optional<HWND>(), sized_to_content, resizable));
204}
Definition ref_ptr.h:261

References engine.

Referenced by flutter::WindowManager::CreateDialogWindow().

◆ CreatePopupWindow()

std::unique_ptr< HostWindow > flutter::HostWindow::CreatePopupWindow ( WindowManager window_manager,
FlutterWindowsEngine engine,
const WindowConstraints preferred_constraints,
GetWindowPositionCallback  get_position_callback,
HWND  parent 
)
static

Definition at line 217 of file host_window.cc.

222 {
223 return std::unique_ptr<HostWindowPopup>(new HostWindowPopup(
224 window_manager, engine, FromWindowConstraints(preferred_constraints),
225 get_position_callback, parent));
226}

References engine.

Referenced by flutter::WindowManager::CreatePopupWindow().

◆ CreateRegularWindow()

std::unique_ptr< HostWindow > flutter::HostWindow::CreateRegularWindow ( WindowManager window_manager,
FlutterWindowsEngine engine,
const WindowSizeRequest preferred_size,
const WindowConstraints preferred_constraints,
LPCWSTR  title,
bool  sized_to_content,
bool  resizable 
)
static

Definition at line 177 of file host_window.cc.

184 {
185 return std::unique_ptr<HostWindow>(
186 new HostWindowRegular(window_manager, engine, preferred_size,
187 FromWindowConstraints(preferred_constraints), title,
188 sized_to_content, resizable));
189}

References engine.

Referenced by flutter::WindowManager::CreateRegularWindow().

◆ CreateTooltipWindow()

std::unique_ptr< HostWindow > flutter::HostWindow::CreateTooltipWindow ( WindowManager window_manager,
FlutterWindowsEngine engine,
const WindowConstraints preferred_constraints,
GetWindowPositionCallback  get_position_callback,
HWND  parent 
)
static

Definition at line 206 of file host_window.cc.

211 {
212 return std::unique_ptr<HostWindowTooltip>(new HostWindowTooltip(
213 window_manager, engine, FromWindowConstraints(preferred_constraints),
214 get_position_callback, parent));
215}

References engine.

Referenced by flutter::WindowManager::CreateTooltipWindow().

◆ DisableRecursively()

void flutter::HostWindow::DisableRecursively ( )
protected

Definition at line 826 of file host_window.cc.

826 {
827 // Disable the window itself.
828 EnableWindow(window_handle_, false);
829
830 for (HostWindow* const owned : GetOwnedWindows()) {
831 owned->DisableRecursively();
832 }
833}
std::vector< HostWindow * > GetOwnedWindows() const

◆ EnableRecursively()

void flutter::HostWindow::EnableRecursively ( bool  enable)
protected

Definition at line 774 of file host_window.cc.

774 {
775 EnableWindow(window_handle_, enable);
776
777 for (HostWindow* const owned : GetOwnedWindows()) {
778 owned->EnableRecursively(enable);
779 }
780}

◆ FindFirstEnabledDescendant()

HostWindow * flutter::HostWindow::FindFirstEnabledDescendant ( ) const
protected

Definition at line 782 of file host_window.cc.

782 {
783 if (IsWindowEnabled(window_handle_)) {
784 return const_cast<HostWindow*>(this);
785 }
786
787 for (HostWindow* const owned : GetOwnedWindows()) {
788 if (HostWindow* const result = owned->FindFirstEnabledDescendant()) {
789 return result;
790 }
791 }
792
793 return nullptr;
794}
HostWindow(WindowManager *window_manager, FlutterWindowsEngine *engine)

References FindFirstEnabledDescendant().

Referenced by FindFirstEnabledDescendant(), and flutter::HostWindowDialog::HandleMessage().

◆ FML_DISALLOW_COPY_AND_ASSIGN()

flutter::HostWindow::FML_DISALLOW_COPY_AND_ASSIGN ( HostWindow  )
protected

◆ FocusRootViewOf()

void flutter::HostWindow::FocusRootViewOf ( HostWindow window)
staticprotected

Definition at line 349 of file host_window.cc.

349 {
350 auto child_content = window->view_controller_->view()->GetWindowHandle();
351 if (window != nullptr && child_content != nullptr) {
352 SetFocus(child_content);
353 }
354};
GLFWwindow * window
Definition main.cc:60

References window.

Referenced by flutter::HostWindowDialog::HandleMessage().

◆ GetArchetype()

WindowArchetype flutter::HostWindow::GetArchetype ( ) const
inlineprotected

Definition at line 228 of file host_window.h.

228{ return archetype_; }
WindowArchetype archetype_

References archetype_.

◆ GetFlutterViewWindowHandle()

HWND flutter::HostWindow::GetFlutterViewWindowHandle ( ) const

Definition at line 345 of file host_window.cc.

345 {
346 return view_controller_->view()->GetWindowHandle();
347}

References GetWindowHandle().

◆ GetFullscreen()

bool flutter::HostWindow::GetFullscreen ( ) const
virtual

Reimplemented in flutter::HostWindowDialog.

Definition at line 710 of file host_window.cc.

710 {
711 return is_fullscreen_;
712}

◆ GetOwnedWindows()

std::vector< HostWindow * > flutter::HostWindow::GetOwnedWindows ( ) const
protected

Definition at line 796 of file host_window.cc.

796 {
797 std::vector<HostWindow*> owned_windows;
798 struct EnumData {
799 HWND owner_window_handle;
800 std::vector<HostWindow*>* owned_windows;
801 } data{window_handle_, &owned_windows};
802
803 EnumWindows(
804 [](HWND hwnd, LPARAM lparam) -> BOOL {
805 auto* const data = reinterpret_cast<EnumData*>(lparam);
806 if (GetWindow(hwnd, GW_OWNER) == data->owner_window_handle) {
807 HostWindow* const window = GetThisFromHandle(hwnd);
808 if (window && !window->is_being_destroyed_) {
809 data->owned_windows->push_back(window);
810 }
811 }
812 return TRUE;
813 },
814 reinterpret_cast<LPARAM>(&data));
815
816 return owned_windows;
817}
static HostWindow * GetThisFromHandle(HWND hwnd)
return TRUE
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
int BOOL
LONG_PTR LPARAM

References flutter::data, TRUE, and window.

◆ GetOwnerWindow()

HostWindow * flutter::HostWindow::GetOwnerWindow ( ) const

Definition at line 819 of file host_window.cc.

819 {
820 if (HWND const owner_window_handle = GetWindow(GetWindowHandle(), GW_OWNER)) {
821 return GetThisFromHandle(owner_window_handle);
822 }
823 return nullptr;
824};
HWND GetWindowHandle() const

Referenced by flutter::HostWindowDialog::HandleMessage(), and flutter::testing::TEST_F().

◆ GetThisFromHandle()

HostWindow * flutter::HostWindow::GetThisFromHandle ( HWND  hwnd)
static

Definition at line 326 of file host_window.cc.

326 {
327 wchar_t class_name[256];
328 if (!GetClassName(hwnd, class_name, sizeof(class_name) / sizeof(wchar_t))) {
329 FML_LOG(ERROR) << "Failed to get class name for window handle " << hwnd
330 << ": " << GetLastErrorAsString();
331 return nullptr;
332 }
333 // Ignore window handles that do not match the expected class name.
334 if (wcscmp(class_name, kWindowClassName) != 0) {
335 return nullptr;
336 }
337
338 return reinterpret_cast<HostWindow*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
339}
#define FML_LOG(severity)
Definition logging.h:101

References FML_LOG.

Referenced by flutter::WindowManager::HandleMessage(), InternalFlutterWindows_WindowManager_GetFullscreen(), InternalFlutterWindows_WindowManager_OnDestroyWindow(), InternalFlutterWindows_WindowManager_SetFullscreen(), InternalFlutterWindows_WindowManager_SetWindowConstraints(), InternalFlutterWindows_WindowManager_SetWindowSize(), InternalFlutterWindows_WindowManager_UpdatePopupPosition(), InternalFlutterWindows_WindowManager_UpdateTooltipPosition(), and flutter::testing::TEST_F().

◆ GetWindowContentSize()

ActualWindowSize flutter::HostWindow::GetWindowContentSize ( HWND  hwnd)
static

Definition at line 714 of file host_window.cc.

714 {
715 RECT rect;
716 GetClientRect(hwnd, &rect);
717 double const dpr = FlutterDesktopGetDpiForHWND(hwnd) /
718 static_cast<double>(USER_DEFAULT_SCREEN_DPI);
719 double const width = rect.right / dpr;
720 double const height = rect.bottom / dpr;
721 return {
722 .width = rect.right / dpr,
723 .height = rect.bottom / dpr,
724 };
725}
UINT FlutterDesktopGetDpiForHWND(HWND hwnd)
int32_t height
int32_t width

References FlutterDesktopGetDpiForHWND(), height, and width.

Referenced by InternalFlutterWindows_WindowManager_GetWindowContentSize().

◆ GetWindowHandle()

HWND flutter::HostWindow::GetWindowHandle ( ) const

Definition at line 341 of file host_window.cc.

341 {
342 return window_handle_;
343}

Referenced by GetFlutterViewWindowHandle(), and flutter::testing::TEST_F().

◆ GetWindowSizeForClientSize()

std::optional< Size > flutter::HostWindow::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 
)
staticprotected

Definition at line 727 of file host_window.cc.

734 {
735 UINT const dpi = GetDpiForHWND(owner_hwnd ? *owner_hwnd : nullptr);
736 double const scale_factor =
737 static_cast<double>(dpi) / USER_DEFAULT_SCREEN_DPI;
738 RECT rect = {
739 .right = static_cast<LONG>(client_size.width() * scale_factor),
740 .bottom = static_cast<LONG>(client_size.height() * scale_factor)};
741
742 if (!win32.AdjustWindowRectExForDpi(&rect, window_style, FALSE,
743 extended_window_style, dpi)) {
744 FML_LOG(ERROR) << "Failed to run AdjustWindowRectExForDpi: "
745 << GetLastErrorAsString();
746 return std::nullopt;
747 }
748
749 double width = static_cast<double>(rect.right - rect.left);
750 double height = static_cast<double>(rect.bottom - rect.top);
751
752 // Apply size constraints.
753 double const non_client_width = width - (client_size.width() * scale_factor);
754 double const non_client_height =
755 height - (client_size.height() * scale_factor);
756 if (smallest) {
757 flutter::Size min_physical_size = ClampToVirtualScreen(
758 flutter::Size(smallest->width() * scale_factor + non_client_width,
759 smallest->height() * scale_factor + non_client_height));
760 width = std::max(width, min_physical_size.width());
761 height = std::max(height, min_physical_size.height());
762 }
763 if (biggest) {
764 flutter::Size max_physical_size = ClampToVirtualScreen(
765 flutter::Size(biggest->width() * scale_factor + non_client_width,
766 biggest->height() * scale_factor + non_client_height));
767 width = std::min(width, max_physical_size.width());
768 height = std::min(height, max_physical_size.height());
769 }
770
771 return flutter::Size{width, height};
772}
double height() const
Definition geometry.h:45
double width() const
Definition geometry.h:44
UINT GetDpiForHWND(HWND hwnd)
Definition dpi_utils.cc:128
long LONG
unsigned int UINT

References flutter::WindowsProcTable::AdjustWindowRectExForDpi(), FML_LOG, flutter::GetDpiForHWND(), height, flutter::Size::height(), width, and flutter::Size::width().

◆ HandleMessage()

LRESULT flutter::HostWindow::HandleMessage ( HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)
protectedvirtual

Reimplemented in flutter::HostWindowDialog, and flutter::HostWindowTooltip.

Definition at line 372 of file host_window.cc.

375 {
377 window_handle_, message, wparam, lparam);
378 if (result) {
379 return *result;
380 }
381
382 switch (message) {
383 case WM_DESTROY:
384 is_being_destroyed_ = true;
385 break;
386
387 case WM_NCLBUTTONDOWN: {
388 // Fix for 500ms hang after user clicks on the title bar, but before
389 // moving mouse. Reference:
390 // https://gamedev.net/forums/topic/672094-keeping-things-moving-during-win32-moveresize-events/5254386/
391 if (SendMessage(window_handle_, WM_NCHITTEST, wparam, lparam) ==
392 HTCAPTION) {
393 POINT cursorPos;
394 // Get the current cursor position and synthesize WM_MOUSEMOVE to
395 // unblock default window proc implementation for WM_NCLBUTTONDOWN at
396 // HTCAPTION.
397 GetCursorPos(&cursorPos);
398 ScreenToClient(window_handle_, &cursorPos);
399 PostMessage(window_handle_, WM_MOUSEMOVE, 0,
400 MAKELPARAM(cursorPos.x, cursorPos.y));
401 }
402 break;
403 }
404
405 case WM_DPICHANGED: {
406 auto* const new_scaled_window_rect = reinterpret_cast<RECT*>(lparam);
407 LONG const width =
408 new_scaled_window_rect->right - new_scaled_window_rect->left;
409 LONG const height =
410 new_scaled_window_rect->bottom - new_scaled_window_rect->top;
411 SetWindowPos(hwnd, nullptr, new_scaled_window_rect->left,
412 new_scaled_window_rect->top, width, height,
413 SWP_NOZORDER | SWP_NOACTIVATE);
414 return 0;
415 }
416
417 case WM_GETMINMAXINFO: {
418 RECT window_rect;
419 GetWindowRect(hwnd, &window_rect);
420 RECT client_rect;
421 GetClientRect(hwnd, &client_rect);
422 LONG const non_client_width = (window_rect.right - window_rect.left) -
423 (client_rect.right - client_rect.left);
424 LONG const non_client_height = (window_rect.bottom - window_rect.top) -
425 (client_rect.bottom - client_rect.top);
426
427 UINT const dpi = flutter::GetDpiForHWND(hwnd);
428 double const scale_factor =
429 static_cast<double>(dpi) / USER_DEFAULT_SCREEN_DPI;
430
431 MINMAXINFO* info = reinterpret_cast<MINMAXINFO*>(lparam);
432 Size const min_physical_size = ClampToVirtualScreen(Size(
433 box_constraints_.smallest().width() * scale_factor + non_client_width,
434 box_constraints_.smallest().height() * scale_factor +
435 non_client_height));
436
437 info->ptMinTrackSize.x = min_physical_size.width();
438 info->ptMinTrackSize.y = min_physical_size.height();
439 Size const max_physical_size = ClampToVirtualScreen(Size(
440 box_constraints_.biggest().width() * scale_factor + non_client_width,
441 box_constraints_.biggest().height() * scale_factor +
442 non_client_height));
443
444 info->ptMaxTrackSize.x = max_physical_size.width();
445 info->ptMaxTrackSize.y = max_physical_size.height();
446 return 0;
447 }
448
449 case WM_SIZE: {
450 auto child_content = view_controller_->view()->GetWindowHandle();
451 if (child_content != nullptr) {
452 // Resize and reposition the child content window.
453 RECT client_rect;
454 GetClientRect(hwnd, &client_rect);
455 MoveWindow(child_content, client_rect.left, client_rect.top,
456 client_rect.right - client_rect.left,
457 client_rect.bottom - client_rect.top, TRUE);
458 }
459 return 0;
460 }
461
462 case WM_ACTIVATE:
463 FocusRootViewOf(this);
464 return 0;
465
466 case WM_DWMCOLORIZATIONCOLORCHANGED:
467 UpdateTheme(hwnd);
468 return 0;
469
470 default:
471 break;
472 }
473
474 if (!view_controller_) {
475 return 0;
476 }
477
478 return DefWindowProc(hwnd, message, wparam, lparam);
479}
Size smallest() const
Definition geometry.h:94
Size biggest() const
Definition geometry.h:93
WindowProcDelegateManager * window_proc_delegate_manager()
BoxConstraints box_constraints_
static void FocusRootViewOf(HostWindow *window)
std::optional< LRESULT > OnTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) const
const char * message
TSize< Scalar > Size
Definition size.h:159
#define SendMessage
#define PostMessage

References flutter::GetDpiForHWND(), height, flutter::Size::height(), message, PostMessage, SendMessage, TRUE, width, and flutter::Size::width().

Referenced by flutter::HostWindowDialog::HandleMessage(), and flutter::HostWindowTooltip::HandleMessage().

◆ InitializeFlutterView()

void flutter::HostWindow::InitializeFlutterView ( HostWindowInitializationParams const &  params)
protected

Definition at line 232 of file host_window.cc.

233 {
234 // Set up the view.
235 auto view_window = std::make_unique<FlutterWindow>(
236 params.initial_window_rect.width(), params.initial_window_rect.height(),
238
239 std::unique_ptr<FlutterWindowsView> view =
240 engine_->CreateView(std::move(view_window), params.is_sized_to_content,
241 params.box_constraints, params.sizing_delegate);
242 FML_CHECK(view != nullptr);
243
245 std::make_unique<FlutterWindowsViewController>(nullptr, std::move(view));
247 // The Windows embedder listens to accessibility updates using the
248 // view's HWND. The embedder's accessibility features may be stale if
249 // the app was in headless mode.
251
252 // Register the window class.
253 if (!IsClassRegistered(kWindowClassName)) {
254 auto const idi_app_icon = 101;
255 WNDCLASSEX window_class = {};
256 window_class.cbSize = sizeof(WNDCLASSEX);
257 window_class.style = CS_HREDRAW | CS_VREDRAW;
258 window_class.lpfnWndProc = HostWindow::WndProc;
259 window_class.hInstance = GetModuleHandle(nullptr);
260 window_class.hIcon =
261 LoadIcon(window_class.hInstance, MAKEINTRESOURCE(idi_app_icon));
262 if (!window_class.hIcon) {
263 window_class.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
264 }
265 window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
266 window_class.lpszClassName = kWindowClassName;
267
268 FML_CHECK(RegisterClassEx(&window_class));
269 }
270
271 // Create the native window.
272 window_handle_ = CreateWindowEx(
273 params.extended_window_style, kWindowClassName, params.title,
274 params.window_style, params.initial_window_rect.left(),
275 params.initial_window_rect.top(), params.initial_window_rect.width(),
276 params.initial_window_rect.height(),
277 params.owner_window ? *params.owner_window : nullptr, nullptr,
278 GetModuleHandle(nullptr), engine_->windows_proc_table().get());
279 FML_CHECK(window_handle_ != nullptr);
280
281 // Adjust the window position so its origin aligns with the top-left corner
282 // of the window frame, not the window rectangle (which includes the
283 // drop-shadow). This adjustment must be done post-creation since the frame
284 // rectangle is only available after the window has been created.
285 RECT frame_rect;
286 DwmGetWindowAttribute(window_handle_, DWMWA_EXTENDED_FRAME_BOUNDS,
287 &frame_rect, sizeof(frame_rect));
288 RECT window_rect;
289 GetWindowRect(window_handle_, &window_rect);
290 LONG const left_dropshadow_width = frame_rect.left - window_rect.left;
291 LONG const top_dropshadow_height = window_rect.top - frame_rect.top;
292 SetWindowPos(window_handle_, nullptr,
293 window_rect.left - left_dropshadow_width,
294 window_rect.top - top_dropshadow_height, 0, 0,
295 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
296
297 UpdateTheme(window_handle_);
298
299 SetChildContent(view_controller_->view()->GetWindowHandle(), window_handle_);
300
301 // Defer showing the window until the first frame is rendered so the user
302 // doesn't see a blank window. Each view has its own first-frame callback,
303 // so this works correctly for multi-window apps.
304 view_controller_->view()->SetFirstFrameCallback(
305 [hwnd = window_handle_, cmd_show = params.nCmdShow]() {
306 if (::IsWindow(hwnd)) {
307 ShowWindow(hwnd, cmd_show);
308 }
309 });
310 archetype_ = params.archetype;
311 SetWindowLongPtr(window_handle_, GWLP_USERDATA,
312 reinterpret_cast<LONG_PTR>(this));
313}
std::shared_ptr< WindowsProcTable > windows_proc_table()
std::unique_ptr< FlutterWindowsView > CreateView(std::unique_ptr< WindowBindingHandler > window, bool is_sized_to_content, const BoxConstraints &box_constraints, FlutterWindowsViewSizingDelegate *sizing_delegate=nullptr)
std::shared_ptr< DisplayManagerWin32 > display_manager()
static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
const EmbeddedViewParams * params
FlView * view
#define FML_CHECK(condition)
Definition logging.h:104
__w64 long LONG_PTR
#define LoadIcon

References flutter::FlutterWindowsEngine::CreateView(), flutter::FlutterWindowsEngine::display_manager(), engine_, FML_CHECK, LoadIcon, params, flutter::FlutterWindowsEngine::running(), flutter::FlutterWindowsEngine::UpdateAccessibilityFeatures(), view, view_controller_, window_handle_, flutter::FlutterWindowsEngine::windows_proc_table(), and WndProc().

Referenced by flutter::HostWindowDialog::HostWindowDialog(), flutter::HostWindowPopup::HostWindowPopup(), flutter::HostWindowRegular::HostWindowRegular(), and flutter::HostWindowTooltip::HostWindowTooltip().

◆ SetConstraints()

void flutter::HostWindow::SetConstraints ( const WindowConstraints constraints)

Definition at line 523 of file host_window.cc.

523 {
524 box_constraints_ = FromWindowConstraints(constraints);
525
526 if (GetFullscreen()) {
527 std::optional<Size> const window_size = GetWindowSizeForClientSize(
533 if (!window_size) {
534 return;
535 }
536
538 saved_window_info_.rect.left + static_cast<LONG>(window_size->width());
539 saved_window_info_.rect.bottom =
540 saved_window_info_.rect.top + static_cast<LONG>(window_size->height());
541 } else {
542 auto const client_size = GetWindowContentSize(window_handle_);
543 auto const current_size = Size(client_size.width, client_size.height);
544 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
545 GetWindowInfo(window_handle_, &window_info);
546 std::optional<Size> const window_size = GetWindowSizeForClientSize(
547 *engine_->windows_proc_table(), current_size,
549 window_info.dwStyle, window_info.dwExStyle, nullptr);
550
551 if (window_size && current_size != window_size) {
552 SetWindowPos(window_handle_, NULL, 0, 0, window_size->width(),
553 window_size->height(),
554 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
555 }
556 }
557}
SavedWindowInfo saved_window_info_
static ActualWindowSize GetWindowContentSize(HWND hwnd)
virtual bool GetFullscreen() const
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)

◆ SetContentSize()

void flutter::HostWindow::SetContentSize ( const WindowSizeRequest size)

Definition at line 481 of file host_window.cc.

481 {
482 if (!size.has_preferred_view_size) {
483 return;
484 }
485
486 if (GetFullscreen()) {
487 std::optional<Size> const window_size = GetWindowSizeForClientSize(
489 Size(size.preferred_view_width, size.preferred_view_height),
492 if (!window_size) {
493 return;
494 }
495
497 ActualWindowSize{.width = size.preferred_view_width,
498 .height = size.preferred_view_height};
500 saved_window_info_.rect.left + static_cast<LONG>(window_size->width());
501 saved_window_info_.rect.bottom =
502 saved_window_info_.rect.top + static_cast<LONG>(window_size->height());
503 } else {
504 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
505 GetWindowInfo(window_handle_, &window_info);
506
507 std::optional<Size> const window_size = GetWindowSizeForClientSize(
509 Size(size.preferred_view_width, size.preferred_view_height),
511 window_info.dwStyle, window_info.dwExStyle, nullptr);
512
513 if (!window_size) {
514 return;
515 }
516
517 SetWindowPos(window_handle_, NULL, 0, 0, window_size->width(),
518 window_size->height(),
519 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
520 }
521}
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

References flutter::size, and flutter::ActualWindowSize::width.

◆ SetFullscreen()

void flutter::HostWindow::SetFullscreen ( bool  fullscreen,
std::optional< FlutterEngineDisplayId display_id 
)
virtual

Reimplemented in flutter::HostWindowDialog.

Definition at line 564 of file host_window.cc.

566 {
567 if (fullscreen == GetFullscreen()) {
568 return;
569 }
570
571 if (fullscreen) {
572 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
573 GetWindowInfo(window_handle_, &window_info);
574 saved_window_info_.style = window_info.dwStyle;
575 saved_window_info_.ex_style = window_info.dwExStyle;
576 // Store the original window rect, DPI, and monitor info to detect changes
577 // and more accurately restore window placements when exiting fullscreen.
578 ::GetWindowRect(window_handle_, &saved_window_info_.rect);
582 MonitorFromWindow(window_handle_, MONITOR_DEFAULTTONEAREST);
585 GetMonitorInfo(saved_window_info_.monitor,
587 }
588
589 if (fullscreen) {
590 // Next, get the raw HMONITOR that we want to be fullscreened on
591 HMONITOR monitor =
592 MonitorFromWindow(window_handle_, MONITOR_DEFAULTTONEAREST);
593 if (display_id) {
594 if (auto const display =
595 engine_->display_manager()->FindById(display_id.value())) {
596 monitor = reinterpret_cast<HMONITOR>(display->display_id);
597 }
598 }
599
600 MONITORINFO monitor_info;
601 monitor_info.cbSize = sizeof(monitor_info);
602 if (!GetMonitorInfo(monitor, &monitor_info)) {
603 FML_LOG(ERROR) << "Cannot set window fullscreen because the monitor info "
604 "was not found";
605 }
606
607 auto const width = RectWidth(monitor_info.rcMonitor);
608 auto const height = RectHeight(monitor_info.rcMonitor);
609 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
610 GetWindowInfo(window_handle_, &window_info);
611
612 // Set new window style and size.
613 SetWindowLong(window_handle_, GWL_STYLE,
614 saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME));
615 SetWindowLong(
616 window_handle_, GWL_EXSTYLE,
617 saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE |
618 WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
619
620 // We call SetWindowPos first to set the window flags immediately. This
621 // makes it so that the WM_GETMINMAXINFO gets called with the correct window
622 // and content sizes.
623 SetWindowPos(window_handle_, NULL, 0, 0, 0, 0,
624 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
625
626 SetWindowPos(window_handle_, nullptr, monitor_info.rcMonitor.left,
627 monitor_info.rcMonitor.top, width, height,
628 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
629 } else {
630 // Restore the window style and bounds saved prior to entering fullscreen.
631 // Use WS_VISIBLE for windows shown after SetFullscreen: crbug.com/1062251.
632 // Making multiple window adjustments here is ugly, but if SetWindowPos()
633 // doesn't redraw, the taskbar won't be repainted.
634 SetWindowLong(window_handle_, GWL_STYLE,
635 saved_window_info_.style | WS_VISIBLE);
636 SetWindowLong(window_handle_, GWL_EXSTYLE, saved_window_info_.ex_style);
637
638 // We call SetWindowPos first to set the window flags immediately. This
639 // makes it so that the WM_GETMINMAXINFO gets called with the correct window
640 // and content sizes.
641 SetWindowPos(window_handle_, NULL, 0, 0, 0, 0,
642 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
643
644 HMONITOR monitor =
645 MonitorFromRect(&saved_window_info_.rect, MONITOR_DEFAULTTONEAREST);
646 MONITORINFO monitor_info;
647 monitor_info.cbSize = sizeof(monitor_info);
648 GetMonitorInfo(monitor, &monitor_info);
649
650 auto window_rect = saved_window_info_.rect;
651
652 // Adjust the window bounds to restore, if displays were disconnected,
653 // virtually rearranged, or otherwise changed metrics during fullscreen.
654 if (monitor != saved_window_info_.monitor ||
656 monitor_info.rcWork)) {
657 window_rect = AdjustToFit(monitor_info.rcWork, window_rect);
658 }
659
660 auto const fullscreen_dpi = GetDpiForHWND(window_handle_);
661 SetWindowPos(window_handle_, nullptr, window_rect.left, window_rect.top,
662 RectWidth(window_rect), RectHeight(window_rect),
663 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
664 auto const final_dpi = GetDpiForHWND(window_handle_);
665 if (final_dpi != saved_window_info_.dpi || final_dpi != fullscreen_dpi) {
666 // Reissue SetWindowPos if the DPI changed from saved or fullscreen DPIs.
667 // The first call may misinterpret bounds spanning displays, if the
668 // fullscreen display's DPI does not match the target display's DPI.
669 //
670 // Scale and clamp the bounds if the final DPI changed from the saved DPI.
671 // This more accurately matches the original placement, while avoiding
672 // unexpected offscreen placement in a recongifured multi-screen space.
673 if (final_dpi != saved_window_info_.dpi) {
674 auto const scale =
675 final_dpi / static_cast<float>(saved_window_info_.dpi);
676 auto const width = static_cast<LONG>(scale * RectWidth(window_rect));
677 auto const height = static_cast<LONG>(scale * RectHeight(window_rect));
678 window_rect.right = window_rect.left + width;
679 window_rect.bottom = window_rect.top + height;
680 window_rect = AdjustToFit(monitor_info.rcWork, window_rect);
681 }
682
683 SetWindowPos(window_handle_, nullptr, window_rect.left, window_rect.top,
684 RectWidth(window_rect), RectHeight(window_rect),
685 SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
686 }
687 }
688
689 if (!task_bar_list_) {
690 HRESULT hr =
691 ::CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER,
692 IID_PPV_ARGS(&task_bar_list_));
693 if (SUCCEEDED(hr) && FAILED(task_bar_list_->HrInit())) {
694 task_bar_list_ = nullptr;
695 }
696 }
697
698 // As per MSDN marking the window as fullscreen should ensure that the
699 // taskbar is moved to the bottom of the Z-order when the fullscreen window
700 // is activated. If the window is not fullscreen, the Shell falls back to
701 // heuristics to determine how the window should be treated, which means
702 // that it could still consider the window as fullscreen. :(
703 if (task_bar_list_) {
704 task_bar_list_->MarkFullscreenWindow(window_handle_, !!fullscreen);
705 }
706
707 is_fullscreen_ = fullscreen;
708}
Microsoft::WRL::ComPtr< ITaskbarList2 > task_bar_list_
LONG RectWidth(const RECT &r)
Definition rect_helper.h:11
bool AreRectsEqual(const RECT &a, const RECT &b)
Definition rect_helper.h:19
LONG RectHeight(const RECT &r)
Definition rect_helper.h:15
#define SUCCEEDED(hr)
#define FAILED(hr)

References flutter::AreRectsEqual(), FAILED, FML_LOG, flutter::GetDpiForHWND(), height, flutter::RectHeight(), flutter::RectWidth(), SUCCEEDED, and width.

◆ UpdateModalStateLayer()

void flutter::HostWindow::UpdateModalStateLayer ( )

Definition at line 835 of file host_window.cc.

835 {
836 auto children = GetOwnedWindows();
837
838 if (children.empty()) {
839 // Leaf window in the active path, enable it.
840 EnableWindow(window_handle_, true);
841 } else {
842 // Non-leaf window in the active path, disable it and process children.
843 EnableWindow(window_handle_, false);
844
845 // On same level of window hierarchy the most recently created window
846 // will remain enabled.
847 auto latest_child = *std::max_element(
848 children.begin(), children.end(), [](HostWindow* a, HostWindow* b) {
849 return a->view_controller_->view()->view_id() <
850 b->view_controller_->view()->view_id();
851 });
852
853 for (HostWindow* const child : children) {
854 if (child == latest_child) {
855 child->UpdateModalStateLayer();
856 } else {
857 child->DisableRecursively();
858 }
859 }
860 }
861}

◆ WndProc()

LRESULT flutter::HostWindow::WndProc ( HWND  hwnd,
UINT  message,
WPARAM  wparam,
LPARAM  lparam 
)
staticprotected

Definition at line 356 of file host_window.cc.

359 {
360 if (message == WM_NCCREATE) {
361 auto* const create_struct = reinterpret_cast<CREATESTRUCT*>(lparam);
362 auto* const windows_proc_table =
363 static_cast<WindowsProcTable*>(create_struct->lpCreateParams);
364 windows_proc_table->EnableNonClientDpiScaling(hwnd);
365 } else if (HostWindow* const window = GetThisFromHandle(hwnd)) {
366 return window->HandleMessage(hwnd, message, wparam, lparam);
367 }
368
369 return DefWindowProc(hwnd, message, wparam, lparam);
370}

References flutter::WindowsProcTable::EnableNonClientDpiScaling(), message, and window.

Referenced by InitializeFlutterView().

Member Data Documentation

◆ archetype_

WindowArchetype flutter::HostWindow::archetype_ = WindowArchetype::kRegular
protected

Definition at line 254 of file host_window.h.

Referenced by GetArchetype().

◆ box_constraints_

BoxConstraints flutter::HostWindow::box_constraints_
protected

Definition at line 260 of file host_window.h.

◆ engine_

FlutterWindowsEngine* flutter::HostWindow::engine_
protected

◆ is_being_destroyed_

bool flutter::HostWindow::is_being_destroyed_ = false
protected

Definition at line 263 of file host_window.h.

Referenced by flutter::HostWindowDialog::HandleMessage().

◆ is_fullscreen_

bool flutter::HostWindow::is_fullscreen_ = false
protected

Definition at line 266 of file host_window.h.

◆ saved_window_info_

SavedWindowInfo flutter::HostWindow::saved_window_info_
protected

Definition at line 269 of file host_window.h.

◆ task_bar_list_

Microsoft::WRL::ComPtr<ITaskbarList2> flutter::HostWindow::task_bar_list_
protected

Definition at line 272 of file host_window.h.

◆ view_controller_

◆ window_handle_

◆ window_manager_

WindowManager* const flutter::HostWindow::window_manager_ = nullptr
protected

Definition at line 243 of file host_window.h.

◆ WindowManager

friend flutter::HostWindow::WindowManager
protected

Definition at line 170 of file host_window.h.


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