Skip to content

Commit

Permalink
Merge pull request #9235 from /issues/16241-1.27.x
Browse files Browse the repository at this point in the history
Fixed follow up of #14813 - The size of the custom ad notification popup is enlarged after reposition - 1.27.x
  • Loading branch information
kjozwiak authored Jun 25, 2021
2 parents 43cc065 + 525e3b5 commit f920d27
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
14 changes: 12 additions & 2 deletions browser/ui/brave_ads/ad_notification_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ void AdNotificationPopup::OnClick(const std::string& notification_id) {
popup->FadeOut();
}

// static
gfx::Rect AdNotificationPopup::GetBounds(const std::string& notification_id) {
DCHECK(!notification_id.empty());

DCHECK(g_ad_notification_popups[notification_id]);
AdNotificationPopup* popup = g_ad_notification_popups[notification_id];
DCHECK(popup);

return popup->CalculateBounds();
}

void AdNotificationPopup::OnDisplayRemoved(
const display::Display& old_display) {
// Called when |old_display| has been removed
Expand Down Expand Up @@ -197,7 +208,7 @@ void AdNotificationPopup::OnWorkAreaChanged() {
void AdNotificationPopup::OnPaintBackground(gfx::Canvas* canvas) {
DCHECK(canvas);

gfx::RectF bounds(GetWidget()->GetLayer()->bounds());
gfx::Rect bounds(GetWidget()->GetLayer()->bounds());
bounds.Inset(-GetShadowMargin());

const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
Expand Down Expand Up @@ -391,7 +402,6 @@ void AdNotificationPopup::RecomputeAlignment() {
gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen();
const gfx::NativeView native_view = GetWidget()->GetNativeView();
AdjustBoundsToFitWorkAreaForNativeView(&bounds, native_view);

GetWidget()->SetBounds(bounds);
}

Expand Down
3 changes: 3 additions & 0 deletions browser/ui/brave_ads/ad_notification_popup.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class AdNotificationPopup : public views::WidgetDelegateView,
// User clicked the notification popup view for the given |notification_id|
static void OnClick(const std::string& notification_id);

// Return the bounds for the given |notification_id|
static gfx::Rect GetBounds(const std::string& notification_id);

// display::DisplayObserver:
void OnDisplayRemoved(const display::Display& old_display) override;
void OnDisplayMetricsChanged(const display::Display& display,
Expand Down
11 changes: 9 additions & 2 deletions browser/ui/brave_ads/ad_notification_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ bool AdNotificationView::OnMouseDragged(const ui::MouseEvent& event) {
return false;
}

gfx::Rect bounds =
GetWidget()->GetContentsView()->GetBoundsInScreen() + movement;
const std::string id = ad_notification_.id();
gfx::Rect bounds = AdNotificationPopup::GetBounds(id) + movement;
const gfx::NativeView native_view = GetWidget()->GetNativeView();
AdjustBoundsToFitWorkAreaForNativeView(&bounds, native_view);
GetWidget()->SetBounds(bounds);
Expand All @@ -103,6 +103,13 @@ void AdNotificationView::OnMouseReleased(const ui::MouseEvent& event) {
View::OnMouseReleased(event);
}

void AdNotificationView::OnDeviceScaleFactorChanged(
float old_device_scale_factor,
float new_device_scale_factor) {
GetWidget()->DeviceScaleFactorChanged(old_device_scale_factor,
new_device_scale_factor);
}

void AdNotificationView::OnThemeChanged() {
views::View::OnThemeChanged();

Expand Down
2 changes: 2 additions & 0 deletions browser/ui/brave_ads/ad_notification_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class AdNotificationView : public views::InkDropHostView {
bool OnMousePressed(const ui::MouseEvent& event) override;
bool OnMouseDragged(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
void OnDeviceScaleFactorChanged(float old_device_scale_factor,
float new_device_scale_factor) override;
void OnThemeChanged() override;

private:
Expand Down

0 comments on commit f920d27

Please sign in to comment.