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

Made custom ads popup respects light/dark mode on linux. #9337

Merged
merged 1 commit into from
Jul 7, 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
4 changes: 3 additions & 1 deletion browser/ui/brave_ads/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ source_set("brave_ads") {
"//brave/app:brave_generated_resources_grit",
"//brave/app/vector_icons",
"//brave/browser/profiles:util",
"//brave/browser/themes",
"//brave/components/brave_ads/browser",
"//brave/components/brave_ads/common",
"//components/prefs",
Expand All @@ -30,7 +31,6 @@ source_set("brave_ads") {
"//ui/compositor",
"//ui/display",
"//ui/gfx",
"//ui/native_theme",
"//ui/views",
]

Expand Down Expand Up @@ -67,6 +67,8 @@ source_set("brave_ads") {
"spacer_view.h",
"text_ad_notification_view.cc",
"text_ad_notification_view.h",
"window_util.cc",
"window_util.h",
]

if (is_mac) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#include "brave/browser/ui/brave_ads/ad_notification_view.h"
#include "brave/browser/ui/brave_ads/padded_image_button.h"
#include "brave/browser/ui/brave_ads/padded_image_view.h"
#include "brave/browser/ui/brave_ads/window_util.h"
#include "brave/grit/brave_generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h"
#include "ui/views/layout/box_layout.h"

Expand Down Expand Up @@ -82,7 +82,7 @@ void AdNotificationControlButtonsView::CreateInfoButton() {
}

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

const gfx::ImageSkia image_skia = gfx::CreateVectorIcon(
should_use_dark_colors ? kBraveAdsDarkModeInfoButtonIcon
Expand All @@ -106,7 +106,7 @@ void AdNotificationControlButtonsView::CreateCloseButton() {
void AdNotificationControlButtonsView::UpdateCloseButton() {
DCHECK(close_button_);

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

const gfx::ImageSkia image_skia = gfx::CreateVectorIcon(
kBraveAdsCloseButtonIcon, kCloseButtonIconDipSize,
Expand Down
6 changes: 3 additions & 3 deletions browser/ui/brave_ads/ad_notification_header_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/strings/utf_string_conversions.h"
#include "brave/browser/ui/brave_ads/insets_util.h"
#include "brave/browser/ui/brave_ads/spacer_view.h"
#include "brave/browser/ui/brave_ads/window_util.h"
#include "brave/grit/brave_generated_resources.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
Expand All @@ -19,7 +20,6 @@
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout.h"
Expand Down Expand Up @@ -126,7 +126,7 @@ void AdNotificationHeaderView::CreateView(const int width) {
}

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

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

Expand Down Expand Up @@ -159,7 +159,7 @@ views::Label* AdNotificationHeaderView::CreateTitleLabel() {
}

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

DCHECK(title_label_);
title_label_->SetEnabledColor(should_use_dark_colors ? kDarkModeTitleColor
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/brave_ads/ad_notification_popup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "brave/browser/ui/brave_ads/ad_notification_view.h"
#include "brave/browser/ui/brave_ads/ad_notification_view_factory.h"
#include "brave/browser/ui/brave_ads/bounds_util.h"
#include "brave/browser/ui/brave_ads/window_util.h"
#include "brave/components/brave_ads/browser/features.h"
#include "brave/components/brave_ads/common/pref_names.h"
#include "brave/grit/brave_generated_resources.h"
Expand All @@ -36,7 +37,6 @@
#include "ui/gfx/shadow_util.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/skia_paint_util.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"

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

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

// Draw border with drop shadow
cc::PaintFlags border_flags;
Expand Down
1 change: 0 additions & 1 deletion browser/ui/brave_ads/ad_notification_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ui/compositor/layer.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/view.h"

namespace brave_ads {
Expand Down
6 changes: 3 additions & 3 deletions browser/ui/brave_ads/text_ad_notification_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
#include "brave/browser/ui/brave_ads/ad_notification_control_buttons_view.h"
#include "brave/browser/ui/brave_ads/ad_notification_header_view.h"
#include "brave/browser/ui/brave_ads/insets_util.h"
#include "brave/browser/ui/brave_ads/window_util.h"
#include "build/build_config.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/text_constants.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
Expand Down Expand Up @@ -155,7 +155,7 @@ views::View* TextAdNotificationView::CreateBodyView(

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

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

Expand Down Expand Up @@ -194,7 +194,7 @@ views::Label* TextAdNotificationView::CreateBodyLabel(
}

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

DCHECK(body_label_);
body_label_->SetEnabledColor(should_use_dark_colors ? kDarkModeBodyColor
Expand Down
17 changes: 17 additions & 0 deletions browser/ui/brave_ads/window_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/brave_ads/window_util.h"

#include "brave/browser/themes/brave_dark_mode_utils.h"

namespace brave_ads {

bool ShouldUseDarkModeTheme() {
return dark_mode::GetActiveBraveDarkModeType() ==
dark_mode::BraveDarkModeType::BRAVE_DARK_MODE_TYPE_DARK;
}

} // namespace brave_ads
15 changes: 15 additions & 0 deletions browser/ui/brave_ads/window_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_
#define BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_

namespace brave_ads {

bool ShouldUseDarkModeTheme();

} // namespace brave_ads

#endif // BRAVE_BROWSER_UI_BRAVE_ADS_WINDOW_UTIL_H_