Chromium Code Reviews| 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..7a3bd54c0df7d515ed632ad068569a7276e8c041 100644 |
| --- a/components/favicon_base/fallback_icon_style.cc |
| +++ b/components/favicon_base/fallback_icon_style.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/favicon_base/fallback_icon_style.h" |
| +#include "ui/gfx/color_analysis.h" |
| #include "ui/gfx/color_utils.h" |
| namespace favicon_base { |
| @@ -12,14 +13,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 +52,17 @@ 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); |
|
huangs
2015/04/17 15:30:47
// Assumes |style.text_color| is light, and clamps
beaudoin
2015/04/17 20:29:05
Done.
|
| + 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 |