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

Unified Diff: ui/base/resource/resource_bundle_mac.mm

Issue 1771963002: Make sure images loaded from MD resource packs contain all reps (Mac). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/resource/resource_bundle_mac.mm
diff --git a/ui/base/resource/resource_bundle_mac.mm b/ui/base/resource/resource_bundle_mac.mm
index fb907400da2230c445cf010cfd71287ed1c9a7df..0b8d526c9a60613446f22da26a79c8c8350772cd 100644
--- a/ui/base/resource/resource_bundle_mac.mm
+++ b/ui/base/resource/resource_bundle_mac.mm
@@ -143,27 +143,43 @@ gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) {
if (delegate_)
image = delegate_->GetNativeImageNamed(resource_id);
- bool found_in_a_material_design_pack = false;
-
if (image.IsEmpty()) {
base::scoped_nsobject<NSImage> ns_image;
+ // Material Design packs are meant to override the standard packs, so
+ // search for the image in those packs first.
for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (!data_packs_[i]->HasOnlyMaterialDesignAssets())
+ continue;
scoped_refptr<base::RefCountedStaticMemory> data(
data_packs_[i]->GetStaticMemory(resource_id));
if (!data.get())
continue;
- // This loop adds the image resource from each available pack, if it's
- // present. When Material Design packs are available, however, their
- // images are meant to override the same image in the standard packs. The
- // Material Design packs exist at the start of the data_packs_ vector,
- // so make a note that the image was pulled from a Material Design pack,
- // and ignore the same image in the standard packs.
- if (found_in_a_material_design_pack) {
- break;
+ base::scoped_nsobject<NSData> ns_data(
+ [[NSData alloc] initWithBytes:data->front() length:data->size()]);
+ if (!ns_image.get()) {
+ ns_image.reset([[NSImage alloc] initWithData:ns_data]);
+ } else {
+ NSImageRep* image_rep = [NSBitmapImageRep imageRepWithData:ns_data];
+ if (image_rep)
+ [ns_image addRepresentation:image_rep];
}
- found_in_a_material_design_pack =
- data_packs_[i]->HasOnlyMaterialDesignAssets();
+ }
+
+ if (ns_image.get()) {
+ image = gfx::Image(ns_image.release());
+ }
+ }
+
+ if (image.IsEmpty()) {
+ base::scoped_nsobject<NSImage> ns_image;
+ for (size_t i = 0; i < data_packs_.size(); ++i) {
+ if (data_packs_[i]->HasOnlyMaterialDesignAssets())
+ continue;
+ scoped_refptr<base::RefCountedStaticMemory> data(
+ data_packs_[i]->GetStaticMemory(resource_id));
+ if (!data.get())
+ continue;
base::scoped_nsobject<NSData> ns_data(
[[NSData alloc] initWithBytes:data->front() length:data->size()]);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698