Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
host_window_sized.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
10
11namespace flutter {
12
15 bool resizable)
16 : HostWindow(window_manager, engine),
17 resizable_(resizable),
18 view_alive_(std::make_shared<int>(0)) {}
19
21 // By the time the base destructor runs, the most-derived class must have
22 // already reset |view_controller_| (and therefore stopped the raster thread
23 // from sizing this object). See the destructor comment in host_window_sized.h
24 // for the rationale. If this fires, a HostWindowSized subclass is missing the
25 // required |view_controller_.reset()| at the start of its destructor.
27 << "HostWindowSized subclass must reset view_controller_ in its "
28 "destructor.";
29}
30
31void HostWindowSized::DidUpdateViewSize(int32_t width, int32_t height) {
32 // This is called from the raster thread.
33 std::weak_ptr<int> weak_view_alive = view_alive_;
34 engine_->task_runner()->PostTask([this, width, height, weak_view_alive]() {
35 auto const view_alive = weak_view_alive.lock();
36 if (!view_alive) {
37 return;
38 }
40 return;
41 }
43 return;
44 }
47
49 });
50}
51
52void HostWindowSized::ApplyContentSize(int32_t physical_width,
53 int32_t physical_height) {
54 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
55 GetWindowInfo(window_handle_, &window_info);
56
57 // Convert physical pixels to logical pixels.
59 double const scale = static_cast<double>(dpi > 0 ? dpi : 96) / 96.0;
60 std::optional<Size> const window_size = GetWindowSizeForClientSize(
62 Size(physical_width / scale, physical_height / scale),
64 window_info.dwStyle, window_info.dwExStyle, nullptr);
65
66 if (!window_size) {
67 return;
68 }
69
70 SetWindowPos(window_handle_, NULL, 0, 0, window_size->width(),
71 window_size->height(),
72 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
73
74 if (resizable_) {
75 // For resizable windows, stop tracking content size after the initial
76 // frame so subsequent user-initiated resizes are forwarded to Flutter.
77 view_controller_->view()->SetSizedToContent(false);
78 }
79}
80
81WindowRect HostWindowSized::GetWorkArea() const {
82 constexpr int32_t kDefaultWorkAreaSize = 10000;
83 WindowRect work_area = {0, 0, kDefaultWorkAreaSize, kDefaultWorkAreaSize};
84 HMONITOR const monitor =
85 MonitorFromWindow(window_handle_, MONITOR_DEFAULTTONEAREST);
86 if (monitor) {
87 MONITORINFO monitor_info = {};
88 monitor_info.cbSize = sizeof(monitor_info);
89 if (GetMonitorInfo(monitor, &monitor_info)) {
90 work_area.left = monitor_info.rcWork.left;
91 work_area.top = monitor_info.rcWork.top;
92 work_area.width = monitor_info.rcWork.right - monitor_info.rcWork.left;
93 work_area.height = monitor_info.rcWork.bottom - monitor_info.rcWork.top;
94 }
95 }
96 return work_area;
97}
98
99} // namespace flutter
Size smallest() const
Definition geometry.h:94
Size biggest() const
Definition geometry.h:93
std::shared_ptr< WindowsProcTable > windows_proc_table()
BoxConstraints box_constraints_
std::unique_ptr< FlutterWindowsViewController > view_controller_
FlutterWindowsEngine * engine_
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)
std::shared_ptr< int > view_alive_
HostWindowSized(WindowManager *window_manager, FlutterWindowsEngine *engine, bool resizable)
virtual void ApplyContentSize(int32_t physical_width, int32_t physical_height)
void PostTask(TaskClosure task)
FlutterEngine engine
Definition main.cc:84
#define FML_DCHECK(condition)
Definition logging.h:122
UINT GetDpiForHWND(HWND hwnd)
Definition dpi_utils.cc:128
Definition ref_ptr.h:261
int32_t height
int32_t width
unsigned int UINT