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

Unified Diff: components/favicon_base/favicon_types.cc

Issue 886163003: [Favicon] Add FallbackIconStyle and FallbackIconService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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/favicon_types.cc
diff --git a/components/favicon_base/favicon_types.cc b/components/favicon_base/favicon_types.cc
index eb0e7bcfa6b0a662720117c33c24ff5abd1b43de..0269eb80ef34aeb1e6b9c3eb471f253fc88a1da5 100644
--- a/components/favicon_base/favicon_types.cc
+++ b/components/favicon_base/favicon_types.cc
@@ -3,17 +3,34 @@
// found in the LICENSE file.
#include "components/favicon_base/favicon_types.h"
+#include "ui/gfx/color_utils.h"
namespace favicon_base {
-// FaviconImageResult ---------------------------------------------------------
+namespace {
+
+// Luminance threshold for background color determine whether to use dark or
+// light text color.
+int kDarkTextLuminanceThreshold = 190;
+
+// 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.
+
+} // namespace
+
+// ---------------------------------------------------------
+// FaviconImageResult
FaviconImageResult::FaviconImageResult() {}
FaviconImageResult::~FaviconImageResult() {}
-// FaviconRawBitmapResult
// --------------------------------------------------------
+// FaviconRawBitmapResult
FaviconRawBitmapResult::FaviconRawBitmapResult()
: expired(false), icon_type(INVALID_ICON) {
@@ -22,4 +39,28 @@ FaviconRawBitmapResult::FaviconRawBitmapResult()
FaviconRawBitmapResult::~FaviconRawBitmapResult() {
}
-} // namespace chrome
+// --------------------------------------------------------
+// FallbackIconStyle
+
+FallbackIconStyle::FallbackIconStyle()
+ : background_color(kDefaultBackgroundColor),
+ text_color(kDefaultTextColorLight),
+ font_size_ratio(kDefaultFontSizeRatio),
+ roundness(kDefaultRoundness) {
+}
+
+FallbackIconStyle::~FallbackIconStyle() {
+}
+
+void FallbackIconStyle::MatchTextColorWithBackgroundColor() {
+ int luminance = color_utils::GetLuminanceForColor(background_color);
+ text_color = (luminance >= kDarkTextLuminanceThreshold ?
+ kDefaultTextColorDark : kDefaultTextColorLight);
+}
+
+bool FallbackIconStyle::is_valid() const {
+ return font_size_ratio >= 0.0 && font_size_ratio <= 1.0 &&
+ roundness >= 0.0 && roundness <= 1.0;
+}
+
+} // namespace favicon_base
« components/favicon_base/fallback_icon_service.cc ('K') | « components/favicon_base/favicon_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698