fix: ensure bounds stability in OnWidgetBoundsChanged
(#43644)
fix: ensure bounds stability in OnWidgetBoundsChanged
This commit is contained in:
parent
f74c353abf
commit
01ef05580f
1 changed files with 12 additions and 3 deletions
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "base/containers/contains.h"
|
#include "base/containers/contains.h"
|
||||||
#include "base/memory/raw_ptr.h"
|
#include "base/memory/raw_ptr.h"
|
||||||
|
#include "base/numerics/ranges.h"
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
@ -1644,10 +1645,18 @@ void NativeWindowViews::OnWidgetBoundsChanged(views::Widget* changed_widget,
|
||||||
if (changed_widget != widget())
|
if (changed_widget != widget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Note: We intentionally use `GetBounds()` instead of `bounds` to properly
|
// |GetWindowBoundsInScreen| has a ~1 pixel margin of error, so if we check
|
||||||
// handle minimized windows on Windows.
|
// 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();
|
const auto new_bounds = GetBounds();
|
||||||
if (widget_size_ != new_bounds.size()) {
|
if (!areWithinOnePixel(widget_size_, new_bounds.size())) {
|
||||||
NotifyWindowResize();
|
NotifyWindowResize();
|
||||||
widget_size_ = new_bounds.size();
|
widget_size_ = new_bounds.size();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue