Flutter Windows Embedder
host_window_popup.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 #include <cstdio>
7 #include <memory>
10 
11 namespace flutter {
13  WindowManager* window_manager,
14  FlutterWindowsEngine* engine,
15  const BoxConstraints& constraints,
16  GetWindowPositionCallback get_position_callback,
17  HWND parent)
18  : HostWindowSized(window_manager, engine, /*resizable=*/false),
19  get_position_callback_(get_position_callback),
20  parent_(parent),
21  isolate_(Isolate::Current()) {
22  // Use minimum constraints as initial size to ensure the view can be created
23  // with valid metrics. The size will be updated when content is rendered.
24  auto const initial_width =
25  static_cast<double>(constraints.smallest().width());
26  auto const initial_height =
27  static_cast<double>(constraints.smallest().height());
28 
31  .window_style = WS_POPUP,
32  .extended_window_style = WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW,
33  .box_constraints = constraints,
34  .initial_window_rect = {{0, 0}, {initial_width, initial_height}},
35  .title = L"",
36  .owner_window = parent,
37  .nCmdShow = SW_SHOWNOACTIVATE,
38  .sizing_delegate = AsSizingDelegate(),
39  .is_sized_to_content = true});
40 }
41 
43  // Reset the view while this most-derived object is still fully alive, to stop
44  // the raster thread from sizing it (via the overridden ApplyContentSize /
45  // GetWorkArea) before any subobject is torn down. See the destructor comment
46  // in host_window_sized.h for the rationale.
47  view_controller_.reset();
48 }
49 
50 void HostWindowPopup::ApplyContentSize(int32_t physical_width,
51  int32_t physical_height) {
53 }
54 
55 WindowRect HostWindowPopup::GetWorkArea() const {
56  return GetWorkAreaForWindow(parent_);
57 }
58 
60  RECT parent_client_rect;
61  GetClientRect(parent_, &parent_client_rect);
62 
63  // Convert top-left and bottom-right points to screen coordinates.
64  POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
65  POINT parent_bottom_right = {parent_client_rect.right,
66  parent_client_rect.bottom};
67 
68  ClientToScreen(parent_, &parent_top_left);
69  ClientToScreen(parent_, &parent_bottom_right);
70 
71  // Get monitor from HWND and usable work area.
72  HMONITOR monitor = MonitorFromWindow(parent_, MONITOR_DEFAULTTONEAREST);
73  WindowRect work_area = GetWorkArea();
74 
75  IsolateScope scope(isolate_);
76  WindowRect rect{};
77 
78  get_position_callback_(WindowSize{physical_width_, physical_height_},
79  WindowRect{parent_top_left.x, parent_top_left.y,
80  parent_bottom_right.x - parent_top_left.x,
81  parent_bottom_right.y - parent_top_left.y},
82  work_area, rect);
83 
84  SetWindowPos(window_handle_, HWND_TOP, rect.left, rect.top, rect.width,
85  rect.height, SWP_NOACTIVATE | SWP_NOOWNERZORDER);
86 
87  // The positioner constrained the dimensions more than current size, apply
88  // positioner constraints.
89  if (rect.width < physical_width_ || rect.height < physical_height_) {
90  auto metrics_event = view_controller_->view()->CreateWindowMetricsEvent();
91  view_controller_->engine()->SendWindowMetricsEvent(metrics_event);
92  }
93 }
94 
95 } // namespace flutter
void InitializeFlutterView(HostWindowInitializationParams const &params)
Definition: host_window.cc:249
std::unique_ptr< FlutterWindowsViewController > view_controller_
Definition: host_window.h:314
HostWindowPopup(WindowManager *window_manager, FlutterWindowsEngine *engine, const BoxConstraints &constraints, GetWindowPositionCallback get_position_callback, HWND parent)
void ApplyContentSize(int32_t physical_width, int32_t physical_height) override
static WindowRect GetWorkAreaForWindow(HWND hwnd)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
void(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &display_rect, WindowRect &output_rect)