Skip to content

Commit dc5ade6

Browse files
authored
Merge pull request #9337 from brave/custom_ads_dark_theme
Made custom ads popup respects light/dark mode on linux.
2 parents c74fae5 + 4d6648e commit dc5ade6

8 files changed

+46
-13
lines changed

browser/ui/brave_ads/BUILD.gn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ source_set("brave_ads") {
2121
"//brave/app:brave_generated_resources_grit",
2222
"//brave/app/vector_icons",
2323
"//brave/browser/profiles:util",
24+
"//brave/browser/themes",
2425
"//brave/components/brave_ads/browser",
2526
"//brave/components/brave_ads/common",
2627
"//components/prefs",
@@ -30,7 +31,6 @@ source_set("brave_ads") {
3031
"//ui/compositor",
3132
"//ui/display",
3233
"//ui/gfx",
33-
"//ui/native_theme",
3434
"//ui/views",
3535
]
3636

@@ -67,6 +67,8 @@ source_set("brave_ads") {
6767
"spacer_view.h",
6868
"text_ad_notification_view.cc",
6969
"text_ad_notification_view.h",
70+
"window_util.cc",
71+
"window_util.h",
7072
]
7173

7274
if (is_mac) {

browser/ui/brave_ads/ad_notification_control_buttons_view.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
#include "brave/browser/ui/brave_ads/ad_notification_view.h"
1313
#include "brave/browser/ui/brave_ads/padded_image_button.h"
1414
#include "brave/browser/ui/brave_ads/padded_image_view.h"
15+
#include "brave/browser/ui/brave_ads/window_util.h"
1516
#include "brave/grit/brave_generated_resources.h"
1617
#include "ui/base/l10n/l10n_util.h"
1718
#include "ui/base/metadata/metadata_impl_macros.h"
1819
#include "ui/compositor/layer.h"
1920
#include "ui/gfx/color_palette.h"
2021
#include "ui/gfx/paint_vector_icon.h"
21-
#include "ui/native_theme/native_theme.h"
2222
#include "ui/views/background.h"
2323
#include "ui/views/layout/box_layout.h"
2424

@@ -82,7 +82,7 @@ void AdNotificationControlButtonsView::CreateInfoButton() {
8282
}
8383

8484
void AdNotificationControlButtonsView::UpdateInfoButton() {
85-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
85+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
8686

8787
const gfx::ImageSkia image_skia = gfx::CreateVectorIcon(
8888
should_use_dark_colors ? kBraveAdsDarkModeInfoButtonIcon
@@ -106,7 +106,7 @@ void AdNotificationControlButtonsView::CreateCloseButton() {
106106
void AdNotificationControlButtonsView::UpdateCloseButton() {
107107
DCHECK(close_button_);
108108

109-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
109+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
110110

111111
const gfx::ImageSkia image_skia = gfx::CreateVectorIcon(
112112
kBraveAdsCloseButtonIcon, kCloseButtonIconDipSize,

browser/ui/brave_ads/ad_notification_header_view.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "base/strings/utf_string_conversions.h"
1111
#include "brave/browser/ui/brave_ads/insets_util.h"
1212
#include "brave/browser/ui/brave_ads/spacer_view.h"
13+
#include "brave/browser/ui/brave_ads/window_util.h"
1314
#include "brave/grit/brave_generated_resources.h"
1415
#include "ui/accessibility/ax_enums.mojom.h"
1516
#include "ui/accessibility/ax_node_data.h"
@@ -19,7 +20,6 @@
1920
#include "ui/gfx/font_list.h"
2021
#include "ui/gfx/geometry/insets.h"
2122
#include "ui/gfx/geometry/size.h"
22-
#include "ui/native_theme/native_theme.h"
2323
#include "ui/views/border.h"
2424
#include "ui/views/controls/label.h"
2525
#include "ui/views/layout/flex_layout.h"
@@ -126,7 +126,7 @@ void AdNotificationHeaderView::CreateView(const int width) {
126126
}
127127

128128
views::Label* AdNotificationHeaderView::CreateTitleLabel() {
129-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
129+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
130130

131131
views::Label* label = new views::Label();
132132

@@ -159,7 +159,7 @@ views::Label* AdNotificationHeaderView::CreateTitleLabel() {
159159
}
160160

161161
void AdNotificationHeaderView::UpdateTitleLabel() {
162-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
162+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
163163

164164
DCHECK(title_label_);
165165
title_label_->SetEnabledColor(should_use_dark_colors ? kDarkModeTitleColor

browser/ui/brave_ads/ad_notification_popup.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "brave/browser/ui/brave_ads/ad_notification_view.h"
1414
#include "brave/browser/ui/brave_ads/ad_notification_view_factory.h"
1515
#include "brave/browser/ui/brave_ads/bounds_util.h"
16+
#include "brave/browser/ui/brave_ads/window_util.h"
1617
#include "brave/components/brave_ads/browser/features.h"
1718
#include "brave/components/brave_ads/common/pref_names.h"
1819
#include "brave/grit/brave_generated_resources.h"
@@ -36,7 +37,6 @@
3637
#include "ui/gfx/shadow_util.h"
3738
#include "ui/gfx/shadow_value.h"
3839
#include "ui/gfx/skia_paint_util.h"
39-
#include "ui/native_theme/native_theme.h"
4040
#include "ui/views/layout/box_layout.h"
4141
#include "ui/views/widget/widget.h"
4242

@@ -212,7 +212,7 @@ void AdNotificationPopup::OnPaintBackground(gfx::Canvas* canvas) {
212212
gfx::Rect bounds(GetWidget()->GetLayer()->bounds());
213213
bounds.Inset(-GetShadowMargin());
214214

215-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
215+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
216216

217217
// Draw border with drop shadow
218218
cc::PaintFlags border_flags;

browser/ui/brave_ads/ad_notification_view.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "ui/compositor/layer.h"
1818
#include "ui/gfx/geometry/rect.h"
1919
#include "ui/gfx/geometry/vector2d.h"
20-
#include "ui/native_theme/native_theme.h"
2120
#include "ui/views/view.h"
2221

2322
namespace brave_ads {

browser/ui/brave_ads/text_ad_notification_view.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include "brave/browser/ui/brave_ads/ad_notification_control_buttons_view.h"
1313
#include "brave/browser/ui/brave_ads/ad_notification_header_view.h"
1414
#include "brave/browser/ui/brave_ads/insets_util.h"
15+
#include "brave/browser/ui/brave_ads/window_util.h"
1516
#include "build/build_config.h"
1617
#include "ui/gfx/color_palette.h"
1718
#include "ui/gfx/font.h"
1819
#include "ui/gfx/font_list.h"
1920
#include "ui/gfx/geometry/insets.h"
2021
#include "ui/gfx/geometry/size.h"
2122
#include "ui/gfx/text_constants.h"
22-
#include "ui/native_theme/native_theme.h"
2323
#include "ui/views/border.h"
2424
#include "ui/views/controls/label.h"
2525
#include "ui/views/layout/box_layout.h"
@@ -155,7 +155,7 @@ views::View* TextAdNotificationView::CreateBodyView(
155155

156156
views::Label* TextAdNotificationView::CreateBodyLabel(
157157
const AdNotification& ad_notification) {
158-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
158+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
159159

160160
const std::u16string body = ad_notification.body();
161161

@@ -194,7 +194,7 @@ views::Label* TextAdNotificationView::CreateBodyLabel(
194194
}
195195

196196
void TextAdNotificationView::UpdateBodyLabel() {
197-
const bool should_use_dark_colors = GetNativeTheme()->ShouldUseDarkColors();
197+
const bool should_use_dark_colors = ShouldUseDarkModeTheme();
198198

199199
DCHECK(body_label_);
200200
body_label_->SetEnabledColor(should_use_dark_colors ? kDarkModeBodyColor

browser/ui/brave_ads/window_util.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/browser/ui/brave_ads/window_util.h"
7+
8+
#include "brave/browser/themes/brave_dark_mode_utils.h"
9+
10+
namespace brave_ads {
11+
12+
bool ShouldUseDarkModeTheme() {
13+
return dark_mode::GetActiveBraveDarkModeType() ==
14+
dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK;
15+
}
16+
17+
} // namespace brave_ads

browser/ui/brave_ads/window_util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#ifndef BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_
7+
#define BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_
8+
9+
namespace brave_ads {
10+
11+
bool ShouldUseDarkModeTheme();
12+
13+
} // namespace brave_ads
14+
15+
#endif // BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_

0 commit comments

Comments
 (0)