From 2c8caa4b787de12efc0aa3ff477824d8c4003779 Mon Sep 17 00:00:00 2001 From: Aleksey Seren Date: Tue, 7 Dec 2021 13:48:25 +0700 Subject: [PATCH] Fix popup bounds recompute on monitor scale change. fix https://github.com/brave/brave-browser/issues/19210 --- .../ui/views/brave_ads/ad_notification_popup.cc | 14 +++++++++++--- browser/ui/views/brave_ads/ad_notification_popup.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/browser/ui/views/brave_ads/ad_notification_popup.cc b/browser/ui/views/brave_ads/ad_notification_popup.cc index da27eb53338b..f9770c8bc782 100644 --- a/browser/ui/views/brave_ads/ad_notification_popup.cc +++ b/browser/ui/views/brave_ads/ad_notification_popup.cc @@ -333,12 +333,17 @@ void AdNotificationPopup::SaveOrigin(const gfx::Point& origin) const { origin.y()); } -gfx::Rect AdNotificationPopup::CalculateBounds() { +gfx::Size AdNotificationPopup::CalculateViewSize() const { DCHECK(ad_notification_view_); gfx::Size size = ad_notification_view_->size(); DCHECK(!size.IsEmpty()); size += gfx::Size(-GetShadowMargin().width(), -GetShadowMargin().height()); + return size; +} + +gfx::Rect AdNotificationPopup::CalculateBounds() { + const gfx::Size size = CalculateViewSize(); const gfx::Point origin = GetOriginForSize(size); return gfx::Rect(origin, size); } @@ -348,8 +353,11 @@ void AdNotificationPopup::RecomputeAlignment() { return; } - const gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); - AdjustBoundsAndSnapToFitWorkAreaForWidget(GetWidget(), bounds); + const gfx::Point window_origin = + GetWidget()->GetWindowBoundsInScreen().origin(); + const gfx::Size view_size = CalculateViewSize(); + AdjustBoundsAndSnapToFitWorkAreaForWidget( + GetWidget(), gfx::Rect(window_origin, view_size)); } const gfx::ShadowDetails& AdNotificationPopup::GetShadowDetails() const { diff --git a/browser/ui/views/brave_ads/ad_notification_popup.h b/browser/ui/views/brave_ads/ad_notification_popup.h index 85b269a470af..bbdc3ae90ff4 100644 --- a/browser/ui/views/brave_ads/ad_notification_popup.h +++ b/browser/ui/views/brave_ads/ad_notification_popup.h @@ -101,6 +101,7 @@ class AdNotificationPopup : public views::WidgetDelegateView, gfx::Point GetOriginForSize(const gfx::Size& size); void SaveOrigin(const gfx::Point& origin) const; + gfx::Size CalculateViewSize() const; gfx::Rect CalculateBounds(); void RecomputeAlignment();