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-like icon which has both dimensions greater than the minimum size. | |
| 135 float best_ratio_difference = std::numeric_limits<float>::infinity(); | |
| 136 for (size_t i = 0; i < bitmaps.size(); ++i) { | |
| 137 if (bitmaps[i].height() < minimum_icon_size_in_px || | |
| 138 bitmaps[i].width() < minimum_icon_size_in_px) { | |
| 139 continue; | |
| 140 } | |
| 141 | |
| 142 float height = static_cast<float>(bitmaps[i].height()); | |
| 143 float width = static_cast<float>(bitmaps[i].width()); | |
| 144 float ratio = height / width; | |
|
mlamouri (slow - plz ping)
2015/09/23 13:45:21
nit: you could inline the static_cast<float> in th
Lalit Maganti
2015/09/23 13:50:02
With the inlining this line became way too long. D
| |
| 145 float ratio_difference = fabs(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 } |
| OLD | NEW |