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 "chrome/browser/extensions/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cctype> | 9 #include <cctype> |
10 #include <string> | 10 #include <string> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 explicit GeneratedIconImageSource(char letter, SkColor color, int output_size) | 86 explicit GeneratedIconImageSource(char letter, SkColor color, int output_size) |
87 : gfx::CanvasImageSource(gfx::Size(output_size, output_size), false), | 87 : gfx::CanvasImageSource(gfx::Size(output_size, output_size), false), |
88 letter_(letter), | 88 letter_(letter), |
89 color_(color), | 89 color_(color), |
90 output_size_(output_size) {} | 90 output_size_(output_size) {} |
91 ~GeneratedIconImageSource() override {} | 91 ~GeneratedIconImageSource() override {} |
92 | 92 |
93 private: | 93 private: |
94 // gfx::CanvasImageSource overrides: | 94 // gfx::CanvasImageSource overrides: |
95 void Draw(gfx::Canvas* canvas) override { | 95 void Draw(gfx::Canvas* canvas) override { |
96 const unsigned char kLuminanceThreshold = 190; | 96 const uint8_t kLumaThreshold = 190; |
97 const int icon_size = output_size_ * 3 / 4; | 97 const int icon_size = output_size_ * 3 / 4; |
98 const int icon_inset = output_size_ / 8; | 98 const int icon_inset = output_size_ / 8; |
99 const size_t border_radius = output_size_ / 16; | 99 const size_t border_radius = output_size_ / 16; |
100 const size_t font_size = output_size_ * 7 / 16; | 100 const size_t font_size = output_size_ * 7 / 16; |
101 | 101 |
102 std::string font_name = | 102 std::string font_name = |
103 l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY); | 103 l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY); |
104 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) |
105 const std::string kChromeOSFontFamily = "Noto Sans"; | 105 const std::string kChromeOSFontFamily = "Noto Sans"; |
106 font_name = kChromeOSFontFamily; | 106 font_name = kChromeOSFontFamily; |
107 #endif | 107 #endif |
108 | 108 |
109 // Draw a rounded rect of the given |color|. | 109 // Draw a rounded rect of the given |color|. |
110 SkPaint background_paint; | 110 SkPaint background_paint; |
111 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 111 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
112 background_paint.setColor(color_); | 112 background_paint.setColor(color_); |
113 | 113 |
114 gfx::Rect icon_rect(icon_inset, icon_inset, icon_size, icon_size); | 114 gfx::Rect icon_rect(icon_inset, icon_inset, icon_size, icon_size); |
115 canvas->DrawRoundRect(icon_rect, border_radius, background_paint); | 115 canvas->DrawRoundRect(icon_rect, border_radius, background_paint); |
116 | 116 |
117 // The text rect's size needs to be odd to center the text correctly. | 117 // The text rect's size needs to be odd to center the text correctly. |
118 gfx::Rect text_rect(icon_inset, icon_inset, icon_size + 1, icon_size + 1); | 118 gfx::Rect text_rect(icon_inset, icon_inset, icon_size + 1, icon_size + 1); |
119 // Draw the letter onto the rounded rect. The letter's color depends on the | 119 // Draw the letter onto the rounded rect. The letter's color depends on the |
120 // luminance of |color|. | 120 // luma of |color|. |
121 unsigned char luminance = color_utils::GetLuminanceForColor(color_); | 121 const uint8_t luma = color_utils::Luma(color_); |
122 canvas->DrawStringRectWithFlags( | 122 canvas->DrawStringRectWithFlags( |
123 base::string16(1, std::toupper(letter_)), | 123 base::string16(1, std::toupper(letter_)), |
124 gfx::FontList(gfx::Font(font_name, font_size)), | 124 gfx::FontList(gfx::Font(font_name, font_size)), |
125 luminance > kLuminanceThreshold ? SK_ColorBLACK : SK_ColorWHITE, | 125 (luma > kLumaThreshold) ? SK_ColorBLACK : SK_ColorWHITE, |
126 text_rect, | 126 text_rect, |
127 gfx::Canvas::TEXT_ALIGN_CENTER); | 127 gfx::Canvas::TEXT_ALIGN_CENTER); |
128 } | 128 } |
129 | 129 |
130 char letter_; | 130 char letter_; |
131 | 131 |
132 SkColor color_; | 132 SkColor color_; |
133 | 133 |
134 int output_size_; | 134 int output_size_; |
135 | 135 |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); | 796 extension, info_list, base::Bind(&OnIconsLoaded, web_app_info, callback)); |
797 } | 797 } |
798 | 798 |
799 bool IsValidBookmarkAppUrl(const GURL& url) { | 799 bool IsValidBookmarkAppUrl(const GURL& url) { |
800 URLPattern origin_only_pattern(Extension::kValidBookmarkAppSchemes); | 800 URLPattern origin_only_pattern(Extension::kValidBookmarkAppSchemes); |
801 origin_only_pattern.SetMatchAllURLs(true); | 801 origin_only_pattern.SetMatchAllURLs(true); |
802 return url.is_valid() && origin_only_pattern.MatchesURL(url); | 802 return url.is_valid() && origin_only_pattern.MatchesURL(url); |
803 } | 803 } |
804 | 804 |
805 } // namespace extensions | 805 } // namespace extensions |
OLD | NEW |