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 <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 Loading... | |
| 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. | |
|
mlamouri (slow - plz ping)
2015/09/18 13:41:59
Very quick comment: maybe you could use a ratio in
Lalit Maganti
2015/09/18 14:06:46
Problem with using a ratio is that the code become
gone
2015/09/18 18:46:41
I agree with Mounir about relying on ratios; the d
Lalit Maganti
2015/09/21 09:52:34
Done.
| |
| 136 int best_dimension_difference = std::numeric_limits<int>::max(); | |
| 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 int dimension_difference = abs(bitmaps[i].height() - bitmaps[i].width()); | |
| 144 if (dimension_difference < best_dimension_difference) { | |
| 145 best_index = i; | |
| 146 best_dimension_difference = dimension_difference; | |
| 147 } | |
| 148 } | |
| 149 | |
| 129 return best_index; | 150 return best_index; |
| 130 } | 151 } |
| OLD | NEW |