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
9
10namespace flutter {
11
14 bool resizable)
15 : HostWindow(window_manager, engine),
16 resizable_(resizable),
17 view_alive_(std::make_shared<int>(0)) {}
18
19void HostWindowSized::DidUpdateViewSize(int32_t width, int32_t height) {
20 // This is called from the raster thread.
21 std::weak_ptr<int> weak_view_alive = view_alive_;
22 engine_->task_runner()->PostTask([this, width, height, weak_view_alive]() {
23 auto const view_alive = weak_view_alive.lock();
24 if (!view_alive) {
25 return;
26 }
28 return;
29 }
31 return;
32 }
35
36 WINDOWINFO window_info = {.cbSize = sizeof(WINDOWINFO)};
37 GetWindowInfo(window_handle_, &window_info);
38
39 // Convert physical pixels to logical pixels.
41 double const scale = static_cast<double>(dpi > 0 ? dpi : 96) / 96.0;
42 std::optional<Size> const window_size = GetWindowSizeForClientSize(
43 *engine_->windows_proc_table(), Size(width / scale, height / scale),
45 window_info.dwStyle, window_info.dwExStyle, nullptr);
46
47 if (!window_size) {
48 return;
49 }
50
51 SetWindowPos(window_handle_, NULL, 0, 0, window_size->width(),
52 window_size->height(),
53 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
54
55 if (resizable_) {
56 // For resizable windows, stop tracking content size after the initial
57 // frame so subsequent user-initiated resizes are forwarded to Flutter.
58 view_controller_->view()->SetSizedToContent(false);
59 }
60 });
61}
62
63WindowRect HostWindowSized::GetWorkArea() const {
64 constexpr int32_t kDefaultWorkAreaSize = 10000;
65 WindowRect work_area = {0, 0, kDefaultWorkAreaSize, kDefaultWorkAreaSize};
66 HMONITOR const monitor =
67 MonitorFromWindow(window_handle_, MONITOR_DEFAULTTONEAREST);
68 if (monitor) {
69 MONITORINFO monitor_info = {};
70 monitor_info.cbSize = sizeof(monitor_info);
71 if (GetMonitorInfo(monitor, &monitor_info)) {
72 work_area.left = monitor_info.rcWork.left;
73 work_area.top = monitor_info.rcWork.top;
74 work_area.width = monitor_info.rcWork.right - monitor_info.rcWork.left;
75 work_area.height = monitor_info.rcWork.bottom - monitor_info.rcWork.top;
76 }
77 }
78 return work_area;
79}
80
81} // 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)
void PostTask(TaskClosure task)
FlutterEngine engine
Definition main.cc:84
UINT GetDpiForHWND(HWND hwnd)
Definition dpi_utils.cc:128
TSize< Scalar > Size
Definition size.h:159
Definition ref_ptr.h:261
int32_t height
int32_t width
unsigned int UINT