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 #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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // default resource. | 82 // default resource. |
83 virtual gfx::Image GetImageNamed(int resource_id) = 0; | 83 virtual gfx::Image GetImageNamed(int resource_id) = 0; |
84 | 84 |
85 // Return an image resource or an empty value to attempt retrieval of the | 85 // Return an image resource or an empty value to attempt retrieval of the |
86 // default resource. | 86 // default resource. |
87 virtual gfx::Image GetNativeImageNamed(int resource_id, ImageRTL rtl) = 0; | 87 virtual gfx::Image GetNativeImageNamed(int resource_id, ImageRTL rtl) = 0; |
88 | 88 |
89 // Return a static memory resource or NULL to attempt retrieval of the | 89 // Return a static memory resource or NULL to attempt retrieval of the |
90 // default resource. | 90 // default resource. |
91 virtual base::RefCountedStaticMemory* LoadDataResourceBytes( | 91 virtual base::RefCountedStaticMemory* LoadDataResourceBytes( |
92 int resource_id) = 0; | 92 int resource_id, |
| 93 float scale_factor) = 0; |
93 | 94 |
94 // Retrieve a raw data resource. Return true if a resource was provided or | 95 // Retrieve a raw data resource. Return true if a resource was provided or |
95 // false to attempt retrieval of the default resource. | 96 // false to attempt retrieval of the default resource. |
96 virtual bool GetRawDataResource(int resource_id, | 97 virtual bool GetRawDataResource(int resource_id, |
| 98 float scale_factor, |
97 base::StringPiece* value) = 0; | 99 base::StringPiece* value) = 0; |
98 | 100 |
99 // Retrieve a localized string. Return true if a string was provided or | 101 // Retrieve a localized string. Return true if a string was provided or |
100 // false to attempt retrieval of the default string. | 102 // false to attempt retrieval of the default string. |
101 virtual bool GetLocalizedString(int message_id, string16* value) = 0; | 103 virtual bool GetLocalizedString(int message_id, string16* value) = 0; |
102 | 104 |
103 // Return a font resource or NULL to attempt retrieval of the default | 105 // Return a font resource or NULL to attempt retrieval of the default |
104 // resource. | 106 // resource. |
105 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; | 107 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; |
106 | 108 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Note that if the same resource has already been loaded in GetImageNamed(), | 176 // Note that if the same resource has already been loaded in GetImageNamed(), |
175 // gfx::Image will perform a conversion, rather than using the native image | 177 // gfx::Image will perform a conversion, rather than using the native image |
176 // loading code of ResourceBundle. | 178 // loading code of ResourceBundle. |
177 // | 179 // |
178 // If |rtl| is RTL_ENABLED then the image is flipped in RTL locales. | 180 // If |rtl| is RTL_ENABLED then the image is flipped in RTL locales. |
179 gfx::Image& GetNativeImageNamed(int resource_id, ImageRTL rtl); | 181 gfx::Image& GetNativeImageNamed(int resource_id, ImageRTL rtl); |
180 | 182 |
181 // Same as GetNativeImageNamed() except that RTL is not enabled. | 183 // Same as GetNativeImageNamed() except that RTL is not enabled. |
182 gfx::Image& GetNativeImageNamed(int resource_id); | 184 gfx::Image& GetNativeImageNamed(int resource_id); |
183 | 185 |
184 // Loads the raw bytes of a data resource into |bytes|, | 186 // Loads the raw bytes of a data resource nearest the scale factor |
185 // without doing any processing or interpretation of | 187 // |scale_factor| into |bytes|, without doing any processing or interpretation |
186 // the resource. Returns whether we successfully read the resource. | 188 // of the resource. Use ResourceHandle::kScaleFactorNone for non-image |
187 base::RefCountedStaticMemory* LoadDataResourceBytes(int resource_id) const; | 189 // resources. Returns NULL if we fail to read the resource. |
| 190 base::RefCountedStaticMemory* LoadDataResourceBytes(int resource_id, |
| 191 float scale_factor) const; |
188 | 192 |
189 // Return the contents of a resource in a StringPiece given the resource id. | 193 // Return the contents of a resource in a StringPiece given the resource id |
190 base::StringPiece GetRawDataResource(int resource_id) const; | 194 // nearest the scale factor |scale_factor|. |
| 195 // Use ResourceHanlde::kScaleFactorNone for non-image resources. |
| 196 base::StringPiece GetRawDataResource(int resource_id, |
| 197 float scale_factor) const; |
191 | 198 |
192 // Get a localized string given a message id. Returns an empty | 199 // Get a localized string given a message id. Returns an empty |
193 // string if the message_id is not found. | 200 // string if the message_id is not found. |
194 string16 GetLocalizedString(int message_id); | 201 string16 GetLocalizedString(int message_id); |
195 | 202 |
196 // Returns the font for the specified style. | 203 // Returns the font for the specified style. |
197 const gfx::Font& GetFont(FontStyle style); | 204 const gfx::Font& GetFont(FontStyle style); |
198 | 205 |
199 // Resets and reloads the cached fonts. This is useful when the fonts of the | 206 // Resets and reloads the cached fonts. This is useful when the fonts of the |
200 // system have changed, for example, when the locale has changed. | 207 // system have changed, for example, when the locale has changed. |
201 void ReloadFonts(); | 208 void ReloadFonts(); |
202 | 209 |
203 // Overrides the path to the pak file from which the locale resources will be | 210 // Overrides the path to the pak file from which the locale resources will be |
204 // loaded. Pass an empty path to undo. | 211 // loaded. Pass an empty path to undo. |
205 void OverrideLocalePakForTest(const FilePath& pak_path); | 212 void OverrideLocalePakForTest(const FilePath& pak_path); |
206 | 213 |
207 private: | 214 private: |
208 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack); | 215 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForResourcePack); |
209 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack); | 216 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetPathForLocalePack); |
210 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetImageNamed); | 217 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetImageNamed); |
211 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetNativeImageNamed); | 218 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetNativeImageNamed); |
212 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateLoadDataResourceBytes); | 219 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateLoadDataResourceBytes); |
213 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource); | 220 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetRawDataResource); |
214 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString); | 221 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetLocalizedString); |
215 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont); | 222 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, DelegateGetFont); |
| 223 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, GetRawDataResource); |
216 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes); | 224 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes); |
217 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LocaleDataPakExists); | 225 FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LocaleDataPakExists); |
218 | 226 |
219 // Ctor/dtor are private, since we're a singleton. | 227 // Ctor/dtor are private, since we're a singleton. |
220 explicit ResourceBundle(Delegate* delegate); | 228 explicit ResourceBundle(Delegate* delegate); |
221 ~ResourceBundle(); | 229 ~ResourceBundle(); |
222 | 230 |
223 // Free skia_images_. | 231 // Free skia_images_. |
224 void FreeImages(); | 232 void FreeImages(); |
225 | 233 |
226 // Load the main resources. | 234 // Load the main resources. |
227 void LoadCommonResources(); | 235 void LoadCommonResources(); |
228 | 236 |
229 // Try to load the locale specific strings from an external data module. | 237 // Try to load the locale specific strings from an external data module. |
230 // Returns the locale that is loaded. | 238 // Returns the locale that is loaded. |
231 std::string LoadLocaleResources(const std::string& pref_locale); | 239 std::string LoadLocaleResources(const std::string& pref_locale); |
232 | 240 |
233 // Load test resources in given path. | 241 // Load test resources in given paths. If either path is empty an empty |
234 void LoadTestResources(const FilePath& path); | 242 // resource pack is loaded. |
| 243 void LoadTestResources(const FilePath& path, const FilePath& locale_path); |
235 | 244 |
236 // Unload the locale specific strings and prepares to load new ones. See | 245 // Unload the locale specific strings and prepares to load new ones. See |
237 // comments for ReloadLocaleResources(). | 246 // comments for ReloadLocaleResources(). |
238 void UnloadLocaleResources(); | 247 void UnloadLocaleResources(); |
239 | 248 |
240 // Initialize all the gfx::Font members if they haven't yet been initialized. | 249 // Initialize all the gfx::Font members if they haven't yet been initialized. |
241 void LoadFontsIfNecessary(); | 250 void LoadFontsIfNecessary(); |
242 | 251 |
243 // Returns the full pathname of the locale file to load. May return an empty | 252 // Returns the full pathname of the locale file to load. May return an empty |
244 // string if no locale data files are found. | 253 // string if no locale data files are found. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 301 |
293 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 302 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
294 }; | 303 }; |
295 | 304 |
296 } // namespace ui | 305 } // namespace ui |
297 | 306 |
298 // TODO(beng): Someday, maybe, get rid of this. | 307 // TODO(beng): Someday, maybe, get rid of this. |
299 using ui::ResourceBundle; | 308 using ui::ResourceBundle; |
300 | 309 |
301 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 310 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
OLD | NEW |