Commit a3e05a25 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

GMC: Respect dark mode

This CL changes MediaNotificationBackground to use the native theme for
determining the default background color instead of using a constant
white color. This fixes an issue where the GMC dialog was white even
when dark mode was on.

Bug: 981218
Change-Id: I668fe7af83286242e4fb5505b49acf53b185af79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775372Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691665}
parent ed723215
......@@ -31,6 +31,7 @@ component("media_message_center") {
"//skia",
"//ui/accessibility",
"//ui/message_center",
"//ui/native_theme",
"//ui/views",
]
}
......@@ -55,6 +56,7 @@ source_set("unit_tests") {
"//testing/gtest",
"//ui/accessibility",
"//ui/message_center",
"//ui/native_theme:test_support",
"//ui/views",
"//ui/views:test_support",
]
......
......@@ -12,6 +12,7 @@
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
......@@ -21,8 +22,6 @@ namespace {
constexpr int kMediaImageGradientWidth = 40;
constexpr SkColor kMediaNotificationDefaultBackgroundColor = SK_ColorWHITE;
// The ratio for a background color option to be considered very popular.
constexpr double kMediaNotificationBackgroundColorVeryPopularRatio = 2.5;
......@@ -281,7 +280,7 @@ void MediaNotificationBackground::Paint(gfx::Canvas* canvas,
// Draw a filled rectangle which will act as the main background of the
// notification. This may cover up some of the artwork.
const SkColor background_color =
background_color_.value_or(kMediaNotificationDefaultBackgroundColor);
background_color_.value_or(GetDefaultBackgroundColor(*view));
canvas->FillRect(GetFilledBackgroundBounds(*view), background_color);
{
......@@ -332,10 +331,11 @@ bool MediaNotificationBackground::UpdateArtworkMaxWidthPct(
return true;
}
SkColor MediaNotificationBackground::GetBackgroundColor() const {
SkColor MediaNotificationBackground::GetBackgroundColor(
const views::View& owner) const {
if (background_color_.has_value())
return *background_color_;
return kMediaNotificationDefaultBackgroundColor;
return GetDefaultBackgroundColor(owner);
}
SkColor MediaNotificationBackground::GetForegroundColor(
......@@ -345,7 +345,7 @@ SkColor MediaNotificationBackground::GetForegroundColor(
? *foreground_color_
: views::style::GetColor(owner, views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY);
return color_utils::BlendForMinContrast(foreground, GetBackgroundColor())
return color_utils::BlendForMinContrast(foreground, GetBackgroundColor(owner))
.color;
}
......@@ -412,4 +412,10 @@ SkPoint MediaNotificationBackground::GetGradientEndPoint(
: draw_bounds.right_center());
}
SkColor MediaNotificationBackground::GetDefaultBackgroundColor(
const views::View& owner) const {
return owner.GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_BubbleBackground);
}
} // namespace media_message_center
......@@ -41,7 +41,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationBackground
bool UpdateCornerRadius(int top_radius, int bottom_radius);
bool UpdateArtworkMaxWidthPct(double max_width_pct);
SkColor GetBackgroundColor() const;
SkColor GetBackgroundColor(const views::View& owner) const;
SkColor GetForegroundColor(const views::View& owner) const;
private:
......@@ -57,6 +57,7 @@ class COMPONENT_EXPORT(MEDIA_MESSAGE_CENTER) MediaNotificationBackground
gfx::Rect GetGradientBounds(const views::View& owner) const;
SkPoint GetGradientStartPoint(const gfx::Rect& draw_bounds) const;
SkPoint GetGradientEndPoint(const gfx::Rect& draw_bounds) const;
SkColor GetDefaultBackgroundColor(const views::View& owner) const;
int top_radius_;
int bottom_radius_;
......
......@@ -13,6 +13,7 @@
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/test_native_theme.h"
#include "ui/views/test/test_views.h"
namespace media_message_center {
......@@ -28,6 +29,22 @@ constexpr double kVibrantSaturation = 0.8;
constexpr int kDefaultForegroundArtworkHeight = 100;
constexpr SkColor kDarkBackgroundColor = SK_ColorBLACK;
class TestDarkTheme : public ui::TestNativeTheme {
public:
TestDarkTheme() = default;
~TestDarkTheme() override = default;
// ui::NativeTheme implementation.
SkColor GetSystemColor(ColorId color_id,
ColorScheme color_scheme) const override {
if (color_id == kColorId_BubbleBackground)
return kDarkBackgroundColor;
return ui::TestNativeTheme::GetSystemColor(color_id, color_scheme);
}
};
SkColor GetColorFromSL(double s, double l) {
return color_utils::HSLToSkColor({0.2, s, l}, SK_AlphaOPAQUE);
}
......@@ -120,6 +137,13 @@ TEST_F(MediaNotificationBackgroundTest,
EXPECT_EQ(kTestColor, GetBackgroundColor());
}
TEST_F(MediaNotificationBackgroundTest, GetBackgroundColorRespectsTheme) {
TestDarkTheme dark_theme;
views::View owner;
owner.SetNativeTheme(&dark_theme);
EXPECT_EQ(kDarkBackgroundColor, background()->GetBackgroundColor(owner));
}
// MediaNotificationBackgroundBlackWhiteTest will repeat these tests with a
// parameter that is either black or white.
class MediaNotificationBackgroundBlackWhiteTest
......
......@@ -441,7 +441,7 @@ bool MediaNotificationView::IsActuallyExpanded() const {
void MediaNotificationView::UpdateForegroundColor() {
const SkColor background =
GetMediaNotificationBackground()->GetBackgroundColor();
GetMediaNotificationBackground()->GetBackgroundColor(*this);
const SkColor foreground =
GetMediaNotificationBackground()->GetForegroundColor(*this);
......
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