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..d3e395b1d1966e53da6d799fa0f86553caf9eeb0 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,19 @@ 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 kDefaultBackgroundColor = SkColorSetRGB(0x78, 0x78, 0x78); |
+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 +53,18 @@ 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); |
+} |
+ |
} // namespace favicon_base |