OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/favicon/favicon_util.h" | 5 #include "chrome/browser/favicon/favicon_util.h" |
6 | 6 |
7 #include "chrome/browser/history/history_types.h" | 7 #include "chrome/browser/history/history_types.h" |
8 #include "chrome/browser/history/select_favicon_frames.h" | 8 #include "chrome/browser/history/select_favicon_frames.h" |
9 #include "chrome/common/icon_messages.h" | 9 #include "chrome/common/icon_messages.h" |
10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "ui/gfx/codec/png_codec.h" | 12 #include "ui/gfx/codec/png_codec.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 | 14 |
15 // static | 15 // static |
16 std::vector<ui::ScaleFactor> FaviconUtil::GetFaviconScaleFactors() { | |
17 const float kScale1x = ui::GetScaleFactorScale(ui::SCALE_FACTOR_100P); | |
18 std::vector<ui::ScaleFactor> favicon_scale_factors = | |
19 ui::GetSupportedScaleFactors(); | |
20 | |
21 // The scale factors returned from ui::GetSupportedScaleFactors() are sorted. | |
22 // Insert the 1x scale factor such that GetFaviconScaleFactors() is sorted as | |
23 // well. | |
24 size_t insert_index = favicon_scale_factors.size(); | |
25 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { | |
26 float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]); | |
27 if (scale == kScale1x) { | |
28 return favicon_scale_factors; | |
29 } else if (scale > kScale1x) { | |
30 insert_index = i; | |
31 break; | |
32 } | |
33 } | |
34 favicon_scale_factors.insert(favicon_scale_factors.begin() + insert_index, | |
35 ui::SCALE_FACTOR_100P); | |
36 return favicon_scale_factors; | |
37 } | |
38 | |
39 // static | |
40 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, | 16 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, |
41 const GURL& url, | 17 const GURL& url, |
42 int image_size) { | 18 int image_size) { |
43 static int id = 0; | 19 static int id = 0; |
44 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, | 20 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, |
45 image_size)); | 21 image_size)); |
46 return id; | 22 return id; |
47 } | 23 } |
48 // static | 24 // static |
49 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( | 25 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( |
(...skipping 10 matching lines...) Expand all Loading... |
60 png_data[i].bitmap_data->size(), | 36 png_data[i].bitmap_data->size(), |
61 &bitmap)) { | 37 &bitmap)) { |
62 bitmaps.push_back(bitmap); | 38 bitmaps.push_back(bitmap); |
63 } | 39 } |
64 } | 40 } |
65 | 41 |
66 if (bitmaps.empty()) | 42 if (bitmaps.empty()) |
67 return gfx::Image(); | 43 return gfx::Image(); |
68 | 44 |
69 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, | 45 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, |
70 scale_factors, favicon_size, NULL); | 46 ui::GetSupportedScaleFactors(), favicon_size, NULL); |
71 return gfx::Image(resized_image_skia); | 47 return gfx::Image(resized_image_skia); |
72 } | 48 } |
OLD | NEW |