Automated Commit: Committing new LKGM version 6953.0.0 for chromeos.
[chromium-blink-merge.git] / components / favicon_base / fallback_icon_style.cc
blobe62061354103c0c154335729d4eeeb9956581b81
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/favicon_base/fallback_icon_style.h"
7 #include "ui/gfx/color_utils.h"
9 namespace favicon_base {
11 namespace {
13 // Luminance threshold for background color determine whether to use dark or
14 // light text color.
15 int kDarkTextLuminanceThreshold = 190;
17 // Default values for FallbackIconStyle.
18 SkColor kDefaultBackgroundColor = SkColorSetRGB(0x80, 0x80, 0x80);
19 SkColor kDefaultTextColorDark = SK_ColorBLACK;
20 SkColor kDefaultTextColorLight = SK_ColorWHITE;
21 double kDefaultFontSizeRatio = 0.8;
22 double kDefaultRoundness = 0.125; // 1 / 8.
24 } // namespace
26 FallbackIconStyle::FallbackIconStyle()
27 : background_color(kDefaultBackgroundColor),
28 text_color(kDefaultTextColorLight),
29 font_size_ratio(kDefaultFontSizeRatio),
30 roundness(kDefaultRoundness) {
33 FallbackIconStyle::~FallbackIconStyle() {
36 void MatchFallbackIconTextColorAgainstBackgroundColor(
37 FallbackIconStyle* style) {
38 int luminance = color_utils::GetLuminanceForColor(style->background_color);
39 style->text_color = (luminance >= kDarkTextLuminanceThreshold ?
40 kDefaultTextColorDark : kDefaultTextColorLight);
43 bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
44 return style.font_size_ratio >= 0.0 && style.font_size_ratio <= 1.0 &&
45 style.roundness >= 0.0 && style.roundness <= 1.0;
48 } // namespace favicon_base