From c23c19880d7f7eec5eee5955f956867f8a54f078 Mon Sep 17 00:00:00 2001 From: huangs Date: Tue, 16 Sep 2014 09:37:52 -0700 Subject: [PATCH] [Themes Service] Implement better default value for which Google logo to use. BUG=414120 TEST=Manual, see bug Review URL: https://codereview.chromium.org/564353002 Cr-Commit-Position: refs/heads/master@{#295081} --- chrome/browser/themes/theme_service.cc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc index 1dba96f3942c..886521a65c18 100644 --- a/chrome/browser/themes/theme_service.cc +++ b/chrome/browser/themes/theme_service.cc @@ -4,6 +4,8 @@ #include "chrome/browser/themes/theme_service.h" +#include + #include "base/bind.h" #include "base/memory/ref_counted_memory.h" #include "base/message_loop/message_loop.h" @@ -78,6 +80,17 @@ void WritePackToDiskCallback(BrowserThemePack* pack, NOTREACHED() << "Could not write theme pack to disk"; } +// Heuristic to determine if color is grayscale. This is used to decide whether +// to use the colorful or white logo, if a theme fails to specify which. +bool IsColorGrayscale(SkColor color) { + const int kChannelTolerance = 9; + int r = SkColorGetR(color); + int g = SkColorGetG(color); + int b = SkColorGetB(color); + int range = std::max(r, std::max(g, b)) - std::min(r, std::min(g, b)); + return range < kChannelTolerance; +} + } // namespace ThemeService::ThemeService() @@ -193,12 +206,15 @@ int ThemeService::GetDisplayProperty(int id) const { return result; } - if (id == Properties::NTP_LOGO_ALTERNATE && - !UsingDefaultTheme() && - !UsingSystemTheme()) { - // Use the alternate logo for themes from the web store except for - // |kDefaultThemeGalleryID|. - return 1; + if (id == Properties::NTP_LOGO_ALTERNATE) { + if (UsingDefaultTheme() || UsingSystemTheme()) + return 0; // Colorful logo. + + if (HasCustomImage(IDR_THEME_NTP_BACKGROUND)) + return 1; // White logo. + + SkColor background_color = GetColor(Properties::COLOR_NTP_BACKGROUND); + return IsColorGrayscale(background_color) ? 0 : 1; } return Properties::GetDefaultDisplayProperty(id); -- 2.11.4.GIT