| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_RESOURCE_BUNDLE_H__ | 5 #ifndef CHROME_COMMON_RESOURCE_BUNDLE_H__ |
| 6 #define CHROME_COMMON_RESOURCE_BUNDLE_H__ | 6 #define CHROME_COMMON_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 | 21 |
| 22 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 23 namespace base { | 23 namespace base { |
| 24 class DataPack; | 24 class DataPack; |
| 25 }; | 25 }; |
| 26 #endif |
| 27 #if defined(OS_LINUX) |
| 26 typedef struct _GdkPixbuf GdkPixbuf; | 28 typedef struct _GdkPixbuf GdkPixbuf; |
| 27 #endif | 29 #endif |
| 28 class ChromeFont; | 30 class ChromeFont; |
| 29 class SkBitmap; | 31 class SkBitmap; |
| 30 class StringPiece; | 32 class StringPiece; |
| 31 | 33 |
| 32 // ResourceBundle is a central facility to load images and other resources, | 34 // ResourceBundle is a central facility to load images and other resources, |
| 33 // such as theme graphics. | 35 // such as theme graphics. |
| 34 // Every resource is loaded only once. | 36 // Every resource is loaded only once. |
| 35 class ResourceBundle { | 37 class ResourceBundle { |
| 36 public: | 38 public: |
| 37 // An enumeration of the various font styles used throughout Chrome. | 39 // An enumeration of the various font styles used throughout Chrome. |
| 38 // The following holds true for the font sizes: | 40 // The following holds true for the font sizes: |
| 39 // Small <= Base <= Medium <= MediumBold <= Large. | 41 // Small <= Base <= Medium <= MediumBold <= Large. |
| 40 enum FontStyle { | 42 enum FontStyle { |
| 41 SmallFont, | 43 SmallFont, |
| 42 BaseFont, | 44 BaseFont, |
| 43 MediumFont, | 45 MediumFont, |
| 44 // NOTE: depending upon the locale, this may *not* result in a bold font. | 46 // NOTE: depending upon the locale, this may *not* result in a bold font. |
| 45 MediumBoldFont, | 47 MediumBoldFont, |
| 46 LargeFont, | 48 LargeFont, |
| 47 WebFont | 49 WebFont |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 // Initialize the ResourceBundle for this process. | 52 // Initialize the ResourceBundle for this process. |
| 53 // NOTE: Mac ignores this and always loads up resources for the language |
| 54 // defined by the Cocoa UI (ie-NSBundle does the langange work). |
| 51 static void InitSharedInstance(const std::wstring& pref_locale); | 55 static void InitSharedInstance(const std::wstring& pref_locale); |
| 52 | 56 |
| 53 // Delete the ResourceBundle for this process if it exists. | 57 // Delete the ResourceBundle for this process if it exists. |
| 54 static void CleanupSharedInstance(); | 58 static void CleanupSharedInstance(); |
| 55 | 59 |
| 56 // Return the global resource loader instance. | 60 // Return the global resource loader instance. |
| 57 static ResourceBundle& GetSharedInstance(); | 61 static ResourceBundle& GetSharedInstance(); |
| 58 | 62 |
| 59 // Load the data file that contains theme resources if present. | 63 // Load the data file that contains theme resources if present. |
| 60 void LoadThemeResources(); | 64 void LoadThemeResources(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Load a theme image as a GdkPixbuf. | 117 // Load a theme image as a GdkPixbuf. |
| 114 GdkPixbuf* LoadPixbuf(int resource_id); | 118 GdkPixbuf* LoadPixbuf(int resource_id); |
| 115 #endif | 119 #endif |
| 116 | 120 |
| 117 private: | 121 private: |
| 118 // We define a DataHandle typedef to abstract across how data is stored | 122 // We define a DataHandle typedef to abstract across how data is stored |
| 119 // across platforms. | 123 // across platforms. |
| 120 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
| 121 // Windows stores resources in DLLs, which are managed by HINSTANCE. | 125 // Windows stores resources in DLLs, which are managed by HINSTANCE. |
| 122 typedef HINSTANCE DataHandle; | 126 typedef HINSTANCE DataHandle; |
| 123 #elif defined(OS_LINUX) | 127 #elif defined(OS_LINUX) || defined(OS_MACOSX) |
| 124 // Linux uses base::DataPack. | 128 // Linux uses base::DataPack. |
| 125 typedef base::DataPack* DataHandle; | 129 typedef base::DataPack* DataHandle; |
| 126 #elif defined(OS_MACOSX) | |
| 127 // TODO(port): Implement resource loading on OS X. | |
| 128 typedef void* DataHandle; | |
| 129 #endif | 130 #endif |
| 130 | 131 |
| 131 // Ctor/dtor are private, since we're a singleton. | 132 // Ctor/dtor are private, since we're a singleton. |
| 132 ResourceBundle(); | 133 ResourceBundle(); |
| 133 ~ResourceBundle(); | 134 ~ResourceBundle(); |
| 134 | 135 |
| 135 // Free skia_images_. | 136 // Free skia_images_. |
| 136 void FreeImages(); | 137 void FreeImages(); |
| 137 | 138 |
| 138 // Try to load the main resources and the locale specific strings from an | 139 // Try to load the main resources and the locale specific strings from an |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 scoped_ptr<ChromeFont> large_font_; | 181 scoped_ptr<ChromeFont> large_font_; |
| 181 scoped_ptr<ChromeFont> web_font_; | 182 scoped_ptr<ChromeFont> web_font_; |
| 182 | 183 |
| 183 static ResourceBundle* g_shared_instance_; | 184 static ResourceBundle* g_shared_instance_; |
| 184 | 185 |
| 185 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); | 186 DISALLOW_EVIL_CONSTRUCTORS(ResourceBundle); |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 #endif // CHROME_COMMON_RESOURCE_BUNDLE_H__ | 189 #endif // CHROME_COMMON_RESOURCE_BUNDLE_H__ |
| 189 | 190 |
| OLD | NEW |