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

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: Moving FallbackIconStyle to its own file to fix Skia dependency issues. 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 FallbackIconStyle::MatchTextColorWithBackgroundColor() {
37 int luminance = color_utils::GetLuminanceForColor(background_color);
38 text_color = (luminance >= kDarkTextLuminanceThreshold ?
39 kDefaultTextColorDark : kDefaultTextColorLight);
40 }
41
42 bool FallbackIconStyle::is_valid() const {
43 return font_size_ratio >= 0.0 && font_size_ratio <= 1.0 &&
44 roundness >= 0.0 && roundness <= 1.0;
45 }
46
47 } // namespace favicon_base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698