| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 5 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
| 6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 // Return the global resource loader instance. | 99 // Return the global resource loader instance. |
| 100 static ResourceBundle& GetSharedInstance(); | 100 static ResourceBundle& GetSharedInstance(); |
| 101 | 101 |
| 102 // Gets the bitmap with the specified resource_id from the current module | 102 // Gets the bitmap with the specified resource_id from the current module |
| 103 // data. Returns a pointer to a shared instance of the SkBitmap. This shared | 103 // data. Returns a pointer to a shared instance of the SkBitmap. This shared |
| 104 // bitmap is owned by the resource bundle and should not be freed. | 104 // bitmap is owned by the resource bundle and should not be freed. |
| 105 // | 105 // |
| 106 // !! THIS IS DEPRECATED. PLEASE USE THE METHOD BELOW. !! | 106 // !! THIS IS DEPRECATED. PLEASE USE THE METHOD BELOW. !! |
| 107 SkBitmap* GetBitmapNamed(int resource_id); | 107 SkBitmap* GetBitmapNamed(int resource_id); |
| 108 bool GetBitmapsNamed(int resource_id, std::vector<SkBitmap*>& bitmaps); |
| 108 | 109 |
| 109 // Gets an image resource from the current module data. This will load the | 110 // Gets an image resource from the current module data. This will load the |
| 110 // image in Skia format by default. The ResourceBundle owns this. | 111 // image in Skia format by default. The ResourceBundle owns this. |
| 111 gfx::Image& GetImageNamed(int resource_id); | 112 gfx::Image& GetImageNamed(int resource_id); |
| 112 | 113 |
| 114 // Gets images for the given |resource_id|. This can be used for icons |
| 115 // rendered at multiple resolutions. |
| 116 bool GetImagesNamed(int resource_id, std::vector<gfx::Image*>& images); |
| 117 |
| 113 // Similar to GetImageNamed, but rather than loading the image in Skia format, | 118 // Similar to GetImageNamed, but rather than loading the image in Skia format, |
| 114 // it will load in the native platform type. This can avoid conversion from | 119 // it will load in the native platform type. This can avoid conversion from |
| 115 // one image type to another. ResourceBundle owns the result. | 120 // one image type to another. ResourceBundle owns the result. |
| 116 // | 121 // |
| 117 // Note that if the same resource has already been loaded in GetImageNamed(), | 122 // Note that if the same resource has already been loaded in GetImageNamed(), |
| 118 // gfx::Image will perform a conversion, rather than using the native image | 123 // gfx::Image will perform a conversion, rather than using the native image |
| 119 // loading code of ResourceBundle. | 124 // loading code of ResourceBundle. |
| 120 gfx::Image& GetNativeImageNamed(int resource_id); | 125 gfx::Image& GetNativeImageNamed(int resource_id); |
| 121 | 126 |
| 122 // Loads the raw bytes of a data resource into |bytes|, | 127 // Loads the raw bytes of a data resource into |bytes|, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // Load test resources in given path. | 226 // Load test resources in given path. |
| 222 void LoadTestResources(const FilePath& path); | 227 void LoadTestResources(const FilePath& path); |
| 223 | 228 |
| 224 // Unload the locale specific strings and prepares to load new ones. See | 229 // Unload the locale specific strings and prepares to load new ones. See |
| 225 // comments for ReloadSharedInstance(). | 230 // comments for ReloadSharedInstance(). |
| 226 void UnloadLocaleResources(); | 231 void UnloadLocaleResources(); |
| 227 | 232 |
| 228 // Initialize all the gfx::Font members if they haven't yet been initialized. | 233 // Initialize all the gfx::Font members if they haven't yet been initialized. |
| 229 void LoadFontsIfNecessary(); | 234 void LoadFontsIfNecessary(); |
| 230 | 235 |
| 236 // Gets images from the cache. |
| 237 bool GetImagesFromCacheNamed(int resource_id, |
| 238 std::vector<gfx::Image*>& images); |
| 239 |
| 231 #if defined(USE_BASE_DATA_PACK) | 240 #if defined(USE_BASE_DATA_PACK) |
| 232 // Returns the full pathname of the main resources file to load. May return | 241 // Returns the full pathname of the main resources file to load. May return |
| 233 // an empty string if no main resources data files are found. | 242 // an empty string if no main resources data files are found. |
| 234 static FilePath GetResourcesFilePath(); | 243 static FilePath GetResourcesFilePath(); |
| 235 #endif | 244 #endif |
| 236 | 245 |
| 237 // Returns the full pathname of the locale file to load. May return an empty | 246 // Returns the full pathname of the locale file to load. May return an empty |
| 238 // string if no locale data files are found. | 247 // string if no locale data files are found. |
| 239 static FilePath GetLocaleFilePath(const std::string& app_locale); | 248 static FilePath GetLocaleFilePath(const std::string& app_locale); |
| 240 | 249 |
| 241 // Returns a handle to bytes from the resource |module|, without doing any | 250 // Returns a handle to bytes from the resource |module|, without doing any |
| 242 // processing or interpretation of the resource. Returns whether we | 251 // processing or interpretation of the resource. Returns whether we |
| 243 // successfully read the resource. Caller does not own the data returned | 252 // successfully read the resource. Caller does not own the data returned |
| 244 // through this method and must not modify the data pointed to by |bytes|. | 253 // through this method and must not modify the data pointed to by |bytes|. |
| 245 static RefCountedStaticMemory* LoadResourceBytes(DataHandle module, | 254 static RefCountedStaticMemory* LoadResourceBytes(DataHandle module, |
| 246 int resource_id); | 255 int resource_id); |
| 247 | 256 |
| 248 // Creates and returns a new SkBitmap given the data file to look in and the | 257 // Creates and returns SkBitmaps given the data file to look in and the |
| 249 // resource id. It's up to the caller to free the returned bitmap when | 258 // resource id. |
| 250 // done. | 259 static bool LoadBitmaps(DataHandle dll_inst, int resource_id, |
| 251 static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id); | 260 std::vector<SkBitmap>& bitmaps); |
| 252 | 261 |
| 253 // Returns an empty image for when a resource cannot be loaded. This is a | 262 // Returns an empty image for when a resource cannot be loaded. This is a |
| 254 // bright red bitmap. | 263 // bright red bitmap. |
| 255 gfx::Image* GetEmptyImage(); | 264 gfx::Image* GetEmptyImage(); |
| 256 | 265 |
| 257 // Class level lock. Used to protect internal data structures that may be | 266 // Class level lock. Used to protect internal data structures that may be |
| 258 // accessed from other threads (e.g., images_). | 267 // accessed from other threads (e.g., images_). |
| 259 scoped_ptr<base::Lock> lock_; | 268 scoped_ptr<base::Lock> lock_; |
| 260 | 269 |
| 261 // Handles for data sources. | 270 // Handles for data sources. |
| 262 DataHandle resources_data_; | 271 DataHandle resources_data_; |
| 263 DataHandle locale_resources_data_; | 272 DataHandle locale_resources_data_; |
| 264 | 273 |
| 265 // References to extra data packs loaded via AddDataPackToSharedInstance. | 274 // References to extra data packs loaded via AddDataPackToSharedInstance. |
| 266 std::vector<LoadedDataPack*> data_packs_; | 275 std::vector<LoadedDataPack*> data_packs_; |
| 267 | 276 |
| 268 // Cached images. The ResourceBundle caches all retrieved images and keeps | 277 // Cached images. The ResourceBundle caches all retrieved images and keeps |
| 269 // ownership of the pointers. | 278 // ownership of the pointers. |
| 270 typedef std::map<int, gfx::Image*> ImageMap; | 279 typedef std::map<int, std::vector<gfx::Image*>* > ImageMap; |
| 271 ImageMap images_; | 280 ImageMap images_; |
| 272 | 281 |
| 273 // The various fonts used. Cached to avoid repeated GDI creation/destruction. | 282 // The various fonts used. Cached to avoid repeated GDI creation/destruction. |
| 274 scoped_ptr<gfx::Font> base_font_; | 283 scoped_ptr<gfx::Font> base_font_; |
| 275 scoped_ptr<gfx::Font> bold_font_; | 284 scoped_ptr<gfx::Font> bold_font_; |
| 276 scoped_ptr<gfx::Font> small_font_; | 285 scoped_ptr<gfx::Font> small_font_; |
| 277 scoped_ptr<gfx::Font> medium_font_; | 286 scoped_ptr<gfx::Font> medium_font_; |
| 278 scoped_ptr<gfx::Font> medium_bold_font_; | 287 scoped_ptr<gfx::Font> medium_bold_font_; |
| 279 scoped_ptr<gfx::Font> large_font_; | 288 scoped_ptr<gfx::Font> large_font_; |
| 280 scoped_ptr<gfx::Font> web_font_; | 289 scoped_ptr<gfx::Font> web_font_; |
| 281 | 290 |
| 282 static ResourceBundle* g_shared_instance_; | 291 static ResourceBundle* g_shared_instance_; |
| 283 | 292 |
| 284 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 293 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
| 285 }; | 294 }; |
| 286 | 295 |
| 287 } // namespace ui | 296 } // namespace ui |
| 288 | 297 |
| 289 // TODO(beng): Someday, maybe, get rid of this. | 298 // TODO(beng): Someday, maybe, get rid of this. |
| 290 using ui::ResourceBundle; | 299 using ui::ResourceBundle; |
| 291 | 300 |
| 292 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 301 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
| OLD | NEW |