From 47c4c6455b2d2646b660df31710e47e3e024dbd6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 16 Mar 2022 10:45:44 +0100 Subject: [PATCH] fix: ensure bounds changes apply when moving windows --- shell/browser/native_window_views.cc | 7 +++++++ shell/browser/native_window_views.h | 3 +++ shell/browser/native_window_views_win.cc | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index a5c58964016c3..4258bce662937 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -699,6 +699,13 @@ bool NativeWindowViews::IsFullscreen() const { } void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) { +#if BUILDFLAG(IS_WIN) + if (is_moving_ || is_resizing_) { + pending_bounds_change_ = bounds; + return; + } +#endif + #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_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 db178209ad6a5..cb3a344efdef3 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -8,6 +8,7 @@ #include "shell/browser/native_window.h" #include +#include #include #include #include @@ -303,6 +304,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 01d88048af794..12ae336acc2f3 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -314,6 +314,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: {