| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 APP_RESOURCE_BUNDLE_H_ | 5 #ifndef APP_RESOURCE_BUNDLE_H_ |
| 6 #define APP_RESOURCE_BUNDLE_H_ | 6 #define APP_RESOURCE_BUNDLE_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // NOTE: Mac ignores this and always loads up resources for the language | 67 // NOTE: Mac ignores this and always loads up resources for the language |
| 68 // defined by the Cocoa UI (ie-NSBundle does the langange work). | 68 // defined by the Cocoa UI (ie-NSBundle does the langange work). |
| 69 static void InitSharedInstance(const std::wstring& pref_locale); | 69 static void InitSharedInstance(const std::wstring& pref_locale); |
| 70 | 70 |
| 71 // Delete the ResourceBundle for this process if it exists. | 71 // Delete the ResourceBundle for this process if it exists. |
| 72 static void CleanupSharedInstance(); | 72 static void CleanupSharedInstance(); |
| 73 | 73 |
| 74 // Return the global resource loader instance. | 74 // Return the global resource loader instance. |
| 75 static ResourceBundle& GetSharedInstance(); | 75 static ResourceBundle& GetSharedInstance(); |
| 76 | 76 |
| 77 // Load the data file that contains theme resources if present. | 77 // Gets the bitmap with the specified resource_id from the current module |
| 78 void LoadThemeResources(); | 78 // data. Returns a pointer to a shared instance of the SkBitmap. This shared |
| 79 | 79 // bitmap is owned by the resource bundle and should not be freed. |
| 80 // Gets the bitmap with the specified resource_id, first by looking into the | |
| 81 // theme data, then in the current module data if applicable. | |
| 82 // Returns a pointer to a shared instance of the SkBitmap. This shared bitmap | |
| 83 // is owned by the resource bundle and should not be freed. | |
| 84 // | 80 // |
| 85 // The bitmap is assumed to exist. This function will log in release, and | 81 // The bitmap is assumed to exist. This function will log in release, and |
| 86 // assert in debug mode if it does not. On failure, this will return a | 82 // assert in debug mode if it does not. On failure, this will return a |
| 87 // pointer to a shared empty placeholder bitmap so it will be visible what | 83 // pointer to a shared empty placeholder bitmap so it will be visible what |
| 88 // is missing. | 84 // is missing. |
| 89 SkBitmap* GetBitmapNamed(int resource_id); | 85 SkBitmap* GetBitmapNamed(int resource_id); |
| 90 | 86 |
| 91 // Loads the raw bytes of an image resource into |bytes|, | 87 // Loads the raw bytes of an image resource into |bytes|, |
| 92 // without doing any processing or interpretation of | 88 // without doing any processing or interpretation of |
| 93 // the resource. Returns whether we successfully read the resource. | 89 // the resource. Returns whether we successfully read the resource. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 base::StringPiece GetRawDataResource(int resource_id); | 105 base::StringPiece GetRawDataResource(int resource_id); |
| 110 | 106 |
| 111 // Get a localized string given a message id. Returns an empty | 107 // Get a localized string given a message id. Returns an empty |
| 112 // string if the message_id is not found. | 108 // string if the message_id is not found. |
| 113 string16 GetLocalizedString(int message_id); | 109 string16 GetLocalizedString(int message_id); |
| 114 | 110 |
| 115 // Returns the font for the specified style. | 111 // Returns the font for the specified style. |
| 116 const gfx::Font& GetFont(FontStyle style); | 112 const gfx::Font& GetFont(FontStyle style); |
| 117 | 113 |
| 118 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
| 119 // Loads and returns an icon from the theme dll. | 115 // Loads and returns an icon from the app module. |
| 120 HICON LoadThemeIcon(int icon_id); | 116 HICON LoadThemeIcon(int icon_id); |
| 121 | 117 |
| 122 // Loads and returns a cursor from the app module. | 118 // Loads and returns a cursor from the app module. |
| 123 HCURSOR LoadCursor(int cursor_id); | 119 HCURSOR LoadCursor(int cursor_id); |
| 124 #elif defined(OS_MACOSX) | 120 #elif defined(OS_MACOSX) |
| 125 // Wrapper for GetBitmapNamed. Converts the bitmap to an autoreleased NSImage. | 121 // Wrapper for GetBitmapNamed. Converts the bitmap to an autoreleased NSImage. |
| 126 NSImage* GetNSImageNamed(int resource_id); | 122 NSImage* GetNSImageNamed(int resource_id); |
| 127 #elif defined(USE_X11) | 123 #elif defined(USE_X11) |
| 128 // Gets the GdkPixbuf with the specified resource_id, first by looking into | 124 // Gets the GdkPixbuf with the specified resource_id from the main data pak |
| 129 // the theme data, than in the current module data if applicable. Returns a | 125 // file. Returns a pointer to a shared instance of the GdkPixbuf. This |
| 130 // pointer to a shared instance of the GdkPixbuf. This shared GdkPixbuf is | 126 // shared GdkPixbuf is owned by the resource bundle and should not be freed. |
| 131 // owned by the resource bundle and should not be freed. | |
| 132 // | 127 // |
| 133 // The bitmap is assumed to exist. This function will log in release, and | 128 // The bitmap is assumed to exist. This function will log in release, and |
| 134 // assert in debug mode if it does not. On failure, this will return a | 129 // assert in debug mode if it does not. On failure, this will return a |
| 135 // pointer to a shared empty placeholder bitmap so it will be visible what | 130 // pointer to a shared empty placeholder bitmap so it will be visible what |
| 136 // is missing. | 131 // is missing. |
| 137 GdkPixbuf* GetPixbufNamed(int resource_id); | 132 GdkPixbuf* GetPixbufNamed(int resource_id); |
| 138 | 133 |
| 139 // As above, but flips it in RTL locales. | 134 // As above, but flips it in RTL locales. |
| 140 GdkPixbuf* GetRTLEnabledPixbufNamed(int resource_id); | 135 GdkPixbuf* GetRTLEnabledPixbufNamed(int resource_id); |
| 141 | 136 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // done. | 191 // done. |
| 197 static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id); | 192 static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id); |
| 198 | 193 |
| 199 // Class level lock. Used to protect internal data structures that may be | 194 // Class level lock. Used to protect internal data structures that may be |
| 200 // accessed from other threads (e.g., skia_images_). | 195 // accessed from other threads (e.g., skia_images_). |
| 201 Lock lock_; | 196 Lock lock_; |
| 202 | 197 |
| 203 // Handles for data sources. | 198 // Handles for data sources. |
| 204 DataHandle resources_data_; | 199 DataHandle resources_data_; |
| 205 DataHandle locale_resources_data_; | 200 DataHandle locale_resources_data_; |
| 206 DataHandle theme_data_; | |
| 207 | 201 |
| 208 // Cached images. The ResourceBundle caches all retrieved bitmaps and keeps | 202 // Cached images. The ResourceBundle caches all retrieved bitmaps and keeps |
| 209 // ownership of the pointers. | 203 // ownership of the pointers. |
| 210 typedef std::map<int, SkBitmap*> SkImageMap; | 204 typedef std::map<int, SkBitmap*> SkImageMap; |
| 211 SkImageMap skia_images_; | 205 SkImageMap skia_images_; |
| 212 #if defined(USE_X11) | 206 #if defined(USE_X11) |
| 213 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; | 207 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; |
| 214 GdkPixbufMap gdk_pixbufs_; | 208 GdkPixbufMap gdk_pixbufs_; |
| 215 #endif | 209 #endif |
| 216 | 210 |
| 217 // The various fonts used. Cached to avoid repeated GDI creation/destruction. | 211 // The various fonts used. Cached to avoid repeated GDI creation/destruction. |
| 218 scoped_ptr<gfx::Font> base_font_; | 212 scoped_ptr<gfx::Font> base_font_; |
| 219 scoped_ptr<gfx::Font> small_font_; | 213 scoped_ptr<gfx::Font> small_font_; |
| 220 scoped_ptr<gfx::Font> medium_font_; | 214 scoped_ptr<gfx::Font> medium_font_; |
| 221 scoped_ptr<gfx::Font> medium_bold_font_; | 215 scoped_ptr<gfx::Font> medium_bold_font_; |
| 222 scoped_ptr<gfx::Font> large_font_; | 216 scoped_ptr<gfx::Font> large_font_; |
| 223 scoped_ptr<gfx::Font> web_font_; | 217 scoped_ptr<gfx::Font> web_font_; |
| 224 | 218 |
| 225 static ResourceBundle* g_shared_instance_; | 219 static ResourceBundle* g_shared_instance_; |
| 226 | 220 |
| 227 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); | 221 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); |
| 228 }; | 222 }; |
| 229 | 223 |
| 230 #endif // APP_RESOURCE_BUNDLE_H_ | 224 #endif // APP_RESOURCE_BUNDLE_H_ |
| OLD | NEW |