From 16e49b55746a7701d664ec8a5ed2258244d954b3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 22 Mar 2022 07:07:09 +0100 Subject: [PATCH] fix: pend bounds change when moving BrowserWindows * fix: ensure bounds changes apply when moving windows * chore: remove unused queue include --- shell/browser/native_window_views.cc | 7 +++++++ shell/browser/native_window_views.h | 2 ++ shell/browser/native_window_views_win.cc | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 6e3dd91b23ed6..3fb461e5b9578 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -714,6 +714,13 @@ bool NativeWindowViews::IsFullscreen() const { } void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { +#if defined(OS_WIN) + if (is_moving_ || is_resizing_) { + pending_bounds_change_ = bounds; + return; + } +#endif + #if defined(OS_WIN) || defined(OS_LINUX) // On Linux and Windows the minimum and maximum size should be updated with // window size when window is not resizable. diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 1be0da6dcbf74..4f7c1e50e8253 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -310,6 +310,8 @@ class NativeWindowViews : public NativeWindow, // Whether the window is currently being moved. bool is_moving_ = false; + absl::optional pending_bounds_change_; + // The color to use as the theme and symbol colors respectively for Window // Controls Overlay if enabled on Windows. SkColor overlay_button_color_; diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index d792da40fa709..f1af57ccc3d4a 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -312,6 +312,15 @@ bool NativeWindowViews::PreHandleMSG(UINT message, NotifyWindowMoved(); is_moving_ = false; } + + // If the user dragged or moved the window during one or more + // calls to window.setBounds(), we want to apply the most recent + // one once they are done with the move or resize operation. + if (pending_bounds_change_.has_value()) { + SetBounds(pending_bounds_change_.value(), false /* animate */); + pending_bounds_change_.reset(); + } + return false; } case WM_MOVING: {