Commit 4056f832 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Use native theme for notification background color

Notifications should use the proper background color so the text on them
is readable. This also derives the inline settings, actions row and
large image background colors from that native background color so light
and dark themes work correctly.

Screenshots: https://imgur.com/rxq48G7

Bug: 1113313,1065604
Change-Id: I20b833a3a157eabc0c7b03385a4ed88651cffa08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2396297Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811636}
parent e1098a5f
......@@ -249,7 +249,7 @@ ArcNotificationContentView::ArcNotificationContentView(
control_buttons_view_(message_view) {
DCHECK(message_view);
// kNotificationWidth must be 360, since this value is separately defiend in
// kNotificationWidth must be 360, since this value is separately defined in
// ArcNotificationWrapperView class in Android side.
DCHECK_EQ(360, message_center::kNotificationWidth);
......@@ -348,7 +348,7 @@ void ArcNotificationContentView::UpdateControlButtonsVisibility() {
return;
// Add the guard to prevent an infinite loop. Changing visibility may generate
// an event and it may call thie method again.
// an event and it may call this method again.
base::AutoReset<bool> reset(&updating_control_buttons_visibility_, true);
if (target_visibility)
......@@ -559,7 +559,8 @@ void ArcNotificationContentView::UpdateMask(bool force_update) {
auto mask_painter =
std::make_unique<message_center::NotificationBackgroundPainter>(
top_radius_, bottom_radius_);
top_radius_, bottom_radius_,
message_center::kNotificationBackgroundColor);
// Set insets to round visible notification corners. https://crbug.com/866777
mask_painter->set_insets(new_insets);
......
......@@ -41,6 +41,7 @@
#include "ui/aura/window.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/test/event_generator.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/views/message_view_factory.h"
#include "ui/message_center/views/notification_control_buttons_view.h"
......
......@@ -77,6 +77,8 @@ base::Optional<SkColor> SkColorFromColorId(
// Dialogs
case ui::NativeTheme::kColorId_DialogBackground:
case ui::NativeTheme::kColorId_BubbleBackground:
// Notifications
case ui::NativeTheme::kColorId_NotificationDefaultBackground:
return GetBgColor("");
case ui::NativeTheme::kColorId_DialogForeground:
case ui::NativeTheme::kColorId_BubbleForeground:
......
......@@ -173,9 +173,7 @@ void MessageView::SetManuallyExpandedOrCollapsed(bool value) {
void MessageView::UpdateCornerRadius(int top_radius, int bottom_radius) {
SetCornerRadius(top_radius, bottom_radius);
SetBackground(views::CreateBackgroundFromPainter(
std::make_unique<NotificationBackgroundPainter>(top_radius,
bottom_radius)));
UpdateBackgroundPainter();
SchedulePaint();
}
......@@ -251,7 +249,7 @@ bool MessageView::OnKeyPressed(const ui::KeyEvent& event) {
}
bool MessageView::OnKeyReleased(const ui::KeyEvent& event) {
// Space key handling is triggerred at key-release timing. See
// Space key handling is triggered at key-release timing. See
// ui/views/controls/buttons/button.cc for why.
if (event.flags() != ui::EF_NONE || event.key_code() != ui::VKEY_SPACE)
return false;
......@@ -327,6 +325,7 @@ void MessageView::AddedToWidget() {
void MessageView::OnThemeChanged() {
InkDropHostView::OnThemeChanged();
UpdateBackgroundPainter();
SetNestedBorderIfNecessary();
}
......@@ -472,6 +471,14 @@ void MessageView::SetNestedBorderIfNecessary() {
}
}
void MessageView::UpdateBackgroundPainter() {
SkColor background_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_NotificationDefaultBackground);
SetBackground(views::CreateBackgroundFromPainter(
std::make_unique<NotificationBackgroundPainter>(
top_radius_, bottom_radius_, background_color)));
}
void MessageView::UpdateControlButtonsVisibility() {
auto* control_buttons_view = GetControlButtonsView();
if (control_buttons_view)
......
......@@ -209,6 +209,9 @@ class MESSAGE_CENTER_EXPORT MessageView
// Sets the border if |is_nested_| is true.
void SetNestedBorderIfNecessary();
// Updates the background painter using the themed background color and radii.
void UpdateBackgroundPainter();
std::string notification_id_;
views::ScrollView* scroller_ = nullptr;
......
......@@ -6,7 +6,6 @@
#define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_BACKGROUND_PAINTER_H_
#include "ui/message_center/message_center_export.h"
#include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/views/painter.h"
namespace message_center {
......@@ -19,7 +18,7 @@ class MESSAGE_CENTER_EXPORT NotificationBackgroundPainter
public:
NotificationBackgroundPainter(int top_radius,
int bottom_radius,
SkColor color = kNotificationBackgroundColor);
SkColor color);
~NotificationBackgroundPainter() override;
// views::Painter
......
......@@ -70,6 +70,7 @@ base::Optional<SkColor> GetDarkSchemeColor(NativeTheme::ColorId color_id) {
case NativeTheme::kColorId_ButtonColor:
case NativeTheme::kColorId_DialogBackground:
case NativeTheme::kColorId_BubbleBackground:
case NativeTheme::kColorId_NotificationDefaultBackground:
return color_utils::AlphaBlend(SK_ColorWHITE, gfx::kGoogleGrey900, 0.04f);
case NativeTheme::kColorId_DialogForeground:
return gfx::kGoogleGrey500;
......@@ -246,6 +247,7 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
case NativeTheme::kColorId_ButtonColor:
case NativeTheme::kColorId_DialogBackground:
case NativeTheme::kColorId_BubbleBackground:
case NativeTheme::kColorId_NotificationDefaultBackground:
return SK_ColorWHITE;
case NativeTheme::kColorId_DialogForeground:
return gfx::kGoogleGrey700;
......@@ -422,15 +424,21 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
return gfx::kGoogleBlue600;
// Notification view
// TODO(crbug.com/1065604): Add support for dark mode.
case NativeTheme::kColorId_NotificationDefaultBackground:
case NativeTheme::kColorId_NotificationPlaceholderIconColor:
return SK_ColorWHITE;
case NativeTheme::kColorId_NotificationActionsRowBackground:
case NativeTheme::kColorId_NotificationInlineSettingsBackground:
return SkColorSetRGB(0xee, 0xee, 0xee);
case NativeTheme::kColorId_NotificationLargeImageBackground:
return SkColorSetRGB(0xf5, 0xf5, 0xf5);
case NativeTheme::kColorId_NotificationInlineSettingsBackground: {
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_NotificationDefaultBackground, color_scheme);
// The alpha value here (0x14) is chosen to generate 0xEEE from 0xFFF.
return color_utils::BlendTowardMaxContrast(bg, 0x14);
}
case NativeTheme::kColorId_NotificationLargeImageBackground: {
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_NotificationDefaultBackground, color_scheme);
// The alpha value here (0x0C) is chosen to generate 0xF5F5F5 from 0xFFF.
return color_utils::BlendTowardMaxContrast(bg, 0x0C);
}
case NativeTheme::kColorId_NotificationEmptyPlaceholderIconColor:
return SkColorSetA(SK_ColorWHITE, 0x60);
case NativeTheme::kColorId_NotificationEmptyPlaceholderTextColor:
......
......@@ -611,6 +611,7 @@ base::Optional<SkColor> NativeThemeWin::GetPlatformHighContrastColor(
case kColorId_TableBackgroundAlternate:
case kColorId_TooltipBackground:
case kColorId_ProminentButtonDisabledColor:
case kColorId_NotificationDefaultBackground:
return system_colors_[SystemThemeColor::kWindow];
// Window Text
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment