summaryrefslogtreecommitdiffstats
path: root/components/favicon_base/fallback_icon_style.cc
diff options
context:
space:
mode:
authorbeaudoin <beaudoin@chromium.org>2015-04-22 10:12:14 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 17:13:08 +0000
commit3e75e59228ae3c4388379ed90ebea2e30ca0c646 (patch)
tree53afc9924fb90f3521f711b59262e692263d1d9c /components/favicon_base/fallback_icon_style.cc
parent5d19e06a5124f148e79838966cf9c9bfe68d3de6 (diff)
downloadchromium_src-3e75e59228ae3c4388379ed90ebea2e30ca0c646.zip
chromium_src-3e75e59228ae3c4388379ed90ebea2e30ca0c646.tar.gz
chromium_src-3e75e59228ae3c4388379ed90ebea2e30ca0c646.tar.bz2
[Icons NTP] Refactor large_icon_source to extract the logic shared between desktop and Android to a new large_icon_service.
This is required since the Android implementation of the icon-based NTP will rely on custom Java code to render the fallback. As a result we want to share the logic needed to retrieve large icons and to compute the fallback style without needing them to go through the full-featured chrome://large-icon that performs the rendering of fallback icons. The Java code will hook directly into the large_icon_service. This CL also fixes a bug, making sure only non-square icons can be returned as large icons. Besides this, this CL doesn't change the behavior but will make it possible to add the large icon selection logic to large_icon_service where it can be shared with the Android code. BUG=467712 Review URL: https://codereview.chromium.org/1092873002 Cr-Commit-Position: refs/heads/master@{#326325}
Diffstat (limited to 'components/favicon_base/fallback_icon_style.cc')
-rw-r--r--components/favicon_base/fallback_icon_style.cc34
1 files changed, 28 insertions, 6 deletions
diff --git a/components/favicon_base/fallback_icon_style.cc b/components/favicon_base/fallback_icon_style.cc
index e620613..d3e395b 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