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

Unified Diff: components/favicon_base/fallback_icon_style.cc

Issue 886163003: [Favicon] Add FallbackIconStyle and FallbackIconService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix; moved FallbackIconStyle member functions outside of struct. Created 5 years, 10 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/fallback_icon_style.cc
diff --git a/components/favicon_base/fallback_icon_style.cc b/components/favicon_base/fallback_icon_style.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e62061354103c0c154335729d4eeeb9956581b81
--- /dev/null
+++ b/components/favicon_base/fallback_icon_style.cc
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/favicon_base/fallback_icon_style.h"
+
+#include "ui/gfx/color_utils.h"
+
+namespace favicon_base {
+
+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
+
+FallbackIconStyle::FallbackIconStyle()
+ : background_color(kDefaultBackgroundColor),
+ text_color(kDefaultTextColorLight),
+ font_size_ratio(kDefaultFontSizeRatio),
+ roundness(kDefaultRoundness) {
+}
+
+FallbackIconStyle::~FallbackIconStyle() {
+}
+
+void MatchFallbackIconTextColorAgainstBackgroundColor(
+ FallbackIconStyle* style) {
+ int luminance = color_utils::GetLuminanceForColor(style->background_color);
+ style->text_color = (luminance >= kDarkTextLuminanceThreshold ?
+ kDefaultTextColorDark : kDefaultTextColorLight);
+}
+
+bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
+ return style.font_size_ratio >= 0.0 && style.font_size_ratio <= 1.0 &&
+ style.roundness >= 0.0 && style.roundness <= 1.0;
+}
+
+} // namespace favicon_base

Powered by Google App Engine
This is Rietveld 408576698