summaryrefslogtreecommitdiffstats
path: root/ui/base/resource
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 23:14:18 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 23:14:18 +0000
commit57e51dcb12469532de1439fe2d7a23c44d4704c3 (patch)
tree253525b59520be044412db8a8a02fcd5dd13150b /ui/base/resource
parent390ce232aa0167dad2084a7351a2114e97971fec (diff)
downloadchromium_src-57e51dcb12469532de1439fe2d7a23c44d4704c3.zip
chromium_src-57e51dcb12469532de1439fe2d7a23c44d4704c3.tar.gz
chromium_src-57e51dcb12469532de1439fe2d7a23c44d4704c3.tar.bz2
Use the maximum device scale factor to determine the resolution of thumbnails.
This CL introduces GetMaxScaleFactor in layout.h and uses it for determining the resolution of thumbnails. Original CL: http://codereview.chromium.org/11264025/ This CL is slightly modified to sort the supported scale factors. BUG=155065 TEST=updated LayoutTest Review URL: https://chromiumcodereview.appspot.com/11367064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/resource')
-rw-r--r--ui/base/resource/resource_bundle.cc30
-rw-r--r--ui/base/resource/resource_bundle.h14
2 files changed, 40 insertions, 4 deletions
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index db6cb55..420330a 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -34,6 +34,10 @@
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/skbitmap_operations.h"
+#if defined(OS_CHROMEOS)
+#include "base/chromeos/chromeos_version.h"
+#endif
+
namespace ui {
namespace {
@@ -229,7 +233,7 @@ void ResourceBundle::AddDataPackFromFile(base::PlatformFile file,
scoped_ptr<DataPack> data_pack(
new DataPack(scale_factor));
if (data_pack->LoadFromFile(file)) {
- data_packs_.push_back(data_pack.release());
+ AddDataPack(data_pack.release());
} else {
LOG(ERROR) << "Failed to load data pack from file."
<< "\nSome features may not be available.";
@@ -306,7 +310,7 @@ void ResourceBundle::LoadTestResources(const FilePath& path,
scoped_ptr<DataPack> data_pack(
new DataPack(SCALE_FACTOR_100P));
if (!path.empty() && data_pack->LoadFromPath(path))
- data_packs_.push_back(data_pack.release());
+ AddDataPack(data_pack.release());
data_pack.reset(new DataPack(ui::SCALE_FACTOR_NONE));
if (!locale_path.empty() && data_pack->LoadFromPath(locale_path)) {
@@ -518,7 +522,8 @@ void ResourceBundle::ReloadFonts() {
ResourceBundle::ResourceBundle(Delegate* delegate)
: delegate_(delegate),
images_and_fonts_lock_(new base::Lock),
- locale_resources_data_lock_(new base::Lock) {
+ locale_resources_data_lock_(new base::Lock),
+ max_scale_factor_(SCALE_FACTOR_100P) {
}
ResourceBundle::~ResourceBundle() {
@@ -548,13 +553,30 @@ void ResourceBundle::AddDataPackFromPathInternal(const FilePath& path,
scoped_ptr<DataPack> data_pack(
new DataPack(scale_factor));
if (data_pack->LoadFromPath(pack_path)) {
- data_packs_.push_back(data_pack.release());
+ AddDataPack(data_pack.release());
} else if (!optional) {
LOG(ERROR) << "Failed to load " << pack_path.value()
<< "\nSome features may not be available.";
}
}
+void ResourceBundle::AddDataPack(DataPack* data_pack) {
+ data_packs_.push_back(data_pack);
+
+#if defined(OS_CHROMEOS)
+ // When Chrome is running on desktop and force-device-scale-factor is not
+ // specified, use SCALE_FACTOR_100P as |max_scale_factor_|.
+ if (!base::chromeos::IsRunningOnChromeOS() &&
+ !CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kForceDeviceScaleFactor))
+ return;
+#endif
+
+ if (GetScaleFactorScale(data_pack->GetScaleFactor()) >
+ GetScaleFactorScale(max_scale_factor_))
+ max_scale_factor_ = data_pack->GetScaleFactor();
+}
+
void ResourceBundle::LoadFontsIfNecessary() {
images_and_fonts_lock_->AssertAcquired();
if (!base_font_.get()) {
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index 49657a1..b5424de 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -33,6 +33,7 @@ class RefCountedStaticMemory;
namespace ui {
+class DataPack;
class ResourceHandle;
// ResourceBundle is a central facility to load images and other resources,
@@ -246,6 +247,12 @@ class UI_EXPORT ResourceBundle {
FilePath GetLocaleFilePath(const std::string& app_locale,
bool test_file_exists);
+ // Returns the maximum scale factor currently loaded.
+ // Returns SCALE_FACTOR_100P if no resource is loaded.
+ ScaleFactor max_scale_factor() const {
+ return max_scale_factor_;
+ }
+
private:
FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack);
FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack);
@@ -279,6 +286,10 @@ class UI_EXPORT ResourceBundle {
ScaleFactor scale_factor,
bool optional);
+ // Inserts |data_pack| to |data_pack_| and updates |max_scale_factor_|
+ // accordingly.
+ void AddDataPack(DataPack* data_pack);
+
// Try to load the locale specific strings from an external data module.
// Returns the locale that is loaded.
std::string LoadLocaleResources(const std::string& pref_locale);
@@ -331,6 +342,9 @@ class UI_EXPORT ResourceBundle {
scoped_ptr<ResourceHandle> locale_resources_data_;
ScopedVector<ResourceHandle> data_packs_;
+ // The maximum scale factor currently loaded.
+ ScaleFactor max_scale_factor_;
+
// Cached images. The ResourceBundle caches all retrieved images and keeps
// ownership of the pointers.
typedef std::map<int, gfx::Image> ImageMap;