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

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: Comment and style fixes. 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..886521a65c184444b75aacb7bac4d77d0a0a2310 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 <algorithm>
+
#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);
« 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