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 |
16 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, | 40 int FaviconUtil::DownloadFavicon(content::RenderViewHost* rvh, |
17 const GURL& url, | 41 const GURL& url, |
18 int image_size) { | 42 int image_size) { |
19 static int id = 0; | 43 static int id = 0; |
20 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, | 44 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url, |
21 image_size)); | 45 image_size)); |
22 return id; | 46 return id; |
23 } | 47 } |
24 // static | 48 // static |
25 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( | 49 gfx::Image FaviconUtil::SelectFaviconFramesFromPNGs( |
(...skipping 10 matching lines...) Expand all Loading... |
36 png_data[i].bitmap_data->size(), | 60 png_data[i].bitmap_data->size(), |
37 &bitmap)) { | 61 &bitmap)) { |
38 bitmaps.push_back(bitmap); | 62 bitmaps.push_back(bitmap); |
39 } | 63 } |
40 } | 64 } |
41 | 65 |
42 if (bitmaps.empty()) | 66 if (bitmaps.empty()) |
43 return gfx::Image(); | 67 return gfx::Image(); |
44 | 68 |
45 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, | 69 gfx::ImageSkia resized_image_skia = SelectFaviconFrames(bitmaps, |
46 ui::GetSupportedScaleFactors(), favicon_size, NULL); | 70 scale_factors, favicon_size, NULL); |
47 return gfx::Image(resized_image_skia); | 71 return gfx::Image(resized_image_skia); |
48 } | 72 } |
OLD | NEW |