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

Side by Side Diff: chrome/browser/manifest/manifest_icon_selector.cc

Issue 1308533006: webapps: allow callers of icon downloader/selector to specify a minimum size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webapps-splashscreen-icon
Patch Set: Address review comments 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
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_selector.h" 5 #include "chrome/browser/manifest/manifest_icon_selector.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 } 158 }
159 159
160 return result; 160 return result;
161 } 161 }
162 162
163 // static 163 // static
164 GURL ManifestIconSelector::FindBestMatchingIcon( 164 GURL ManifestIconSelector::FindBestMatchingIcon(
165 const std::vector<Manifest::Icon>& unfiltered_icons, 165 const std::vector<Manifest::Icon>& unfiltered_icons,
166 const int ideal_icon_size_in_dp, 166 const int ideal_icon_size_in_dp,
167 const int minimum_icon_size_in_dp,
167 const gfx::Screen* screen) { 168 const gfx::Screen* screen) {
168 const float device_scale_factor = 169 const float device_scale_factor =
169 screen->GetPrimaryDisplay().device_scale_factor(); 170 screen->GetPrimaryDisplay().device_scale_factor();
170 const int ideal_icon_size_in_px = 171 const float ideal_icon_size_in_px =
171 static_cast<int>(round(ideal_icon_size_in_dp * device_scale_factor)); 172 ideal_icon_size_in_dp * device_scale_factor;
gone 2015/09/14 23:03:32 Why did you stop rounding?
Lalit Maganti 2015/09/15 16:59:04 Tiredness when resolving merge conflicts = silly s
172 173 const float minimum_icon_size_in_px =
173 const float minimum_scale_factor = std::max(device_scale_factor - 1, 1.0f); 174 minimum_icon_size_in_dp * device_scale_factor;
174 const int minimum_icon_size_in_px =
175 static_cast<int>(round(ideal_icon_size_in_dp * minimum_scale_factor));
176 175
177 std::vector<Manifest::Icon> icons = 176 std::vector<Manifest::Icon> icons =
178 ManifestIconSelector::FilterIconsByType(unfiltered_icons); 177 ManifestIconSelector::FilterIconsByType(unfiltered_icons);
179 178
180 ManifestIconSelector selector(ideal_icon_size_in_px, 179 ManifestIconSelector selector(ideal_icon_size_in_px,
181 minimum_icon_size_in_px); 180 minimum_icon_size_in_px);
182 int index = selector.FindBestMatchingIcon(icons, device_scale_factor); 181 int index = selector.FindBestMatchingIcon(icons, device_scale_factor);
183 if (index == -1) 182 if (index == -1)
184 return GURL(); 183 return GURL();
185 return icons[index].src; 184 return icons[index].src;
186 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698