Commit 68034593 authored by oshima@chromium.org's avatar oshima@chromium.org

Move IsScaleFactorSupported, FindClosestScaleFactorUnsafe to ui/base/resource_bundle.cc

where they're used.

BUG=372212
R=sky@chromium.org

Review URL: https://codereview.chromium.org/291073002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271874 0039d316-1c4b-4281-b951-d872f2087c98
parent 728de07b
...@@ -90,30 +90,6 @@ float GetImageScale(ScaleFactor scale_factor) { ...@@ -90,30 +90,6 @@ float GetImageScale(ScaleFactor scale_factor) {
return GetScaleForScaleFactor(scale_factor); return GetScaleForScaleFactor(scale_factor);
} }
bool IsScaleFactorSupported(ScaleFactor scale_factor) {
DCHECK(g_supported_scale_factors != NULL);
return std::find(g_supported_scale_factors->begin(),
g_supported_scale_factors->end(),
scale_factor) != g_supported_scale_factors->end();
}
// 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(kScaleFactorScales[scale_factor] - scale);
if (diff < smallest_diff) {
closest_match = scale_factor;
smallest_diff = diff;
}
}
return closest_match;
}
float GetScaleForScaleFactor(ScaleFactor scale_factor) { float GetScaleForScaleFactor(ScaleFactor scale_factor) {
return kScaleFactorScales[scale_factor]; return kScaleFactorScales[scale_factor];
} }
......
...@@ -55,14 +55,6 @@ UI_BASE_EXPORT ScaleFactor GetSupportedScaleFactor(float image_scale); ...@@ -55,14 +55,6 @@ UI_BASE_EXPORT ScaleFactor GetSupportedScaleFactor(float image_scale);
// Returns the ScaleFactor used by |view|. // Returns the ScaleFactor used by |view|.
UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view); UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view);
// Returns true if |scale_factor| is supported by this platform.
UI_BASE_EXPORT bool IsScaleFactorSupported(ScaleFactor scale_factor);
// 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.
UI_BASE_EXPORT ScaleFactor FindClosestScaleFactorUnsafe(float scale);
// Returns the image scale for the scale factor passed in. // Returns the image scale for the scale factor passed in.
UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor); UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include <limits>
#include <vector> #include <vector>
#include "base/big_endian.h" #include "base/big_endian.h"
...@@ -83,6 +84,25 @@ void InitDefaultFontList() { ...@@ -83,6 +84,25 @@ void InitDefaultFontList() {
#endif #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 } // namespace
// An ImageSkiaSource that loads bitmaps for the requested scale factor from // An ImageSkiaSource that loads bitmaps for the requested scale factor from
...@@ -514,6 +534,14 @@ ScaleFactor ResourceBundle::GetMaxScaleFactor() const { ...@@ -514,6 +534,14 @@ ScaleFactor ResourceBundle::GetMaxScaleFactor() const {
#endif #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) ResourceBundle::ResourceBundle(Delegate* delegate)
: delegate_(delegate), : delegate_(delegate),
images_and_fonts_lock_(new base::Lock), images_and_fonts_lock_(new base::Lock),
......
...@@ -256,6 +256,10 @@ class UI_BASE_EXPORT ResourceBundle { ...@@ -256,6 +256,10 @@ class UI_BASE_EXPORT ResourceBundle {
// Returns SCALE_FACTOR_100P if no resource is loaded. // Returns SCALE_FACTOR_100P if no resource is loaded.
ScaleFactor GetMaxScaleFactor() const; ScaleFactor GetMaxScaleFactor() const;
protected:
// Returns true if |scale_factor| is supported by this platform.
static bool IsScaleFactorSupported(ScaleFactor scale_factor);
private: private:
FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetPathForLocalePack); FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetPathForLocalePack);
FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetImageNamed); FRIEND_TEST_ALL_PREFIXES(ResourceBundleTest, DelegateGetImageNamed);
......
...@@ -36,7 +36,7 @@ void ResourceBundle::LoadCommonResources() { ...@@ -36,7 +36,7 @@ void ResourceBundle::LoadCommonResources() {
AddDataPackFromPath(GetResourcesPakFilePath( AddDataPackFromPath(GetResourcesPakFilePath(
"chrome_100_percent.pak"), SCALE_FACTOR_100P); "chrome_100_percent.pak"), SCALE_FACTOR_100P);
if (ui::IsScaleFactorSupported(SCALE_FACTOR_200P)) { if (IsScaleFactorSupported(SCALE_FACTOR_200P)) {
AddOptionalDataPackFromPath(GetResourcesPakFilePath( AddOptionalDataPackFromPath(GetResourcesPakFilePath(
"chrome_200_percent.pak"), SCALE_FACTOR_200P); "chrome_200_percent.pak"), SCALE_FACTOR_200P);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment