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

Unified Diff: components/favicon_base/fallback_icon_style.cc

Issue 1092873002: [Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to f… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added back changes to instant_service.cc Created 5 years, 8 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
Index: components/favicon_base/fallback_icon_style.cc
diff --git a/components/favicon_base/fallback_icon_style.cc b/components/favicon_base/fallback_icon_style.cc
index e62061354103c0c154335729d4eeeb9956581b81..c1a39df70921fe7e79495db936fd6946f35158a9 100644
--- a/components/favicon_base/fallback_icon_style.cc
+++ b/components/favicon_base/fallback_icon_style.cc
@@ -4,6 +4,9 @@
#include "components/favicon_base/fallback_icon_style.h"
+#include <algorithm>
+
+#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_utils.h"
namespace favicon_base {
@@ -12,14 +15,20 @@ namespace {
// Luminance threshold for background color determine whether to use dark or
// light text color.
-int kDarkTextLuminanceThreshold = 190;
+const int kDarkTextLuminanceThreshold = 190;
+
+// The maximum luminance of the background color to ensure light text is
+// readable.
+const double kMaxBackgroundColorLuminance = 0.67;
// Default values for FallbackIconStyle.
-SkColor kDefaultBackgroundColor = SkColorSetRGB(0x80, 0x80, 0x80);
-SkColor kDefaultTextColorDark = SK_ColorBLACK;
-SkColor kDefaultTextColorLight = SK_ColorWHITE;
-double kDefaultFontSizeRatio = 0.8;
-double kDefaultRoundness = 0.125; // 1 / 8.
+const SkColor kDarkGray = SkColorSetRGB(0x78, 0x78, 0x78);
+const SkColor kDefaultBackgroundColor = kDarkGray;
+const SkColor kDefaultTextColorDark = SK_ColorBLACK;
+const SkColor kDefaultTextColorLight = SK_ColorWHITE;
+const double kDefaultFontSizeRatio = 0.44;
+const double kDefaultRoundness = 0; // Square. Round corners are applied
+ // externally (Javascript or Java).
} // namespace
@@ -45,4 +54,19 @@ bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
style.roundness >= 0.0 && style.roundness <= 1.0;
}
+void SetDominantColorAsBackground(
+ const scoped_refptr<base::RefCountedMemory>& bitmap_data,
+ FallbackIconStyle* style) {
+ SkColor dominant_color =
+ color_utils::CalculateKMeanColorOfPNG(bitmap_data);
+ // Assumes |style.text_color| is light, and clamps luminance down to a
+ // reasonable maximum value so text is readable.
+ color_utils::HSL color_hsl;
+ color_utils::SkColorToHSL(dominant_color, &color_hsl);
+ color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLuminance);
+ style->background_color =
+ color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE);
+}
+
kmadhusu 2015/04/21 17:00:27 nit: Please remove this blank line.
beaudoin 2015/04/21 18:09:54 Done.
+
} // namespace favicon_base

Powered by Google App Engine
This is Rietveld 408576698