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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/favicon_base/fallback_icon_style.h"
6
7 #include "ui/gfx/color_utils.h"
8
9 namespace favicon_base {
10
11 namespace {
12
13 // Luminance threshold for background color determine whether to use dark or
14 // light text color.
15 int kDarkTextLuminanceThreshold = 190;
16
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.
23
24 } // namespace
25
26 FallbackIconStyle::FallbackIconStyle()
27 : background_color(kDefaultBackgroundColor),
28 text_color(kDefaultTextColorLight),
29 font_size_ratio(kDefaultFontSizeRatio),
30 roundness(kDefaultRoundness) {
31 }
32
33 FallbackIconStyle::~FallbackIconStyle() {
34 }
35
36 void MatchFallbackIconTextColorAgainstBackgroundColor(
37 FallbackIconStyle* style) {
38 int luminance = color_utils::GetLuminanceForColor(style->background_color);
39 style->text_color = (luminance >= kDarkTextLuminanceThreshold ?
40 kDefaultTextColorDark : kDefaultTextColorLight);
41 }
42
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;
46 }
47
48 } // namespace favicon_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698