Skip to content

Commit

Permalink
Fix popup bounds recompute on monitor scale change.
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Dec 7, 2021
1 parent 8f6c1fc commit 2c8caa4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions browser/ui/views/brave_ads/ad_notification_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions browser/ui/views/brave_ads/ad_notification_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2c8caa4

Please sign in to comment.