diff options
author | beaudoin <beaudoin@chromium.org> | 2015-04-22 10:12:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 17:13:08 +0000 |
commit | 3e75e59228ae3c4388379ed90ebea2e30ca0c646 (patch) | |
tree | 53afc9924fb90f3521f711b59262e692263d1d9c /components/favicon_base | |
parent | 5d19e06a5124f148e79838966cf9c9bfe68d3de6 (diff) | |
download | chromium_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')
-rw-r--r-- | components/favicon_base/fallback_icon_style.cc | 34 | ||||
-rw-r--r-- | components/favicon_base/fallback_icon_style.h | 8 | ||||
-rw-r--r-- | components/favicon_base/favicon_callback.h | 6 | ||||
-rw-r--r-- | components/favicon_base/favicon_types.cc | 12 | ||||
-rw-r--r-- | components/favicon_base/favicon_types.h | 19 |
5 files changed, 71 insertions, 8 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 diff --git a/components/favicon_base/fallback_icon_style.h b/components/favicon_base/fallback_icon_style.h index 097636b..84842ed 100644 --- a/components/favicon_base/fallback_icon_style.h +++ b/components/favicon_base/fallback_icon_style.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ #define COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ +#include "base/memory/ref_counted_memory.h" #include "third_party/skia/include/core/SkColor.h" namespace favicon_base { @@ -37,6 +38,13 @@ void MatchFallbackIconTextColorAgainstBackgroundColor(FallbackIconStyle* style); // Returns whether |style| values are within bounds. bool ValidateFallbackIconStyle(const FallbackIconStyle& style); +// Set |style|'s background color to the dominant color of |bitmap_data|, +// clamping luminance down to a reasonable maximum value so that light text is +// readable. +void SetDominantColorAsBackground( + const scoped_refptr<base::RefCountedMemory>& bitmap_data, + FallbackIconStyle* style); + } // namespace favicon_base #endif // COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ diff --git a/components/favicon_base/favicon_callback.h b/components/favicon_base/favicon_callback.h index 7616a11..96029f1 100644 --- a/components/favicon_base/favicon_callback.h +++ b/components/favicon_base/favicon_callback.h @@ -13,6 +13,7 @@ namespace favicon_base { struct FaviconRawBitmapResult; struct FaviconImageResult; +struct LargeIconResult; // Callback for functions that can be used to return a |gfx::Image| and the // |GURL| it is loaded from. They are returned as a |FaviconImageResult| object. @@ -29,6 +30,11 @@ typedef base::Callback<void(const FaviconRawBitmapResult&)> typedef base::Callback<void(const std::vector<FaviconRawBitmapResult>&)> FaviconResultsCallback; +// Callback for functions returning data for a large icon. |LargeIconResult| +// will contain either the raw bitmap for a large icon or the style of the +// fallback to use if a sufficiently large icon could not be found. +typedef base::Callback<void(const LargeIconResult&)> LargeIconCallback; + } // namespace favicon_base #endif // COMPONENTS_FAVICON_BASE_FAVICON_CALLBACK_H_ diff --git a/components/favicon_base/favicon_types.cc b/components/favicon_base/favicon_types.cc index 0188f1e..e69f1d7 100644 --- a/components/favicon_base/favicon_types.cc +++ b/components/favicon_base/favicon_types.cc @@ -4,6 +4,8 @@ #include "components/favicon_base/favicon_types.h" +#include "components/favicon_base/fallback_icon_style.h" + namespace favicon_base { // --------------------------------------------------------- @@ -20,7 +22,13 @@ FaviconRawBitmapResult::FaviconRawBitmapResult() : expired(false), icon_type(INVALID_ICON) { } -FaviconRawBitmapResult::~FaviconRawBitmapResult() { -} +FaviconRawBitmapResult::~FaviconRawBitmapResult() {} + +// -------------------------------------------------------- +// LargeIconResult + +LargeIconResult::LargeIconResult() {} + +LargeIconResult::~LargeIconResult() {} } // namespace favicon_base diff --git a/components/favicon_base/favicon_types.h b/components/favicon_base/favicon_types.h index ea64754..f7c812a 100644 --- a/components/favicon_base/favicon_types.h +++ b/components/favicon_base/favicon_types.h @@ -6,12 +6,15 @@ #define COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_ #include "base/memory/ref_counted_memory.h" +#include "base/memory/scoped_ptr.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/image/image.h" #include "url/gurl.h" namespace favicon_base { +struct FallbackIconStyle; + typedef int64 FaviconID; // Defines the icon types. They are also stored in icon_type field of favicons @@ -72,6 +75,22 @@ struct FaviconRawBitmapResult { // HistoryBackend::SetFavicons(). typedef FaviconRawBitmapResult FaviconRawBitmapData; +// Result returned by LargeIconService::GetLargeIconOrFallbackStyle(). Contains +// either the bitmap data if the favicon database has a sufficiently large +// favicon bitmap and the style of the fallback icon otherwise. +struct LargeIconResult { + LargeIconResult(); + ~LargeIconResult(); + + // The bitmap from the favicon database if the database has a sufficiently + // large one. + FaviconRawBitmapResult bitmap; + + // The fallback icon style if a sufficiently large icon isn't available. This + // uses the dominant color of a smaller icon as the background if available. + scoped_ptr<FallbackIconStyle> fallback_icon_style; +}; + } // namespace favicon_base #endif // COMPONENTS_FAVICON_BASE_FAVICON_TYPES_H_ |