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

Side by Side 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: Switch to using ratios 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/manifest/manifest_icon_downloader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <limits> 7 #include <limits>
8 8
9 #include "chrome/browser/manifest/manifest_icon_selector.h" 9 #include "chrome/browser/manifest/manifest_icon_selector.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 if (best_delta > 0 && delta < 0) 120 if (best_delta > 0 && delta < 0)
121 continue; 121 continue;
122 122
123 if ((best_delta > 0 && delta < best_delta) || 123 if ((best_delta > 0 && delta < best_delta) ||
124 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) { 124 (best_delta < 0 && delta > best_delta && delta >= max_negative_delta)) {
125 best_index = i; 125 best_index = i;
126 best_delta = delta; 126 best_delta = delta;
127 } 127 }
128 } 128 }
129
130 if (best_index != -1)
131 return best_index;
132
133 // There was no square icon of a correct size found. Try to find the most
134 // square possible icon which has both dimensions greater than the minimum
135 // size.
136 float best_ratio_difference = std::numeric_limits<float>::infinity();
137 for (size_t i = 0; i < bitmaps.size(); ++i) {
138 if (bitmaps[i].height() < minimum_icon_size_in_px ||
139 bitmaps[i].width() < minimum_icon_size_in_px) {
140 continue;
141 }
142
143 float ratio = static_cast<float>(bitmaps[i].height()) /
gone 2015/09/21 09:51:03 Can you use some temporary variables to make it ea
Lalit Maganti 2015/09/21 09:52:34 Done.
144 static_cast<float>(bitmaps[i].width());
145 float ratio_difference = abs(ratio - 1);
146 if (ratio_difference < best_ratio_difference) {
147 best_index = i;
148 best_ratio_difference = ratio_difference;
149 }
150 }
151
129 return best_index; 152 return best_index;
130 } 153 }
OLDNEW
« 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