10 #include "flutter/fml/logging.h"
18 DWORD HostWindowSatellite::GetWindowStyleForSatellite(
bool resizable) {
21 DWORD window_style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU;
23 window_style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
32 const BoxConstraints& constraints,
36 bool sized_to_content,
39 get_position_callback_(get_position_callback),
46 .window_style = GetWindowStyleForSatellite(resizable),
47 .extended_window_style = 0,
48 .box_constraints = constraints,
49 .initial_window_rect =
50 GetInitialRect(engine, preferred_size, constraints, parent,
51 sized_to_content, resizable),
52 .title = title ? title : L
"",
53 .owner_window = parent,
55 .is_sized_to_content = sized_to_content,
69 Rect HostWindowSatellite::GetInitialRect(
72 const BoxConstraints& constraints,
74 bool sized_to_content,
77 engine, preferred_size, constraints,
78 GetWindowStyleForSatellite(resizable), 0,
79 parent, sized_to_content);
83 return {{CW_USEDEFAULT, CW_USEDEFAULT},
84 window_size ? *window_size : Size{CW_USEDEFAULT, CW_USEDEFAULT}};
87 WindowRect HostWindowSatellite::GetWorkArea()
const {
91 std::optional<WindowRect> HostWindowSatellite::ComputePosition(
92 const WindowSize& window_size)
const {
93 if (!get_position_callback_) {
97 RECT parent_client_rect;
98 GetClientRect(parent_, &parent_client_rect);
101 POINT parent_top_left = {parent_client_rect.left, parent_client_rect.top};
102 POINT parent_bottom_right = {parent_client_rect.right,
103 parent_client_rect.bottom};
104 ClientToScreen(parent_, &parent_top_left);
105 ClientToScreen(parent_, &parent_bottom_right);
107 IsolateScope scope(isolate_);
109 WindowRect rect = {};
110 get_position_callback_(window_size,
111 WindowRect{parent_top_left.x, parent_top_left.y,
112 parent_bottom_right.x - parent_top_left.x,
113 parent_bottom_right.y - parent_top_left.y},
118 void HostWindowSatellite::ApplyInitialPosition() {
119 if (initial_position_applied_) {
127 WindowSize
const window_size = {window_rect.right - window_rect.left,
128 window_rect.bottom - window_rect.top};
130 std::optional<WindowRect>
const rect = ComputePosition(window_size);
135 SetWindowPos(
window_handle_,
nullptr, rect->left, rect->top, rect->width,
136 rect->height, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
138 initial_position_applied_ =
true;
142 if (rect->width != window_size.width || rect->height != window_size.height) {
151 ApplyInitialPosition();
155 int32_t physical_height) {
163 ApplyInitialPosition();
166 std::optional<POINT> HostWindowSatellite::GetParentClientOrigin()
const {
168 if (IsIconic(parent_)) {
172 POINT origin = {0, 0};
173 if (!ClientToScreen(parent_, &origin)) {
180 double HostWindowSatellite::GetParentScaleFactor()
const {
184 void HostWindowSatellite::UpdateParentOffset() {
185 std::optional<POINT>
const parent_origin = GetParentClientOrigin();
187 if (!parent_origin || !GetWindowRect(
window_handle_, &window_rect)) {
191 double const scale_factor = GetParentScaleFactor();
192 parent_offset_x_ = (window_rect.left - parent_origin->x) / scale_factor;
193 parent_offset_y_ = (window_rect.top - parent_origin->y) / scale_factor;
197 bool const was_following_parent = std::exchange(is_following_parent_,
true);
202 for (
int pass = 0; pass < 2; ++pass) {
203 std::optional<POINT>
const parent_origin = GetParentClientOrigin();
205 if (!parent_origin || !GetWindowRect(
window_handle_, &window_rect)) {
209 double const scale_factor = GetParentScaleFactor();
210 LONG
const target_x =
211 parent_origin->x + std::lround(parent_offset_x_ * scale_factor);
212 LONG
const target_y =
213 parent_origin->y + std::lround(parent_offset_y_ * scale_factor);
214 if (target_x == window_rect.left && target_y == window_rect.top) {
219 SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
222 is_following_parent_ = was_following_parent;
226 if (new_parent == parent_ || new_parent ==
nullptr) {
231 for (HWND ancestor = new_parent; ancestor !=
nullptr;
232 ancestor = GetWindow(ancestor, GW_OWNER)) {
234 FML_LOG(ERROR) <<
"Refusing to anchor a satellite window to itself or to "
235 "one of its own satellites.";
240 parent_ = new_parent;
244 reinterpret_cast<LONG_PTR
>(new_parent));
246 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE |
251 UpdateParentOffset();
261 if ((wparam & 0xFFF0) == SC_MINIMIZE) {
266 case WM_ENTERSIZEMOVE:
267 is_in_move_size_loop_ =
true;
270 case WM_EXITSIZEMOVE:
271 is_in_move_size_loop_ =
false;
274 case WM_DPICHANGED: {
278 if (is_in_move_size_loop_ || is_following_parent_) {
287 bool const was_following_parent =
288 std::exchange(is_following_parent_,
true);
289 LRESULT
const result =
291 is_following_parent_ = was_following_parent;
296 case WM_WINDOWPOSCHANGED: {
299 auto const*
const window_pos =
reinterpret_cast<WINDOWPOS*
>(lparam);
300 if (!is_following_parent_ && window_pos &&
301 !(window_pos->flags & SWP_NOMOVE)) {
302 UpdateParentOffset();
311 if (
auto const result =
WindowProcDelegateManager * window_proc_delegate_manager()
void InitializeFlutterView(HostWindowInitializationParams const ¶ms)
void HandleWindowActivation(HWND hwnd, WPARAM wparam)
std::unique_ptr< FlutterWindowsViewController > view_controller_
static std::optional< Size > GetInitialWindowSize(FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, DWORD window_style, DWORD extended_window_style, std::optional< HWND > const &owner_window, bool sized_to_content)
FlutterWindowsEngine * engine_
virtual LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
void OnFirstFrame() override
HostWindowSatellite(WindowManager *window_manager, FlutterWindowsEngine *engine, const WindowSizeRequest &preferred_size, const BoxConstraints &constraints, GetWindowPositionCallback get_position_callback, HWND parent, LPCWSTR title, bool sized_to_content, bool resizable)
LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) override
void ApplyContentSize(int32_t physical_width, int32_t physical_height) override
~HostWindowSatellite() override
void SetSatelliteParent(HWND new_parent)
static WindowRect GetWorkAreaForWindow(HWND hwnd)
FlutterWindowsViewSizingDelegate * AsSizingDelegate()
virtual void ApplyContentSize(int32_t physical_width, int32_t physical_height)
std::optional< LRESULT > OnTopLevelWindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) const
UINT GetDpiForHWND(HWND hwnd)
void(* GetWindowPositionCallback)(const WindowSize &child_size, const WindowRect &parent_rect, const WindowRect &display_rect, WindowRect &output_rect)
constexpr UINT kDefaultDpi
WindowArchetype archetype
bool has_preferred_view_size