| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // Don't try to load empty values or values that are not absolute paths. | 97 // Don't try to load empty values or values that are not absolute paths. |
| 98 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) | 98 if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) |
| 99 return base::FilePath(); | 99 return base::FilePath(); |
| 100 | 100 |
| 101 if (test_file_exists && !base::PathExists(locale_file_path)) | 101 if (test_file_exists && !base::PathExists(locale_file_path)) |
| 102 return base::FilePath(); | 102 return base::FilePath(); |
| 103 | 103 |
| 104 return locale_file_path; | 104 return locale_file_path; |
| 105 } | 105 } |
| 106 | 106 |
| 107 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) { | 107 gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { |
| 108 // Flipped images are not used on Mac. | |
| 109 DCHECK_EQ(rtl, RTL_DISABLED); | |
| 110 | |
| 111 // Check to see if the image is already in the cache. | 108 // Check to see if the image is already in the cache. |
| 112 { | 109 { |
| 113 base::AutoLock lock(*images_and_fonts_lock_); | 110 base::AutoLock lock(*images_and_fonts_lock_); |
| 114 if (images_.count(resource_id)) { | 111 if (images_.count(resource_id)) { |
| 115 if (!images_[resource_id].HasRepresentation(gfx::Image::kImageRepCocoa)) { | 112 if (!images_[resource_id].HasRepresentation(gfx::Image::kImageRepCocoa)) { |
| 116 DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a" | 113 DLOG(WARNING) << "ResourceBundle::GetNativeImageNamed() is returning a" |
| 117 << " cached gfx::Image that isn't backed by an NSImage. The image" | 114 << " cached gfx::Image that isn't backed by an NSImage. The image" |
| 118 << " will be converted, rather than going through the NSImage loader." | 115 << " will be converted, rather than going through the NSImage loader." |
| 119 << " resource_id = " << resource_id; | 116 << " resource_id = " << resource_id; |
| 120 } | 117 } |
| 121 return images_[resource_id]; | 118 return images_[resource_id]; |
| 122 } | 119 } |
| 123 } | 120 } |
| 124 | 121 |
| 125 gfx::Image image; | 122 gfx::Image image; |
| 126 if (delegate_) | 123 if (delegate_) |
| 127 image = delegate_->GetNativeImageNamed(resource_id, rtl); | 124 image = delegate_->GetNativeImageNamed(resource_id); |
| 128 | 125 |
| 129 bool found_in_a_material_design_pack = false; | 126 bool found_in_a_material_design_pack = false; |
| 130 | 127 |
| 131 if (image.IsEmpty()) { | 128 if (image.IsEmpty()) { |
| 132 base::scoped_nsobject<NSImage> ns_image; | 129 base::scoped_nsobject<NSImage> ns_image; |
| 133 for (size_t i = 0; i < data_packs_.size(); ++i) { | 130 for (size_t i = 0; i < data_packs_.size(); ++i) { |
| 134 scoped_refptr<base::RefCountedStaticMemory> data( | 131 scoped_refptr<base::RefCountedStaticMemory> data( |
| 135 data_packs_[i]->GetStaticMemory(resource_id)); | 132 data_packs_[i]->GetStaticMemory(resource_id)); |
| 136 if (!data.get()) | 133 if (!data.get()) |
| 137 continue; | 134 continue; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 169 |
| 173 // Another thread raced the load and has already cached the image. | 170 // Another thread raced the load and has already cached the image. |
| 174 if (images_.count(resource_id)) | 171 if (images_.count(resource_id)) |
| 175 return images_[resource_id]; | 172 return images_[resource_id]; |
| 176 | 173 |
| 177 images_[resource_id] = image; | 174 images_[resource_id] = image; |
| 178 return images_[resource_id]; | 175 return images_[resource_id]; |
| 179 } | 176 } |
| 180 | 177 |
| 181 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |