Chromium Code Reviews| 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 "chrome/browser/manifest/manifest_icon_downloader.h" | 5 #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 bool ManifestIconDownloader::Download( | 48 bool ManifestIconDownloader::Download( |
| 49 content::WebContents* web_contents, | 49 content::WebContents* web_contents, |
| 50 const GURL& icon_url, | 50 const GURL& icon_url, |
| 51 int ideal_icon_size_in_dp, | 51 int ideal_icon_size_in_dp, |
| 52 int minimum_icon_size_in_dp, | 52 int minimum_icon_size_in_dp, |
| 53 const ManifestIconDownloader::IconFetchCallback& callback) { | 53 const ManifestIconDownloader::IconFetchCallback& callback) { |
| 54 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); | 54 DCHECK(minimum_icon_size_in_dp <= ideal_icon_size_in_dp); |
| 55 if (!web_contents || !icon_url.is_valid()) | 55 if (!web_contents || !icon_url.is_valid()) |
| 56 return false; | 56 return false; |
| 57 | 57 |
| 58 const gfx::Screen* screen = | 58 const gfx::Screen* screen = gfx::Screen::GetScreen(); |
|
oshima
2016/01/19 20:44:31
inline?
scottmg
2016/01/19 21:55:57
Done.
| |
| 59 gfx::Screen::GetScreenFor(web_contents->GetNativeView()); | |
| 60 | |
| 61 const float device_scale_factor = | 59 const float device_scale_factor = |
| 62 screen->GetPrimaryDisplay().device_scale_factor(); | 60 screen->GetPrimaryDisplay().device_scale_factor(); |
| 63 const int ideal_icon_size_in_px = | 61 const int ideal_icon_size_in_px = |
| 64 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor)); | 62 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor)); |
| 65 const int minimum_icon_size_in_px = | 63 const int minimum_icon_size_in_px = |
| 66 static_cast<int>(round(minimum_icon_size_in_dp * device_scale_factor)); | 64 static_cast<int>(round(minimum_icon_size_in_dp * device_scale_factor)); |
| 67 | 65 |
| 68 web_contents->DownloadImage( | 66 web_contents->DownloadImage( |
| 69 icon_url, | 67 icon_url, |
| 70 false, // is_favicon | 68 false, // is_favicon |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 float ratio = height / width; | 194 float ratio = height / width; |
| 197 float ratio_difference = fabs(ratio - 1); | 195 float ratio_difference = fabs(ratio - 1); |
| 198 if (ratio_difference < best_ratio_difference) { | 196 if (ratio_difference < best_ratio_difference) { |
| 199 best_index = i; | 197 best_index = i; |
| 200 best_ratio_difference = ratio_difference; | 198 best_ratio_difference = ratio_difference; |
| 201 } | 199 } |
| 202 } | 200 } |
| 203 | 201 |
| 204 return best_index; | 202 return best_index; |
| 205 } | 203 } |
| OLD | NEW |