OLD | NEW |
---|---|
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_service.h" | 5 #include "components/favicon_base/fallback_icon_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/favicon/core/browser/fallback_icon_client.h" | |
sdefresne
2015/03/17 09:41:52
favicon_base component must not depends on favicon
huangs
2015/03/23 03:28:35
Moved to components/favicon/core to join siblings
| |
11 #include "components/favicon_base/fallback_icon_style.h" | 12 #include "components/favicon_base/fallback_icon_style.h" |
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
13 #include "third_party/skia/include/core/SkPaint.h" | 14 #include "third_party/skia/include/core/SkPaint.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/codec/png_codec.h" | 16 #include "ui/gfx/codec/png_codec.h" |
16 #include "ui/gfx/font_list.h" | 17 #include "ui/gfx/font_list.h" |
17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
18 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
(...skipping 10 matching lines...) Expand all Loading... | |
31 base::string16 GetFallbackIconText(const GURL& url) { | 32 base::string16 GetFallbackIconText(const GURL& url) { |
32 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( | 33 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( |
33 url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 34 url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
34 return domain.empty() ? base::string16() : | 35 return domain.empty() ? base::string16() : |
35 base::i18n::ToUpper(base::ASCIIToUTF16(domain.substr(0, 1))); | 36 base::i18n::ToUpper(base::ASCIIToUTF16(domain.substr(0, 1))); |
36 } | 37 } |
37 | 38 |
38 } // namespace | 39 } // namespace |
39 | 40 |
40 FallbackIconService::FallbackIconService( | 41 FallbackIconService::FallbackIconService( |
41 const std::vector<std::string>& font_list) | 42 FallbackIconClient* fallback_icon_client) |
42 : font_list_(font_list) { | 43 : fallback_icon_client_(fallback_icon_client) { |
43 } | 44 } |
44 | 45 |
45 FallbackIconService::~FallbackIconService() { | 46 FallbackIconService::~FallbackIconService() { |
46 } | 47 } |
47 | 48 |
48 std::vector<unsigned char> FallbackIconService::RenderFallbackIconBitmap( | 49 std::vector<unsigned char> FallbackIconService::RenderFallbackIconBitmap( |
49 const GURL& icon_url, | 50 const GURL& icon_url, |
50 int size, | 51 int size, |
51 const FallbackIconStyle& style) { | 52 const FallbackIconStyle& style) { |
52 int size_to_use = std::min(kMaxFallbackFaviconSize, size); | 53 int size_to_use = std::min(kMaxFallbackFaviconSize, size); |
(...skipping 28 matching lines...) Expand all Loading... | |
81 base::string16 icon_text = GetFallbackIconText(icon_url); | 82 base::string16 icon_text = GetFallbackIconText(icon_url); |
82 if (icon_text.empty()) | 83 if (icon_text.empty()) |
83 return; | 84 return; |
84 int font_size = static_cast<int>(size * style.font_size_ratio); | 85 int font_size = static_cast<int>(size * style.font_size_ratio); |
85 if (font_size <= 0) | 86 if (font_size <= 0) |
86 return; | 87 return; |
87 | 88 |
88 // TODO(huangs): See how expensive gfx::FontList() is, and possibly cache. | 89 // TODO(huangs): See how expensive gfx::FontList() is, and possibly cache. |
89 canvas->DrawStringRectWithFlags( | 90 canvas->DrawStringRectWithFlags( |
90 icon_text, | 91 icon_text, |
91 gfx::FontList(font_list_, gfx::Font::NORMAL, font_size), | 92 gfx::FontList(fallback_icon_client_->GetFontNameList(), gfx::Font::NORMAL, |
93 font_size), | |
92 style.text_color, | 94 style.text_color, |
93 gfx::Rect(kOffsetX, kOffsetY, size, size), | 95 gfx::Rect(kOffsetX, kOffsetY, size, size), |
94 gfx::Canvas::TEXT_ALIGN_CENTER); | 96 gfx::Canvas::TEXT_ALIGN_CENTER); |
95 } | 97 } |
96 | 98 |
97 } // namespace favicon_base | 99 } // namespace favicon_base |
OLD | NEW |