Index: chrome/browser/themes/theme_service.cc |
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc |
index 1dba96f3942c8ba2eb9da04364133930dcdf980c..b07a456f00d792269ebc7a89639b3c6d99c8fa17 100644 |
--- a/chrome/browser/themes/theme_service.cc |
+++ b/chrome/browser/themes/theme_service.cc |
@@ -78,6 +78,19 @@ 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); |
+ // range = max(r, g, b) - min(r, g, b). |
pkotwicz
2014/09/16 03:57:18
Nit: Use std::max() and std::min(). It makes the c
huangs
2014/09/16 15:38:54
Done.
|
+ int range = (r > g) ? (r > b ? r : b) - (g < b ? g : b) : |
+ (g > b ? g : b) - (r < b ? r : b); |
+ return range < kChannelTolerance; |
+} |
+ |
} // namespace |
ThemeService::ThemeService() |
@@ -193,12 +206,17 @@ 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) { |
+ // Use colorful logo for |kDefaultThemeGalleryID| themes. |
pkotwicz
2014/09/16 03:57:18
Remove the comment. It no longer makes sense.
huangs
2014/09/16 15:38:54
Done; made the comments more succinct.
|
+ if (UsingDefaultTheme() || UsingSystemTheme()) |
+ return 0; |
+ |
+ // Use white logo if background image is used. |
+ if (HasCustomImage(IDR_THEME_NTP_BACKGROUND)) |
+ return 1; |
+ |
+ SkColor background_color = GetColor(Properties::COLOR_NTP_BACKGROUND); |
+ return IsColorGrayscale(background_color) ? 0 : 1; |
} |
return Properties::GetDefaultDisplayProperty(id); |