Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Unified Diff: chrome/browser/themes/theme_service.cc

Issue 564353002: [Themes Service] Implement better default value for which Google logo to use. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698