Index: ui/base/resource/resource_bundle.cc |
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc |
index f84e8dbb8d432f03040d2a7ef4e472c06ce51c10..667b92cad2ad4f271df1aa1d44a63bd3d1b49994 100644 |
--- a/ui/base/resource/resource_bundle.cc |
+++ b/ui/base/resource/resource_bundle.cc |
@@ -60,7 +60,7 @@ void ResourceBundle::InitSharedInstanceWithPakFile(const FilePath& path) { |
DCHECK(g_shared_instance_ == NULL) << "ResourceBundle initialized twice"; |
g_shared_instance_ = new ResourceBundle(NULL); |
- g_shared_instance_->LoadTestResources(path); |
+ g_shared_instance_->LoadTestResources(path, path); |
} |
// static |
@@ -101,7 +101,7 @@ void ResourceBundle::AddDataPack(const FilePath& path, float scale_factor) { |
return; |
scoped_ptr<DataPack> data_pack( |
- new DataPack(ResourceHandle::kScaleFactor100x)); |
+ new DataPack(scale_factor)); |
if (data_pack->Load(pack_path)) { |
data_packs_.push_back(data_pack.release()); |
} else { |
@@ -176,16 +176,21 @@ std::string ResourceBundle::LoadLocaleResources( |
return app_locale; |
} |
-void ResourceBundle::LoadTestResources(const FilePath& path) { |
+void ResourceBundle::LoadTestResources(const FilePath& path, |
+ const FilePath& locale_path) { |
// Use the given resource pak for both common and localized resources. |
scoped_ptr<DataPack> data_pack( |
new DataPack(ResourceHandle::kScaleFactor100x)); |
- if (data_pack->Load(path)) |
+ if (!path.empty() && data_pack->Load(path)) |
data_packs_.push_back(data_pack.release()); |
- data_pack.reset(new DataPack(ResourceHandle::kScaleFactor100x)); |
- if (data_pack->Load(path)) |
+ data_pack.reset(new DataPack(ResourceHandle::kScaleFactorNone)); |
+ if (!locale_path.empty() && data_pack->Load(locale_path)) { |
locale_resources_data_.reset(data_pack.release()); |
+ } else { |
+ locale_resources_data_.reset( |
+ new DataPack(ResourceHandle::kScaleFactorNone)); |
+ } |
} |
void ResourceBundle::UnloadLocaleResources() { |
@@ -270,31 +275,51 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { |
} |
base::RefCountedStaticMemory* ResourceBundle::LoadDataResourceBytes( |
- int resource_id) const { |
+ int resource_id, |
+ float scale_factor) const { |
base::RefCountedStaticMemory* bytes = NULL; |
if (delegate_) |
- bytes = delegate_->LoadDataResourceBytes(resource_id); |
+ bytes = delegate_->LoadDataResourceBytes(resource_id, scale_factor); |
if (!bytes) { |
- for (size_t i = 0; i < data_packs_.size() && !bytes; ++i) |
- bytes = data_packs_[i]->GetStaticMemory(resource_id); |
+ base::StringPiece data = GetRawDataResource(resource_id, scale_factor); |
+ if (!data.empty()) { |
+ bytes = new base::RefCountedStaticMemory( |
+ reinterpret_cast<const unsigned char*>(data.data()), data.length()); |
+ } |
} |
return bytes; |
} |
-base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) const { |
+base::StringPiece ResourceBundle::GetRawDataResource( |
+ int resource_id, |
+ float scale_factor) const { |
base::StringPiece data; |
- if (delegate_ && delegate_->GetRawDataResource(resource_id, &data)) |
+ if (delegate_ && |
+ delegate_->GetRawDataResource(resource_id, scale_factor, &data)) |
return data; |
DCHECK(locale_resources_data_.get()); |
if (locale_resources_data_->GetStringPiece(resource_id, &data)) |
return data; |
+ size_t best_match = data_packs_.size(); |
+ float best_match_scale = 0; |
for (size_t i = 0; i < data_packs_.size(); ++i) { |
- if (data_packs_[i]->GetStringPiece(resource_id, &data)) |
- return data; |
+ if (best_match == data_packs_.size() || |
tony
2012/05/11 21:22:03
This seems unnecessarily complex considering the p
flackr
2012/05/11 21:59:07
We should always have a 1x asset. I was mostly wor
flackr
2012/05/15 02:16:33
Done.
|
+ fabs(best_match_scale - scale_factor) > |
+ fabs(data_packs_[i]->GetScaleFactor() - scale_factor)) { |
+ if (data_packs_[i]->HasResource(resource_id)) { |
+ best_match = i; |
+ best_match_scale = data_packs_[i]->GetScaleFactor(); |
+ } |
+ } |
+ } |
+ |
+ if (best_match < data_packs_.size() && |
+ data_packs_[best_match]->GetStringPiece(resource_id, &data)) { |
+ return data; |
} |
return base::StringPiece(); |
@@ -320,7 +345,7 @@ string16 ResourceBundle::GetLocalizedString(int message_id) { |
if (!locale_resources_data_->GetStringPiece(message_id, &data)) { |
// Fall back on the main data pack (shouldn't be any strings here except in |
// unittests). |
- data = GetRawDataResource(message_id); |
+ data = GetRawDataResource(message_id, ResourceHandle::kScaleFactorNone); |
if (data.empty()) { |
NOTREACHED() << "unable to find resource: " << message_id; |
return string16(); |