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 15 matching lines...) Expand all Loading... | |
26 class SkBitmap; | 26 class SkBitmap; |
27 typedef uint32 SkColor; | 27 typedef uint32 SkColor; |
28 | 28 |
29 namespace base { | 29 namespace base { |
30 class Lock; | 30 class Lock; |
31 class StringPiece; | 31 class StringPiece; |
32 } | 32 } |
33 | 33 |
34 namespace gfx { | 34 namespace gfx { |
35 class Font; | 35 class Font; |
36 class Image; | |
36 } | 37 } |
37 | 38 |
38 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
39 #ifdef __OBJC__ | 40 #ifdef __OBJC__ |
40 @class NSImage; | 41 @class NSImage; |
41 #else | 42 #else |
42 class NSImage; | 43 class NSImage; |
43 #endif // __OBJC__ | 44 #endif // __OBJC__ |
44 #endif // defined(OS_MACOSX) | 45 #endif // defined(OS_MACOSX) |
45 | 46 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 92 |
92 // Delete the ResourceBundle for this process if it exists. | 93 // Delete the ResourceBundle for this process if it exists. |
93 static void CleanupSharedInstance(); | 94 static void CleanupSharedInstance(); |
94 | 95 |
95 // Return the global resource loader instance. | 96 // Return the global resource loader instance. |
96 static ResourceBundle& GetSharedInstance(); | 97 static ResourceBundle& GetSharedInstance(); |
97 | 98 |
98 // Gets the bitmap with the specified resource_id from the current module | 99 // Gets the bitmap with the specified resource_id from the current module |
99 // data. Returns a pointer to a shared instance of the SkBitmap. This shared | 100 // data. Returns a pointer to a shared instance of the SkBitmap. This shared |
100 // bitmap is owned by the resource bundle and should not be freed. | 101 // bitmap is owned by the resource bundle and should not be freed. |
102 // | |
103 // !! THIS IS DEPRECATED. PLEASE USE THE METHOD BELOW. !! | |
101 SkBitmap* GetBitmapNamed(int resource_id); | 104 SkBitmap* GetBitmapNamed(int resource_id); |
102 | 105 |
106 // Gets an image resource from the current module data. This will load the | |
107 // image in Skia format by default. The ResourceBundle owns this. | |
108 gfx::Image& GetImageNamed(int resource_id); | |
109 | |
110 // Similar to GetImageNamed, but rather than loading the image in Skia format, | |
111 // it will load in the native platform type. This can avoid conversion from | |
112 // one image type to another. ResourceBundle owns the result. | |
TVL
2011/02/18 21:19:12
so this isn't completely true. It might not go th
Robert Sesek
2011/02/18 21:48:17
Added a comment.
| |
113 gfx::Image& GetNativeImageNamed(int resource_id); | |
114 | |
103 // Loads the raw bytes of a data resource into |bytes|, | 115 // Loads the raw bytes of a data resource into |bytes|, |
104 // without doing any processing or interpretation of | 116 // without doing any processing or interpretation of |
105 // the resource. Returns whether we successfully read the resource. | 117 // the resource. Returns whether we successfully read the resource. |
106 RefCountedStaticMemory* LoadDataResourceBytes(int resource_id) const; | 118 RefCountedStaticMemory* LoadDataResourceBytes(int resource_id) const; |
107 | 119 |
108 // Return the contents of a resource in a StringPiece given the resource id. | 120 // Return the contents of a resource in a StringPiece given the resource id. |
109 base::StringPiece GetRawDataResource(int resource_id) const; | 121 base::StringPiece GetRawDataResource(int resource_id) const; |
110 | 122 |
111 // Get a localized string given a message id. Returns an empty | 123 // Get a localized string given a message id. Returns an empty |
112 // string if the message_id is not found. | 124 // string if the message_id is not found. |
113 string16 GetLocalizedString(int message_id); | 125 string16 GetLocalizedString(int message_id); |
114 | 126 |
115 // Returns the font for the specified style. | 127 // Returns the font for the specified style. |
116 const gfx::Font& GetFont(FontStyle style); | 128 const gfx::Font& GetFont(FontStyle style); |
117 | 129 |
118 // Returns the gfx::NativeImage, the native platform type, named resource. | |
119 // Internally, this makes use of GetNSImageNamed(), GetPixbufNamed(), or | |
120 // GetBitmapNamed() depending on the platform (see gfx/native_widget_types.h). | |
121 // NOTE: On Mac the returned resource is autoreleased. | |
122 gfx::NativeImage GetNativeImageNamed(int resource_id); | |
123 | |
124 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
125 // Loads and returns an icon from the app module. | 131 // Loads and returns an icon from the app module. |
126 HICON LoadThemeIcon(int icon_id); | 132 HICON LoadThemeIcon(int icon_id); |
127 | 133 |
128 // Loads and returns a cursor from the app module. | 134 // Loads and returns a cursor from the app module. |
129 HCURSOR LoadCursor(int cursor_id); | 135 HCURSOR LoadCursor(int cursor_id); |
130 #elif defined(OS_MACOSX) | |
131 private: | |
132 // Wrapper for GetBitmapNamed. Converts the bitmap to an autoreleased NSImage. | |
133 // TODO(rsesek): Move implementation into GetNativeImageNamed(). | |
134 NSImage* GetNSImageNamed(int resource_id); | |
135 public: | |
136 #elif defined(USE_X11) | 136 #elif defined(USE_X11) |
137 // Gets the GdkPixbuf with the specified resource_id from the main data pak | 137 // Gets the GdkPixbuf with the specified resource_id from the main data pak |
138 // file. Returns a pointer to a shared instance of the GdkPixbuf. This | 138 // file. Returns a pointer to a shared instance of the GdkPixbuf. This |
139 // shared GdkPixbuf is owned by the resource bundle and should not be freed. | 139 // shared GdkPixbuf is owned by the resource bundle and should not be freed. |
140 // | 140 // |
141 // The bitmap is assumed to exist. This function will log in release, and | 141 // The bitmap is assumed to exist. This function will log in release, and |
142 // assert in debug mode if it does not. On failure, this will return a | 142 // assert in debug mode if it does not. On failure, this will return a |
143 // pointer to a shared empty placeholder bitmap so it will be visible what | 143 // pointer to a shared empty placeholder bitmap so it will be visible what |
144 // is missing. | 144 // is missing. |
145 GdkPixbuf* GetPixbufNamed(int resource_id); | 145 GdkPixbuf* GetPixbufNamed(int resource_id); |
146 | 146 |
147 // As above, but flips it in RTL locales. | 147 // As above, but flips it in RTL locales. |
148 GdkPixbuf* GetRTLEnabledPixbufNamed(int resource_id); | 148 GdkPixbuf* GetRTLEnabledPixbufNamed(int resource_id); |
149 | 149 |
150 private: | 150 private: |
151 // Shared implementation for the above two functions. | 151 // Shared implementation for the above two functions. |
152 GdkPixbuf* GetPixbufImpl(int resource_id, bool rtl_enabled); | 152 gfx::Image* GetPixbufImpl(int resource_id, bool rtl_enabled); |
153 | 153 |
154 public: | 154 public: |
155 #endif | 155 #endif |
156 | 156 |
157 // TODO(glen): Move these into theme provider (dialogs still depend on | 157 // TODO(glen): Move these into theme provider (dialogs still depend on |
158 // ResourceBundle). | 158 // ResourceBundle). |
159 static const SkColor frame_color; | 159 static const SkColor frame_color; |
160 static const SkColor frame_color_inactive; | 160 static const SkColor frame_color_inactive; |
161 static const SkColor frame_color_app_panel; | 161 static const SkColor frame_color_app_panel; |
162 static const SkColor frame_color_app_panel_inactive; | 162 static const SkColor frame_color_app_panel_inactive; |
(...skipping 30 matching lines...) Expand all Loading... | |
193 typedef DataPack* DataHandle; | 193 typedef DataPack* DataHandle; |
194 #endif | 194 #endif |
195 | 195 |
196 // Ctor/dtor are private, since we're a singleton. | 196 // Ctor/dtor are private, since we're a singleton. |
197 ResourceBundle(); | 197 ResourceBundle(); |
198 ~ResourceBundle(); | 198 ~ResourceBundle(); |
199 | 199 |
200 // Free skia_images_. | 200 // Free skia_images_. |
201 void FreeImages(); | 201 void FreeImages(); |
202 | 202 |
203 #if defined(USE_X11) | |
204 // Free gdkPixbufs_. | |
205 void FreeGdkPixBufs(); | |
206 #endif | |
207 | |
208 // Load the main resources. | 203 // Load the main resources. |
209 void LoadCommonResources(); | 204 void LoadCommonResources(); |
210 | 205 |
211 // Try to load the locale specific strings from an external data module. | 206 // Try to load the locale specific strings from an external data module. |
212 // Returns the locale that is loaded. | 207 // Returns the locale that is loaded. |
213 std::string LoadLocaleResources(const std::string& pref_locale); | 208 std::string LoadLocaleResources(const std::string& pref_locale); |
214 | 209 |
215 // Unload the locale specific strings and prepares to load new ones. See | 210 // Unload the locale specific strings and prepares to load new ones. See |
216 // comments for ReloadSharedInstance(). | 211 // comments for ReloadSharedInstance(). |
217 void UnloadLocaleResources(); | 212 void UnloadLocaleResources(); |
(...skipping 16 matching lines...) Expand all Loading... | |
234 // successfully read the resource. Caller does not own the data returned | 229 // successfully read the resource. Caller does not own the data returned |
235 // through this method and must not modify the data pointed to by |bytes|. | 230 // through this method and must not modify the data pointed to by |bytes|. |
236 static RefCountedStaticMemory* LoadResourceBytes(DataHandle module, | 231 static RefCountedStaticMemory* LoadResourceBytes(DataHandle module, |
237 int resource_id); | 232 int resource_id); |
238 | 233 |
239 // Creates and returns a new SkBitmap given the data file to look in and the | 234 // Creates and returns a new SkBitmap given the data file to look in and the |
240 // resource id. It's up to the caller to free the returned bitmap when | 235 // resource id. It's up to the caller to free the returned bitmap when |
241 // done. | 236 // done. |
242 static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id); | 237 static SkBitmap* LoadBitmap(DataHandle dll_inst, int resource_id); |
243 | 238 |
239 // Returns an empty image for when a resource cannot be loaded. This is a | |
240 // bright red bitmap. | |
241 gfx::Image* GetEmptyImage(); | |
242 | |
244 // Class level lock. Used to protect internal data structures that may be | 243 // Class level lock. Used to protect internal data structures that may be |
245 // accessed from other threads (e.g., skia_images_). | 244 // accessed from other threads (e.g., images_). |
246 scoped_ptr<base::Lock> lock_; | 245 scoped_ptr<base::Lock> lock_; |
247 | 246 |
248 // Handles for data sources. | 247 // Handles for data sources. |
249 DataHandle resources_data_; | 248 DataHandle resources_data_; |
250 DataHandle locale_resources_data_; | 249 DataHandle locale_resources_data_; |
251 | 250 |
252 // References to extra data packs loaded via AddDataPackToSharedInstance. | 251 // References to extra data packs loaded via AddDataPackToSharedInstance. |
253 std::vector<LoadedDataPack*> data_packs_; | 252 std::vector<LoadedDataPack*> data_packs_; |
254 | 253 |
255 // Cached images. The ResourceBundle caches all retrieved bitmaps and keeps | 254 // Cached images. The ResourceBundle caches all retrieved images and keeps |
256 // ownership of the pointers. | 255 // ownership of the pointers. |
257 typedef std::map<int, SkBitmap*> SkImageMap; | 256 typedef std::map<int, gfx::Image*> ImageMap; |
258 SkImageMap skia_images_; | 257 ImageMap images_; |
259 #if defined(USE_X11) | |
260 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; | |
261 GdkPixbufMap gdk_pixbufs_; | |
262 #endif | |
263 | 258 |
264 // The various fonts used. Cached to avoid repeated GDI creation/destruction. | 259 // The various fonts used. Cached to avoid repeated GDI creation/destruction. |
265 scoped_ptr<gfx::Font> base_font_; | 260 scoped_ptr<gfx::Font> base_font_; |
266 scoped_ptr<gfx::Font> bold_font_; | 261 scoped_ptr<gfx::Font> bold_font_; |
267 scoped_ptr<gfx::Font> small_font_; | 262 scoped_ptr<gfx::Font> small_font_; |
268 scoped_ptr<gfx::Font> medium_font_; | 263 scoped_ptr<gfx::Font> medium_font_; |
269 scoped_ptr<gfx::Font> medium_bold_font_; | 264 scoped_ptr<gfx::Font> medium_bold_font_; |
270 scoped_ptr<gfx::Font> large_font_; | 265 scoped_ptr<gfx::Font> large_font_; |
271 scoped_ptr<gfx::Font> web_font_; | 266 scoped_ptr<gfx::Font> web_font_; |
272 | 267 |
273 static ResourceBundle* g_shared_instance_; | 268 static ResourceBundle* g_shared_instance_; |
274 | 269 |
275 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 270 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
276 }; | 271 }; |
277 | 272 |
278 } // namespace ui | 273 } // namespace ui |
279 | 274 |
280 // TODO(beng): Someday, maybe, get rid of this. | 275 // TODO(beng): Someday, maybe, get rid of this. |
281 using ui::ResourceBundle; | 276 using ui::ResourceBundle; |
282 | 277 |
283 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 278 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
OLD | NEW |