| 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 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
| 18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| 21 #include "ui/base/layout.h" | 21 #include "ui/base/layout.h" |
| 22 #include "ui/base/ui_export.h" | 22 #include "ui/base/ui_export.h" |
| 23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font_list.h" |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
| 26 | 26 |
| 27 class SkBitmap; | 27 class SkBitmap; |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 class Lock; | 30 class Lock; |
| 31 class RefCountedStaticMemory; | 31 class RefCountedStaticMemory; |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // Retrieve a raw data resource. Return true if a resource was provided or | 100 // Retrieve a raw data resource. Return true if a resource was provided or |
| 101 // false to attempt retrieval of the default resource. | 101 // false to attempt retrieval of the default resource. |
| 102 virtual bool GetRawDataResource(int resource_id, | 102 virtual bool GetRawDataResource(int resource_id, |
| 103 ScaleFactor scale_factor, | 103 ScaleFactor scale_factor, |
| 104 base::StringPiece* value) = 0; | 104 base::StringPiece* value) = 0; |
| 105 | 105 |
| 106 // Retrieve a localized string. Return true if a string was provided or | 106 // Retrieve a localized string. Return true if a string was provided or |
| 107 // false to attempt retrieval of the default string. | 107 // false to attempt retrieval of the default string. |
| 108 virtual bool GetLocalizedString(int message_id, string16* value) = 0; | 108 virtual bool GetLocalizedString(int message_id, string16* value) = 0; |
| 109 | 109 |
| 110 // Return a font resource or NULL to attempt retrieval of the default | 110 // Returns a font or NULL to attempt retrieval of the default resource. |
| 111 // resource. | |
| 112 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; | 111 virtual scoped_ptr<gfx::Font> GetFont(FontStyle style) = 0; |
| 113 | 112 |
| 114 protected: | 113 protected: |
| 115 virtual ~Delegate() {} | 114 virtual ~Delegate() {} |
| 116 }; | 115 }; |
| 117 | 116 |
| 118 // Initialize the ResourceBundle for this process. Does not take ownership of | 117 // Initialize the ResourceBundle for this process. Does not take ownership of |
| 119 // the |delegate| value. Returns the language selected. | 118 // the |delegate| value. Returns the language selected. |
| 120 // NOTE: Mac ignores this and always loads up resources for the language | 119 // NOTE: Mac ignores this and always loads up resources for the language |
| 121 // defined by the Cocoa UI (i.e., NSBundle does the language work). | 120 // defined by the Cocoa UI (i.e., NSBundle does the language work). |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // nearest the scale factor |scale_factor|. | 225 // nearest the scale factor |scale_factor|. |
| 227 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources | 226 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources |
| 228 // (such as wallpaper). | 227 // (such as wallpaper). |
| 229 base::StringPiece GetRawDataResourceForScale(int resource_id, | 228 base::StringPiece GetRawDataResourceForScale(int resource_id, |
| 230 ScaleFactor scale_factor) const; | 229 ScaleFactor scale_factor) const; |
| 231 | 230 |
| 232 // Get a localized string given a message id. Returns an empty | 231 // Get a localized string given a message id. Returns an empty |
| 233 // string if the message_id is not found. | 232 // string if the message_id is not found. |
| 234 string16 GetLocalizedString(int message_id); | 233 string16 GetLocalizedString(int message_id); |
| 235 | 234 |
| 235 // Returns the font list for the specified style. |
| 236 const gfx::FontList& GetFontList(FontStyle style); |
| 237 |
| 236 // Returns the font for the specified style. | 238 // Returns the font for the specified style. |
| 237 const gfx::Font& GetFont(FontStyle style); | 239 const gfx::Font& GetFont(FontStyle style); |
| 238 | 240 |
| 239 // Resets and reloads the cached fonts. This is useful when the fonts of the | 241 // Resets and reloads the cached fonts. This is useful when the fonts of the |
| 240 // system have changed, for example, when the locale has changed. | 242 // system have changed, for example, when the locale has changed. |
| 241 void ReloadFonts(); | 243 void ReloadFonts(); |
| 242 | 244 |
| 243 // Overrides the path to the pak file from which the locale resources will be | 245 // Overrides the path to the pak file from which the locale resources will be |
| 244 // loaded. Pass an empty path to undo. | 246 // loaded. Pass an empty path to undo. |
| 245 void OverrideLocalePakForTest(const base::FilePath& pak_path); | 247 void OverrideLocalePakForTest(const base::FilePath& pak_path); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 296 |
| 295 // Load test resources in given paths. If either path is empty an empty | 297 // Load test resources in given paths. If either path is empty an empty |
| 296 // resource pack is loaded. | 298 // resource pack is loaded. |
| 297 void LoadTestResources(const base::FilePath& path, | 299 void LoadTestResources(const base::FilePath& path, |
| 298 const base::FilePath& locale_path); | 300 const base::FilePath& locale_path); |
| 299 | 301 |
| 300 // Unload the locale specific strings and prepares to load new ones. See | 302 // Unload the locale specific strings and prepares to load new ones. See |
| 301 // comments for ReloadLocaleResources(). | 303 // comments for ReloadLocaleResources(). |
| 302 void UnloadLocaleResources(); | 304 void UnloadLocaleResources(); |
| 303 | 305 |
| 304 // Initialize all the gfx::Font members if they haven't yet been initialized. | 306 // Initializes all the gfx::FontList members if they haven't yet been |
| 307 // initialized. |
| 305 void LoadFontsIfNecessary(); | 308 void LoadFontsIfNecessary(); |
| 306 | 309 |
| 310 // Returns a FontList or NULL by calling Delegate::GetFont and converting |
| 311 // scoped_ptr<gfx::Font> to scoped_ptr<gfx::FontList>. |
| 312 scoped_ptr<gfx::FontList> GetFontListFromDelegate(FontStyle style); |
| 313 |
| 307 // Fills the |bitmap| given the data file to look in and the |resource_id|. | 314 // Fills the |bitmap| given the data file to look in and the |resource_id|. |
| 308 // Returns false if the resource does not exist. | 315 // Returns false if the resource does not exist. |
| 309 // | 316 // |
| 310 // If the call succeeds, |fell_back_to_1x| indicates whether Chrome's custom | 317 // If the call succeeds, |fell_back_to_1x| indicates whether Chrome's custom |
| 311 // csCl PNG chunk is present (added by GRIT if it falls back to a 100% image). | 318 // csCl PNG chunk is present (added by GRIT if it falls back to a 100% image). |
| 312 bool LoadBitmap(const ResourceHandle& data_handle, | 319 bool LoadBitmap(const ResourceHandle& data_handle, |
| 313 int resource_id, | 320 int resource_id, |
| 314 SkBitmap* bitmap, | 321 SkBitmap* bitmap, |
| 315 bool* fell_back_to_1x) const; | 322 bool* fell_back_to_1x) const; |
| 316 | 323 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // The maximum scale factor currently loaded. | 370 // The maximum scale factor currently loaded. |
| 364 ScaleFactor max_scale_factor_; | 371 ScaleFactor max_scale_factor_; |
| 365 | 372 |
| 366 // Cached images. The ResourceBundle caches all retrieved images and keeps | 373 // Cached images. The ResourceBundle caches all retrieved images and keeps |
| 367 // ownership of the pointers. | 374 // ownership of the pointers. |
| 368 typedef std::map<int, gfx::Image> ImageMap; | 375 typedef std::map<int, gfx::Image> ImageMap; |
| 369 ImageMap images_; | 376 ImageMap images_; |
| 370 | 377 |
| 371 gfx::Image empty_image_; | 378 gfx::Image empty_image_; |
| 372 | 379 |
| 373 // The various fonts used. Cached to avoid repeated GDI creation/destruction. | 380 // The various font lists used. Cached to avoid repeated GDI |
| 374 scoped_ptr<gfx::Font> base_font_; | 381 // creation/destruction. |
| 375 scoped_ptr<gfx::Font> bold_font_; | 382 scoped_ptr<gfx::FontList> base_font_list_; |
| 376 scoped_ptr<gfx::Font> small_font_; | 383 scoped_ptr<gfx::FontList> bold_font_list_; |
| 377 scoped_ptr<gfx::Font> small_bold_font_; | 384 scoped_ptr<gfx::FontList> small_font_list_; |
| 378 scoped_ptr<gfx::Font> medium_font_; | 385 scoped_ptr<gfx::FontList> small_bold_font_list_; |
| 379 scoped_ptr<gfx::Font> medium_bold_font_; | 386 scoped_ptr<gfx::FontList> medium_font_list_; |
| 380 scoped_ptr<gfx::Font> large_font_; | 387 scoped_ptr<gfx::FontList> medium_bold_font_list_; |
| 381 scoped_ptr<gfx::Font> large_bold_font_; | 388 scoped_ptr<gfx::FontList> large_font_list_; |
| 382 scoped_ptr<gfx::Font> web_font_; | 389 scoped_ptr<gfx::FontList> large_bold_font_list_; |
| 390 scoped_ptr<gfx::FontList> web_font_list_; |
| 383 | 391 |
| 384 base::FilePath overridden_pak_path_; | 392 base::FilePath overridden_pak_path_; |
| 385 | 393 |
| 386 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 394 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
| 387 }; | 395 }; |
| 388 | 396 |
| 389 } // namespace ui | 397 } // namespace ui |
| 390 | 398 |
| 391 // TODO(beng): Someday, maybe, get rid of this. | 399 // TODO(beng): Someday, maybe, get rid of this. |
| 392 using ui::ResourceBundle; | 400 using ui::ResourceBundle; |
| 393 | 401 |
| 394 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 402 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
| OLD | NEW |