Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed follow up of #14813 - The size of the custom ad notification popup is enlarged after reposition - 1.27.x #9235

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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