Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
host_window_regular.cc
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
6
8
9namespace flutter {
10
11namespace {
12
13// Returns the Win32 window style for a regular window.
14//
15// If |resizable| is false, the resize border (WS_THICKFRAME) and maximize
16// button (WS_MAXIMIZEBOX) are omitted.
17DWORD GetWindowStyleForRegular(bool resizable) {
18 DWORD style = WS_OVERLAPPEDWINDOW;
19 if (!resizable) {
20 style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
21 }
22 return style;
23}
24
25} // namespace
26
29 const WindowSizeRequest& preferred_size,
30 const BoxConstraints& constraints,
31 LPCWSTR title,
32 bool sized_to_content,
33 bool resizable)
34 : HostWindowSized(window_manager, engine, resizable) {
35 FML_CHECK(sized_to_content || preferred_size.has_preferred_view_size);
36 DWORD const window_style = GetWindowStyleForRegular(resizable);
39 .window_style = window_style,
40 .extended_window_style = 0,
41 .box_constraints = constraints,
42 .initial_window_rect = GetInitialRect(engine, preferred_size, constraints,
43 sized_to_content, resizable),
44 .title = title,
45 .owner_window = std::optional<HWND>(),
46 .sizing_delegate = sized_to_content ? AsSizingDelegate() : nullptr,
47 .is_sized_to_content = sized_to_content,
48 });
49}
50
51Rect HostWindowRegular::GetInitialRect(FlutterWindowsEngine* engine,
52 const WindowSizeRequest& preferred_size,
53 const BoxConstraints& constraints,
54 bool sized_to_content,
55 bool resizable) {
56 double client_width;
57 double client_height;
58 if (sized_to_content) {
59 // Use the minimum constraint as the initial window size. The window will
60 // be resized to match the rendered content after the first frame.
61 client_width = std::max(1.0, constraints.smallest().width());
62 client_height = std::max(1.0, constraints.smallest().height());
63 } else {
64 client_width = preferred_size.preferred_view_width;
65 client_height = preferred_size.preferred_view_height;
66 }
67
68 std::optional<Size> const window_size =
70 *engine->windows_proc_table(), Size(client_width, client_height),
71 constraints.smallest(), constraints.biggest(),
72 GetWindowStyleForRegular(resizable), 0, nullptr);
73 return {{CW_USEDEFAULT, CW_USEDEFAULT},
74 window_size ? *window_size : Size{CW_USEDEFAULT, CW_USEDEFAULT}};
75}
76
77} // namespace flutter
Size smallest() const
Definition geometry.h:94
Size biggest() const
Definition geometry.h:93
void InitializeFlutterView(HostWindowInitializationParams const &params)
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)
HostWindowRegular(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, LPCWSTR title, bool sized_to_content, bool resizable)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
double height() const
Definition geometry.h:45
double width() const
Definition geometry.h:44
FlutterEngine engine
Definition main.cc:84
#define FML_CHECK(condition)
Definition logging.h:104
TSize< Scalar > Size
Definition size.h:159
unsigned long DWORD