Flutter Windows Embedder
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 
9 
10 namespace flutter {
11 
12 namespace {
13 
14 // Returns the Win32 window style for a regular window.
15 //
16 // If |resizable| is false, the resize border (WS_THICKFRAME) and maximize
17 // button (WS_MAXIMIZEBOX) are omitted.
18 DWORD GetWindowStyleForRegular(bool resizable) {
19  DWORD style = WS_OVERLAPPEDWINDOW;
20  if (!resizable) {
21  style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
22  }
23  return style;
24 }
25 
26 } // namespace
27 
29  FlutterWindowsEngine* engine,
30  const WindowSizeRequest& preferred_size,
31  const BoxConstraints& constraints,
32  LPCWSTR title,
33  bool sized_to_content,
34  bool resizable)
35  : HostWindowSized(window_manager, engine, resizable) {
36  FML_CHECK(sized_to_content || preferred_size.has_preferred_view_size);
37  DWORD const window_style = GetWindowStyleForRegular(resizable);
40  .window_style = window_style,
41  .extended_window_style = 0,
42  .box_constraints = constraints,
43  .initial_window_rect = GetInitialRect(engine, preferred_size, constraints,
44  sized_to_content, resizable),
45  .title = title,
46  .owner_window = std::optional<HWND>(),
47  .sizing_delegate = sized_to_content ? AsSizingDelegate() : nullptr,
48  .is_sized_to_content = sized_to_content,
49  });
50 }
51 
53  // Reset the view while this most-derived object is still fully alive, to stop
54  // the raster thread from sizing it before any subobject is torn down. See the
55  // destructor comment in host_window_sized.h for the rationale.
56  view_controller_.reset();
57 }
58 
59 Rect HostWindowRegular::GetInitialRect(FlutterWindowsEngine* engine,
60  const WindowSizeRequest& preferred_size,
61  const BoxConstraints& constraints,
62  bool sized_to_content,
63  bool resizable) {
64  double client_width;
65  double client_height;
66  if (sized_to_content) {
67  // Use the minimum constraint as the initial window size. The window will
68  // be resized to match the rendered content after the first frame.
69  client_width = std::max(1.0, constraints.smallest().width());
70  client_height = std::max(1.0, constraints.smallest().height());
71  } else {
72  client_width = preferred_size.preferred_view_width;
73  client_height = preferred_size.preferred_view_height;
74  }
75 
76  std::optional<Size> const window_size =
78  *engine->windows_proc_table(), Size(client_width, client_height),
79  constraints.smallest(), constraints.biggest(),
80  GetWindowStyleForRegular(resizable), 0, nullptr);
81  return {{CW_USEDEFAULT, CW_USEDEFAULT},
82  window_size ? *window_size : Size{CW_USEDEFAULT, CW_USEDEFAULT}};
83 }
84 
85 } // namespace flutter
std::shared_ptr< WindowsProcTable > windows_proc_table()
void InitializeFlutterView(HostWindowInitializationParams const &params)
Definition: host_window.cc:232
std::unique_ptr< FlutterWindowsViewController > view_controller_
Definition: host_window.h:259
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)
Definition: host_window.cc:751
HostWindowRegular(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, LPCWSTR title, bool sized_to_content, bool resizable)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()