Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: chrome/browser/manifest/manifest_icon_downloader.cc

Issue 1354903003: manifest: allow the icon downloader to choose non-square icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add check for width being greater than ideal Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/manifest/manifest_icon_downloader_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/manifest/manifest_icon_downloader.cc
diff --git a/chrome/browser/manifest/manifest_icon_downloader.cc b/chrome/browser/manifest/manifest_icon_downloader.cc
index 34ff954d39e64fe15fe901ff85c973b2b19ba0da..4a5e14496e6e6afcd7df995cc1d49ae7613c8a3a 100644
--- a/chrome/browser/manifest/manifest_icon_downloader.cc
+++ b/chrome/browser/manifest/manifest_icon_downloader.cc
@@ -68,7 +68,8 @@ void ManifestIconDownloader::OnIconFetched(
// Only scale if we need to scale down. For scaling up we will let the system
// handle that when it is required to display it. This saves space in the
// webapp storage system as well.
- if (chosen.height() > ideal_icon_size_in_px) {
+ if (chosen.height() > ideal_icon_size_in_px ||
+ chosen.width() > ideal_icon_size_in_px) {
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
@@ -126,5 +127,28 @@ int ManifestIconDownloader::FindClosestBitmapIndex(
best_delta = delta;
}
}
+
+ if (best_index != -1)
+ return best_index;
+
+ // There was no square icon of a correct size found. Try to find the most
+ // square-like icon which has both dimensions greater than the minimum size.
+ float best_ratio_difference = std::numeric_limits<float>::infinity();
+ for (size_t i = 0; i < bitmaps.size(); ++i) {
+ if (bitmaps[i].height() < minimum_icon_size_in_px ||
+ bitmaps[i].width() < minimum_icon_size_in_px) {
+ continue;
+ }
+
+ float height = static_cast<float>(bitmaps[i].height());
+ float width = static_cast<float>(bitmaps[i].width());
+ float ratio = height / width;
+ float ratio_difference = fabs(ratio - 1);
+ if (ratio_difference < best_ratio_difference) {
+ best_index = i;
+ best_ratio_difference = ratio_difference;
+ }
+ }
+
return best_index;
}
« no previous file with comments | « no previous file | chrome/browser/manifest/manifest_icon_downloader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698