OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/favicon_base/favicon_types.h" | 5 #include "components/favicon_base/favicon_types.h" |
| 6 #include "ui/gfx/color_utils.h" |
6 | 7 |
7 namespace favicon_base { | 8 namespace favicon_base { |
8 | 9 |
9 // FaviconImageResult --------------------------------------------------------- | 10 namespace { |
| 11 |
| 12 // Luminance threshold for background color determine whether to use dark or |
| 13 // light text color. |
| 14 int kDarkTextLuminanceThreshold = 190; |
| 15 |
| 16 // Default values for FallbackIconStyle. |
| 17 SkColor kDefaultBackgroundColor = SkColorSetRGB(0x80, 0x80, 0x80); |
| 18 SkColor kDefaultTextColorDark = SK_ColorBLACK; |
| 19 SkColor kDefaultTextColorLight = SK_ColorWHITE; |
| 20 double kDefaultFontSizeRatio = 0.8; |
| 21 double kDefaultRoundness = 0.125; // 1 / 8. |
| 22 |
| 23 } // namespace |
| 24 |
| 25 // --------------------------------------------------------- |
| 26 // FaviconImageResult |
10 | 27 |
11 FaviconImageResult::FaviconImageResult() {} | 28 FaviconImageResult::FaviconImageResult() {} |
12 | 29 |
13 FaviconImageResult::~FaviconImageResult() {} | 30 FaviconImageResult::~FaviconImageResult() {} |
14 | 31 |
| 32 // -------------------------------------------------------- |
15 // FaviconRawBitmapResult | 33 // FaviconRawBitmapResult |
16 // -------------------------------------------------------- | |
17 | 34 |
18 FaviconRawBitmapResult::FaviconRawBitmapResult() | 35 FaviconRawBitmapResult::FaviconRawBitmapResult() |
19 : expired(false), icon_type(INVALID_ICON) { | 36 : expired(false), icon_type(INVALID_ICON) { |
20 } | 37 } |
21 | 38 |
22 FaviconRawBitmapResult::~FaviconRawBitmapResult() { | 39 FaviconRawBitmapResult::~FaviconRawBitmapResult() { |
23 } | 40 } |
24 | 41 |
25 } // namespace chrome | 42 // -------------------------------------------------------- |
| 43 // FallbackIconStyle |
| 44 |
| 45 FallbackIconStyle::FallbackIconStyle() |
| 46 : background_color(kDefaultBackgroundColor), |
| 47 text_color(kDefaultTextColorLight), |
| 48 font_size_ratio(kDefaultFontSizeRatio), |
| 49 roundness(kDefaultRoundness) { |
| 50 } |
| 51 |
| 52 FallbackIconStyle::~FallbackIconStyle() { |
| 53 } |
| 54 |
| 55 void FallbackIconStyle::MatchTextColorWithBackgroundColor() { |
| 56 int luminance = color_utils::GetLuminanceForColor(background_color); |
| 57 text_color = (luminance >= kDarkTextLuminanceThreshold ? |
| 58 kDefaultTextColorDark : kDefaultTextColorLight); |
| 59 } |
| 60 |
| 61 bool FallbackIconStyle::is_valid() const { |
| 62 return font_size_ratio >= 0.0 && font_size_ratio <= 1.0 && |
| 63 roundness >= 0.0 && roundness <= 1.0; |
| 64 } |
| 65 |
| 66 } // namespace favicon_base |
OLD | NEW |