diff options
author | huangs <huangs@chromium.org> | 2015-02-11 14:18:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-11 22:19:03 +0000 |
commit | 3382fc9d60d79fc9d829fd626a4d591d2f2a23ff (patch) | |
tree | 67ba7273e057d307aaf37a56262217f1ac2a0e4d /components/favicon_base/fallback_icon_style.cc | |
parent | 17d1302c86810f3313c18894f601e21eb6a45f19 (diff) | |
download | chromium_src-3382fc9d60d79fc9d829fd626a4d591d2f2a23ff.zip chromium_src-3382fc9d60d79fc9d829fd626a4d591d2f2a23ff.tar.gz chromium_src-3382fc9d60d79fc9d829fd626a4d591d2f2a23ff.tar.bz2 |
[Favicon] Add FallbackIconStyle and FallbackIconService.
Design: go/chrome-fallback-icons
This implements
- FallbackIconStyle: A struct to specify fallback data.
- FallbackIconService: Helper class to render the fallback icon as a
filled rounded square with a single letter from the URL.
- Extra dependencies are needed to convert URL to the icon letter.
This CL is sliced off from https://codereview.chromium.org/835903005/ .
BUG=455063
Review URL: https://codereview.chromium.org/886163003
Cr-Commit-Position: refs/heads/master@{#315854}
Diffstat (limited to 'components/favicon_base/fallback_icon_style.cc')
-rw-r--r-- | components/favicon_base/fallback_icon_style.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/components/favicon_base/fallback_icon_style.cc b/components/favicon_base/fallback_icon_style.cc new file mode 100644 index 0000000..e620613 --- /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 |