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

Side by Side Diff: components/favicon_base/fallback_icon_style.cc

Issue 2374753002: Track when fallback icon color is the default. (Closed)
Patch Set: Merge branch 'refs/heads/master' into default-color Created 4 years, 2 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/fallback_icon_style.h" 5 #include "components/favicon_base/fallback_icon_style.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/gfx/color_analysis.h" 9 #include "ui/gfx/color_analysis.h"
10 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
(...skipping 16 matching lines...) Expand all
27 const SkColor kDefaultTextColorDark = SK_ColorBLACK; 27 const SkColor kDefaultTextColorDark = SK_ColorBLACK;
28 const SkColor kDefaultTextColorLight = SK_ColorWHITE; 28 const SkColor kDefaultTextColorLight = SK_ColorWHITE;
29 const double kDefaultFontSizeRatio = 0.44; 29 const double kDefaultFontSizeRatio = 0.44;
30 const double kDefaultRoundness = 0; // Square. Round corners are applied 30 const double kDefaultRoundness = 0; // Square. Round corners are applied
31 // externally (Javascript or Java). 31 // externally (Javascript or Java).
32 32
33 } // namespace 33 } // namespace
34 34
35 FallbackIconStyle::FallbackIconStyle() 35 FallbackIconStyle::FallbackIconStyle()
36 : background_color(kDefaultBackgroundColor), 36 : background_color(kDefaultBackgroundColor),
37 is_default_background_color(true),
37 text_color(kDefaultTextColorLight), 38 text_color(kDefaultTextColorLight),
38 font_size_ratio(kDefaultFontSizeRatio), 39 font_size_ratio(kDefaultFontSizeRatio),
39 roundness(kDefaultRoundness) { 40 roundness(kDefaultRoundness) {}
40 }
41 41
42 FallbackIconStyle::~FallbackIconStyle() { 42 FallbackIconStyle::~FallbackIconStyle() {
43 } 43 }
44 44
45 bool FallbackIconStyle::operator==(const FallbackIconStyle& other) const { 45 bool FallbackIconStyle::operator==(const FallbackIconStyle& other) const {
46 return background_color == other.background_color && 46 return background_color == other.background_color &&
47 text_color == other.text_color && 47 is_default_background_color == other.is_default_background_color &&
48 font_size_ratio == other.font_size_ratio && 48 text_color == other.text_color &&
49 roundness == other.roundness; 49 font_size_ratio == other.font_size_ratio &&
50 roundness == other.roundness;
50 } 51 }
51 52
52 void MatchFallbackIconTextColorAgainstBackgroundColor( 53 void MatchFallbackIconTextColorAgainstBackgroundColor(
53 FallbackIconStyle* style) { 54 FallbackIconStyle* style) {
54 const uint8_t luma = color_utils::GetLuma(style->background_color); 55 const uint8_t luma = color_utils::GetLuma(style->background_color);
55 style->text_color = (luma >= kDarkTextLumaThreshold) ? 56 style->text_color = (luma >= kDarkTextLumaThreshold) ?
56 kDefaultTextColorDark : kDefaultTextColorLight; 57 kDefaultTextColorDark : kDefaultTextColorLight;
57 } 58 }
58 59
59 bool ValidateFallbackIconStyle(const FallbackIconStyle& style) { 60 bool ValidateFallbackIconStyle(const FallbackIconStyle& style) {
(...skipping 13 matching lines...) Expand all
73 bitmap_data, lower_bound, upper_bound, &sampler); 74 bitmap_data, lower_bound, upper_bound, &sampler);
74 // |CalculateKMeanColorOfPNG| will try to return a color that lies within the 75 // |CalculateKMeanColorOfPNG| will try to return a color that lies within the
75 // specified bounds if one exists in the image. If there's no such color, it 76 // specified bounds if one exists in the image. If there's no such color, it
76 // will return the dominant color which may be lighter than our upper bound. 77 // will return the dominant color which may be lighter than our upper bound.
77 // Clamp lightness down to a reasonable maximum value so text is readable. 78 // Clamp lightness down to a reasonable maximum value so text is readable.
78 color_utils::HSL color_hsl; 79 color_utils::HSL color_hsl;
79 color_utils::SkColorToHSL(dominant_color, &color_hsl); 80 color_utils::SkColorToHSL(dominant_color, &color_hsl);
80 color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLightness); 81 color_hsl.l = std::min(color_hsl.l, kMaxBackgroundColorLightness);
81 style->background_color = 82 style->background_color =
82 color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE); 83 color_utils::HSLToSkColor(color_hsl, SK_AlphaOPAQUE);
84 style->is_default_background_color = false;
83 } 85 }
84 86
85 } // namespace favicon_base 87 } // namespace favicon_base
OLDNEW
« no previous file with comments | « components/favicon_base/fallback_icon_style.h ('k') | components/favicon_base/fallback_icon_url_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698