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

Unified Diff: ui/base/resource/resource_bundle.cc

Issue 291073002: Move IsScaleFactorSupported, FindClosestScaleFactorUnsafe to ui/base/resource_bundle.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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 | « ui/base/resource/resource_bundle.h ('k') | ui/base/resource/resource_bundle_auralinux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/resource/resource_bundle.cc
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index b35d211240f5c2b475546f0e826aa6a4e983f807..83aba3c0e988dc3a2829ae4cdc3ea7f7cbd52a3e 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -4,6 +4,7 @@
#include "ui/base/resource/resource_bundle.h"
+#include <limits>
#include <vector>
#include "base/big_endian.h"
@@ -83,6 +84,25 @@ void InitDefaultFontList() {
#endif
}
+#if defined(OS_ANDROID)
+// Returns the scale factor closest to |scale| from the full list of factors.
+// Note that it does NOT rely on the list of supported scale factors.
+// Finding the closest match is inefficient and shouldn't be done frequently.
+ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
+ float smallest_diff = std::numeric_limits<float>::max();
+ ScaleFactor closest_match = SCALE_FACTOR_100P;
+ for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) {
+ const ScaleFactor scale_factor = static_cast<ScaleFactor>(i);
+ float diff = std::abs(GetScaleForScaleFactor(scale_factor) - scale);
+ if (diff < smallest_diff) {
+ closest_match = scale_factor;
+ smallest_diff = diff;
+ }
+ }
+ return closest_match;
+}
+#endif // OS_ANDROID
+
} // namespace
// An ImageSkiaSource that loads bitmaps for the requested scale factor from
@@ -514,6 +534,14 @@ ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
#endif
}
+bool ResourceBundle::IsScaleFactorSupported(ScaleFactor scale_factor) {
+ const std::vector<ScaleFactor>& supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ return std::find(supported_scale_factors.begin(),
+ supported_scale_factors.end(),
+ scale_factor) != supported_scale_factors.end();
+}
+
ResourceBundle::ResourceBundle(Delegate* delegate)
: delegate_(delegate),
images_and_fonts_lock_(new base::Lock),
« no previous file with comments | « ui/base/resource/resource_bundle.h ('k') | ui/base/resource/resource_bundle_auralinux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698