Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ | 6 #define CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "app/theme_provider.h" | 13 #include "app/theme_provider.h" |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/non_thread_safe.h" | 15 #include "base/non_thread_safe.h" |
| 16 #include "base/ref_counted.h" | 16 #include "base/ref_counted.h" |
| 17 #include "skia/ext/skia_utils.h" | 17 #include "skia/ext/skia_utils.h" |
| 18 | 18 |
| 19 class Extension; | 19 class Extension; |
| 20 class Profile; | 20 class Profile; |
| 21 class DictionaryValue; | 21 class DictionaryValue; |
| 22 | 22 |
| 23 namespace themes { | |
|
tony
2009/07/07 19:47:05
:( The style guide says the namespaces name should
| |
| 24 | |
| 25 // Strings used by themes to identify colors for different parts of our UI. | |
| 26 extern const char* kColorFrame; | |
| 27 extern const char* kColorFrameInactive; | |
| 28 extern const char* kColorFrameIncognito; | |
| 29 extern const char* kColorFrameIncognitoInactive; | |
| 30 extern const char* kColorToolbar; | |
| 31 extern const char* kColorTabText; | |
| 32 extern const char* kColorBackgroundTabText; | |
| 33 extern const char* kColorBookmarkText; | |
| 34 extern const char* kColorNTPBackground; | |
| 35 extern const char* kColorNTPText; | |
| 36 extern const char* kColorNTPLink; | |
| 37 extern const char* kColorNTPSection; | |
| 38 extern const char* kColorNTPSectionText; | |
| 39 extern const char* kColorNTPSectionLink; | |
| 40 extern const char* kColorControlBackground; | |
| 41 extern const char* kColorButtonBackground; | |
| 42 | |
| 43 // Strings used by themes to identify tints to apply to different parts of | |
| 44 // our UI. The frame tints apply to the frame color and produce the | |
| 45 // COLOR_FRAME* colors. | |
| 46 extern const char* kTintButtons; | |
| 47 extern const char* kTintFrame; | |
| 48 extern const char* kTintFrameInactive; | |
| 49 extern const char* kTintFrameIncognito; | |
| 50 extern const char* kTintFrameIncognitoInactive; | |
| 51 extern const char* kTintBackgroundTab; | |
| 52 | |
| 53 // Strings used by themes to identify miscellaneous numerical properties. | |
| 54 extern const char* kDisplayPropertyNTPAlignment; | |
| 55 | |
| 56 // Strings used in alignment properties. | |
| 57 extern const char* kAlignmentTop; | |
| 58 extern const char* kAlignmentBottom; | |
| 59 extern const char* kAlignmentLeft; | |
| 60 extern const char* kAlignmentRight; | |
| 61 | |
| 62 // Default colors. | |
| 63 extern const SkColor kDefaultColorFrame; | |
| 64 extern const SkColor kDefaultColorFrameInactive; | |
| 65 extern const SkColor kDefaultColorFrameIncognito; | |
| 66 extern const SkColor kDefaultColorFrameIncognitoInactive; | |
| 67 extern const SkColor kDefaultColorToolbar; | |
| 68 extern const SkColor kDefaultColorTabText; | |
| 69 extern const SkColor kDefaultColorBackgroundTabText; | |
| 70 extern const SkColor kDefaultColorBookmarkText; | |
| 71 extern const SkColor kDefaultColorNTPBackground; | |
| 72 extern const SkColor kDefaultColorNTPText; | |
| 73 extern const SkColor kDefaultColorNTPLink; | |
| 74 extern const SkColor kDefaultColorNTPSection; | |
| 75 extern const SkColor kDefaultColorNTPSectionText; | |
| 76 extern const SkColor kDefaultColorNTPSectionLink; | |
| 77 extern const SkColor kDefaultColorControlBackground; | |
| 78 extern const SkColor kDefaultColorButtonBackground; | |
| 79 | |
| 80 extern const skia::HSL kDefaultTintButtons; | |
| 81 extern const skia::HSL kDefaultTintFrame; | |
| 82 extern const skia::HSL kDefaultTintFrameInactive; | |
| 83 extern const skia::HSL kDefaultTintFrameIncognito; | |
| 84 extern const skia::HSL kDefaultTintFrameIncognitoInactive; | |
| 85 extern const skia::HSL kDefaultTintBackgroundTab; | |
| 86 } // namespace themes | |
| 87 | |
| 23 class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, | 88 class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, |
| 24 public NonThreadSafe, | 89 public NonThreadSafe, |
| 25 public ThemeProvider { | 90 public ThemeProvider { |
| 26 public: | 91 public: |
| 27 BrowserThemeProvider(); | 92 BrowserThemeProvider(); |
| 28 virtual ~BrowserThemeProvider(); | 93 virtual ~BrowserThemeProvider(); |
| 29 | 94 |
| 30 enum { | 95 enum { |
| 31 COLOR_FRAME, | 96 COLOR_FRAME, |
| 32 COLOR_FRAME_INACTIVE, | 97 COLOR_FRAME_INACTIVE, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 virtual bool ShouldUseNativeFrame(); | 136 virtual bool ShouldUseNativeFrame(); |
| 72 virtual bool HasCustomImage(int id); | 137 virtual bool HasCustomImage(int id); |
| 73 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) | 138 #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) |
| 74 virtual GdkPixbuf* GetPixbufNamed(int id); | 139 virtual GdkPixbuf* GetPixbufNamed(int id); |
| 75 #elif defined(OS_MACOSX) | 140 #elif defined(OS_MACOSX) |
| 76 virtual NSImage* GetNSImageNamed(int id); | 141 virtual NSImage* GetNSImageNamed(int id); |
| 77 virtual NSColor* GetNSColorTint(int id); | 142 virtual NSColor* GetNSColorTint(int id); |
| 78 #endif | 143 #endif |
| 79 | 144 |
| 80 // Set the current theme to the theme defined in |extension|. | 145 // Set the current theme to the theme defined in |extension|. |
| 81 void SetTheme(Extension* extension); | 146 virtual void SetTheme(Extension* extension); |
| 82 | 147 |
| 83 // Reset the theme to default. | 148 // Reset the theme to default. |
| 84 void UseDefaultTheme(); | 149 virtual void UseDefaultTheme(); |
| 150 | |
| 151 // Set the current theme to the native theme. On some platforms, the native | |
| 152 // theme is the default theme. | |
| 153 virtual void SetNativeTheme() { UseDefaultTheme(); } | |
| 85 | 154 |
| 86 // Convert a bitfield alignment into a string like "top left". Public so that | 155 // Convert a bitfield alignment into a string like "top left". Public so that |
| 87 // it can be used to generate CSS values. Takes a bitfield of AlignmentMasks. | 156 // it can be used to generate CSS values. Takes a bitfield of AlignmentMasks. |
| 88 static std::string AlignmentToString(int alignment); | 157 static std::string AlignmentToString(int alignment); |
| 89 | 158 |
| 90 // Parse alignments from something like "top left" into a bitfield of | 159 // Parse alignments from something like "top left" into a bitfield of |
| 91 // AlignmentMasks | 160 // AlignmentMasks |
| 92 static int StringToAlignment(const std::string &alignment); | 161 static int StringToAlignment(const std::string &alignment); |
| 93 | 162 |
| 163 protected: | |
| 164 // Sets an individual color value. | |
| 165 void SetColor(const char* id, const SkColor& color); | |
| 166 | |
| 167 // Sets an individual tint value. | |
| 168 void SetTint(const char* id, const skia::HSL& tint); | |
| 169 | |
| 170 // Generate any frame colors that weren't specified. | |
| 171 void GenerateFrameColors(); | |
| 172 | |
| 173 // Generate any frame images that weren't specified. The resulting images | |
| 174 // will be stored in our cache. | |
| 175 void GenerateFrameImages(); | |
| 176 | |
| 177 // Clears all the override fields and saves the dictionary. | |
| 178 void ClearAllThemeData(); | |
| 179 | |
| 180 // Load theme data from preferences. | |
| 181 virtual void LoadThemePrefs(); | |
| 182 | |
| 183 // Let all the browser views know that themes have changed. | |
| 184 void NotifyThemeChanged(); | |
| 185 | |
| 186 // Loads a bitmap from the theme, which may be tinted or | |
| 187 // otherwise modified, or an application default. | |
| 188 virtual SkBitmap* LoadThemeBitmap(int id); | |
| 189 | |
| 190 Profile* profile() { return profile_; } | |
| 191 | |
| 94 private: | 192 private: |
| 95 typedef std::map<const int, std::string> ImageMap; | 193 typedef std::map<const int, std::string> ImageMap; |
| 96 typedef std::map<const std::string, SkColor> ColorMap; | 194 typedef std::map<const std::string, SkColor> ColorMap; |
| 97 typedef std::map<const std::string, skia::HSL> TintMap; | 195 typedef std::map<const std::string, skia::HSL> TintMap; |
| 98 typedef std::map<const std::string, int> DisplayPropertyMap; | 196 typedef std::map<const std::string, int> DisplayPropertyMap; |
| 99 | 197 |
| 100 // Reads the image data from the theme file into the specified vector. Returns | 198 // Reads the image data from the theme file into the specified vector. Returns |
| 101 // true on success. | 199 // true on success. |
| 102 bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data); | 200 bool ReadThemeFileData(int id, std::vector<unsigned char>* raw_data); |
| 103 | 201 |
| 104 // Loads a bitmap from the theme, which may be tinted or | |
| 105 // otherwise modified, or an application default. | |
| 106 SkBitmap* LoadThemeBitmap(int id); | |
| 107 | |
| 108 // Returns the string key for the given tint |id| TINT_* enum value. | 202 // Returns the string key for the given tint |id| TINT_* enum value. |
| 109 const std::string GetTintKey(int id); | 203 const std::string GetTintKey(int id); |
| 110 | 204 |
| 111 // Returns the default tint for the given tint |id| TINT_* enum value. | 205 // Returns the default tint for the given tint |id| TINT_* enum value. |
| 112 skia::HSL GetDefaultTint(int id); | 206 skia::HSL GetDefaultTint(int id); |
| 113 | 207 |
| 114 // Get the specified tint - |id| is one of the TINT_* enum values. | 208 // Get the specified tint - |id| is one of the TINT_* enum values. |
| 115 skia::HSL GetTint(int id); | 209 skia::HSL GetTint(int id); |
| 116 | 210 |
| 117 // Tint |bitmap| with the tint specified by |hsl_id| | 211 // Tint |bitmap| with the tint specified by |hsl_id| |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 132 | 226 |
| 133 // Set tint data for our images and colors. The keys of |tints| are | 227 // Set tint data for our images and colors. The keys of |tints| are |
| 134 // any of the kTint* contstants, and the values are a three-item list | 228 // any of the kTint* contstants, and the values are a three-item list |
| 135 // containing real numbers in the range 0-1 (and -1 for 'null'). | 229 // containing real numbers in the range 0-1 (and -1 for 'null'). |
| 136 void SetTintData(DictionaryValue* tints); | 230 void SetTintData(DictionaryValue* tints); |
| 137 | 231 |
| 138 // Set miscellaneous display properties. While these can be defined as | 232 // Set miscellaneous display properties. While these can be defined as |
| 139 // strings, they are currently stored as integers. | 233 // strings, they are currently stored as integers. |
| 140 void SetDisplayPropertyData(DictionaryValue* display_properties); | 234 void SetDisplayPropertyData(DictionaryValue* display_properties); |
| 141 | 235 |
| 142 // Generate any frame colors that weren't specified. | |
| 143 void GenerateFrameColors(); | |
| 144 | |
| 145 // Generate any frame images that weren't specified. The resulting images | |
| 146 // will be stored in our cache. | |
| 147 void GenerateFrameImages(); | |
| 148 | |
| 149 // Create any images that aren't pregenerated (e.g. background tab images). | 236 // Create any images that aren't pregenerated (e.g. background tab images). |
| 150 SkBitmap* GenerateBitmap(int id); | 237 SkBitmap* GenerateBitmap(int id); |
| 151 | 238 |
| 152 // Save our data - when saving images we need the original dictionary | 239 // Save our data - when saving images we need the original dictionary |
| 153 // from the extension because it contains the text ids that we want to save. | 240 // from the extension because it contains the text ids that we want to save. |
| 154 void SaveImageData(DictionaryValue* images); | 241 void SaveImageData(DictionaryValue* images); |
| 155 void SaveColorData(); | 242 void SaveColorData(); |
| 156 void SaveTintData(); | 243 void SaveTintData(); |
| 157 void SaveDisplayPropertyData(); | 244 void SaveDisplayPropertyData(); |
| 158 | 245 |
| 159 // Let all the browser views know that themes have changed. | |
| 160 void NotifyThemeChanged(); | |
| 161 | |
| 162 // Load theme data from preferences. | |
| 163 void LoadThemePrefs(); | |
| 164 | |
| 165 SkColor FindColor(const char* id, SkColor default_color); | 246 SkColor FindColor(const char* id, SkColor default_color); |
| 166 | 247 |
| 167 // Frees generated images and clears the image cache. | 248 // Frees generated images and clears the image cache. |
| 168 void ClearCaches(); | 249 void ClearCaches(); |
| 169 | 250 |
| 170 // Clears the platform-specific caches. Do not call directly; it's called | 251 // Clears the platform-specific caches. Do not call directly; it's called |
| 171 // from ClearCaches(). | 252 // from ClearCaches(). |
| 172 void FreePlatformCaches(); | 253 void FreePlatformCaches(); |
| 173 | 254 |
| 174 // Cached images. We cache all retrieved and generated bitmaps and keep | 255 // Cached images. We cache all retrieved and generated bitmaps and keep |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 191 | 272 |
| 192 ImageMap images_; | 273 ImageMap images_; |
| 193 ColorMap colors_; | 274 ColorMap colors_; |
| 194 TintMap tints_; | 275 TintMap tints_; |
| 195 DisplayPropertyMap display_properties_; | 276 DisplayPropertyMap display_properties_; |
| 196 | 277 |
| 197 DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); | 278 DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); |
| 198 }; | 279 }; |
| 199 | 280 |
| 200 #endif // CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ | 281 #endif // CHROME_BROWSER_BROWSER_THEME_PROVIDER_H_ |
| OLD | NEW |