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) |
11 #include <windows.h> | 11 #include <windows.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/file_path.h" | 18 #include "base/file_path.h" |
19 #include "base/lock.h" | 19 #include "base/lock.h" |
20 #include "base/scoped_ptr.h" | 20 #include "base/scoped_ptr.h" |
21 #include "base/string16.h" | 21 #include "base/string16.h" |
22 | 22 |
23 #if defined(OS_LINUX) || defined(OS_MACOSX) | 23 #if defined(OS_LINUX) || defined(OS_MACOSX) |
24 namespace base { | 24 namespace base { |
25 class DataPack; | 25 class DataPack; |
26 }; | 26 } |
27 #endif | 27 #endif |
28 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
29 typedef struct _GdkPixbuf GdkPixbuf; | 29 typedef struct _GdkPixbuf GdkPixbuf; |
30 #endif | 30 #endif |
31 class ChromeFont; | 31 namespace gfx{ |
| 32 class Font; |
| 33 } |
32 class SkBitmap; | 34 class SkBitmap; |
33 typedef uint32 SkColor; | 35 typedef uint32 SkColor; |
34 class StringPiece; | 36 class StringPiece; |
35 | 37 |
36 // ResourceBundle is a central facility to load images and other resources, | 38 // ResourceBundle is a central facility to load images and other resources, |
37 // such as theme graphics. | 39 // such as theme graphics. |
38 // Every resource is loaded only once. | 40 // Every resource is loaded only once. |
39 class ResourceBundle { | 41 class ResourceBundle { |
40 public: | 42 public: |
41 // An enumeration of the various font styles used throughout Chrome. | 43 // An enumeration of the various font styles used throughout Chrome. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 97 |
96 // Like GetDataResource(), but avoids copying the resource. Instead, it | 98 // Like GetDataResource(), but avoids copying the resource. Instead, it |
97 // returns a StringPiece which points into the actual resource in the image. | 99 // returns a StringPiece which points into the actual resource in the image. |
98 StringPiece GetRawDataResource(int resource_id); | 100 StringPiece GetRawDataResource(int resource_id); |
99 | 101 |
100 // Get a localized string given a message id. Returns an empty | 102 // Get a localized string given a message id. Returns an empty |
101 // string if the message_id is not found. | 103 // string if the message_id is not found. |
102 string16 GetLocalizedString(int message_id); | 104 string16 GetLocalizedString(int message_id); |
103 | 105 |
104 // Returns the font for the specified style. | 106 // Returns the font for the specified style. |
105 ChromeFont GetFont(FontStyle style); | 107 gfx::Font GetFont(FontStyle style); |
106 | 108 |
107 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
108 // Loads and returns an icon from the theme dll. | 110 // Loads and returns an icon from the theme dll. |
109 HICON LoadThemeIcon(int icon_id); | 111 HICON LoadThemeIcon(int icon_id); |
110 | 112 |
111 // Loads and returns a cursor from the app module. | 113 // Loads and returns a cursor from the app module. |
112 HCURSOR LoadCursor(int cursor_id); | 114 HCURSOR LoadCursor(int cursor_id); |
113 #elif defined(OS_LINUX) | 115 #elif defined(OS_LINUX) |
114 // Gets the GdkPixbuf with the specified resource_id, first by looking into | 116 // Gets the GdkPixbuf with the specified resource_id, first by looking into |
115 // the theme data, than in the current module data if applicable. Returns a | 117 // the theme data, than in the current module data if applicable. Returns a |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ResourceBundle(); | 149 ResourceBundle(); |
148 ~ResourceBundle(); | 150 ~ResourceBundle(); |
149 | 151 |
150 // Free skia_images_. | 152 // Free skia_images_. |
151 void FreeImages(); | 153 void FreeImages(); |
152 | 154 |
153 // Try to load the main resources and the locale specific strings from an | 155 // Try to load the main resources and the locale specific strings from an |
154 // external data module. | 156 // external data module. |
155 void LoadResources(const std::wstring& pref_locale); | 157 void LoadResources(const std::wstring& pref_locale); |
156 | 158 |
157 // Initialize all the ChromeFont members if they haven't yet been initialized. | 159 // Initialize all the gfx::Font members if they haven't yet been initialized. |
158 void LoadFontsIfNecessary(); | 160 void LoadFontsIfNecessary(); |
159 | 161 |
160 // Returns the full pathname of the locale file to load. May return an empty | 162 // Returns the full pathname of the locale file to load. May return an empty |
161 // string if no locale data files are found. | 163 // string if no locale data files are found. |
162 FilePath GetLocaleFilePath(const std::wstring& pref_locale); | 164 FilePath GetLocaleFilePath(const std::wstring& pref_locale); |
163 | 165 |
164 // Loads the raw bytes of a resource from |module| into |bytes|, | 166 // Loads the raw bytes of a resource from |module| into |bytes|, |
165 // without doing any processing or interpretation of | 167 // without doing any processing or interpretation of |
166 // the resource. Returns whether we successfully read the resource. | 168 // the resource. Returns whether we successfully read the resource. |
167 static bool LoadResourceBytes(DataHandle module, | 169 static bool LoadResourceBytes(DataHandle module, |
(...skipping 17 matching lines...) Expand all Loading... |
185 // Cached images. The ResourceBundle caches all retrieved bitmaps and keeps | 187 // Cached images. The ResourceBundle caches all retrieved bitmaps and keeps |
186 // ownership of the pointers. | 188 // ownership of the pointers. |
187 typedef std::map<int, SkBitmap*> SkImageMap; | 189 typedef std::map<int, SkBitmap*> SkImageMap; |
188 SkImageMap skia_images_; | 190 SkImageMap skia_images_; |
189 #if defined(OS_LINUX) | 191 #if defined(OS_LINUX) |
190 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; | 192 typedef std::map<int, GdkPixbuf*> GdkPixbufMap; |
191 GdkPixbufMap gdk_pixbufs_; | 193 GdkPixbufMap gdk_pixbufs_; |
192 #endif | 194 #endif |
193 | 195 |
194 // The various fonts used. Cached to avoid repeated GDI creation/destruction. | 196 // The various fonts used. Cached to avoid repeated GDI creation/destruction. |
195 scoped_ptr<ChromeFont> base_font_; | 197 scoped_ptr<gfx::Font> base_font_; |
196 scoped_ptr<ChromeFont> small_font_; | 198 scoped_ptr<gfx::Font> small_font_; |
197 scoped_ptr<ChromeFont> medium_font_; | 199 scoped_ptr<gfx::Font> medium_font_; |
198 scoped_ptr<ChromeFont> medium_bold_font_; | 200 scoped_ptr<gfx::Font> medium_bold_font_; |
199 scoped_ptr<ChromeFont> large_font_; | 201 scoped_ptr<gfx::Font> large_font_; |
200 scoped_ptr<ChromeFont> web_font_; | 202 scoped_ptr<gfx::Font> web_font_; |
201 | 203 |
202 static ResourceBundle* g_shared_instance_; | 204 static ResourceBundle* g_shared_instance_; |
203 | 205 |
204 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); | 206 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); |
205 }; | 207 }; |
206 | 208 |
207 #endif // APP_RESOURCE_BUNDLE_H_ | 209 #endif // APP_RESOURCE_BUNDLE_H_ |
OLD | NEW |