From 26d6f62c019835962d99952a22ef33660bc551e4 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:31:48 -0500 Subject: [PATCH] fix: ensure bounds stability in `OnWidgetBoundsChanged` (#43457) * fix: ensure bounds stability in OnWidgetBoundsChanged Co-authored-by: Shelley Vohr * Update shell/browser/native_window_views.cc Co-authored-by: Charles Kerr Co-authored-by: Shelley Vohr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/browser/native_window_views.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 7f0e8dc5f5b..2e43d44d7b6 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -22,6 +22,7 @@ #include "base/containers/contains.h" #include "base/memory/raw_ref.h" +#include "base/numerics/ranges.h" #include "base/strings/utf_string_conversions.h" #include "content/public/browser/desktop_media_id.h" #include "content/public/common/color_parser.h" @@ -1637,10 +1638,18 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget, if (changed_widget != widget()) return; - // Note: We intentionally use `GetBounds()` instead of `bounds` to properly - // handle minimized windows on Windows. + // |GetWindowBoundsInScreen| has a ~1 pixel margin of error, so if we check + // existing bounds directly against the new bounds without accounting for that + // we'll have constant false positives when the window is moving but the user + // hasn't changed its size at all. + auto areWithinOnePixel = [](gfx::Size old_size, gfx::Size new_size) -> bool { + return base::IsApproximatelyEqual(old_size.width(), new_size.width(), 1) && + base::IsApproximatelyEqual(old_size.height(), new_size.height(), 1); + }; + + // We use |GetBounds| to account for minimized windows on Windows. const auto new_bounds = GetBounds(); - if (widget_size_ != new_bounds.size()) { + if (!areWithinOnePixel(widget_size_, new_bounds.size())) { NotifyWindowResize(); widget_size_ = new_bounds.size(); }