diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-09 01:07:42 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-09 01:07:42 +0000 |
commit | 4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f (patch) | |
tree | 69a1e9f78b3a5fa8b909cfab336826b09c44235f /chrome/browser/browser_theme_provider.h | |
parent | 5085ee0b4bfbe4625e63ee6975bb95702e13e0aa (diff) | |
download | chromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.zip chromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.tar.gz chromium_src-4a19063d1459a4c9c8c4c50ed86eb9048f69ea3f.tar.bz2 |
This is the first pass at themes.
This CL is paired with http://codereview.chromium.org/67284
This CL (for commit purposes) includes http://codereview.chromium.org/67284
BUG=4463,11232,11233,11234,11235
Review URL: http://codereview.chromium.org/99030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15704 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_theme_provider.h')
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h new file mode 100644 index 0000000..bf16a0d --- /dev/null +++ b/chrome/browser/browser_theme_provider.h @@ -0,0 +1,125 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_THEME_PROVIDER_H_ +#define CHROME_BROWSER_THEME_PROVIDER_H_ + +#include "app/resource_bundle.h" +#include "app/theme_provider.h" +#include "base/ref_counted.h" +#include "skia/ext/skia_utils.h" + +class Extension; +class Profile; +class DictionaryValue; + +class BrowserThemeProvider : + public base::RefCountedThreadSafe<BrowserThemeProvider>, + public ThemeProvider { + public: + BrowserThemeProvider(); + virtual ~BrowserThemeProvider(); + + enum { + COLOR_FRAME, + COLOR_FRAME_INACTIVE, + COLOR_FRAME_INCOGNITO, + COLOR_FRAME_INCOGNITO_INACTIVE, + COLOR_TOOLBAR, + COLOR_TAB_TEXT, + COLOR_BACKGROUND_TAB_TEXT, + COLOR_BOOKMARK_TEXT, + COLOR_NTP_TEXT, + COLOR_NTP_LINK, + COLOR_NTP_SECTION, + TINT_BUTTONS, + TINT_FRAME, + TINT_FRAME_INACTIVE, + TINT_FRAME_INCOGNITO, + TINT_FRAME_INCOGNITO_INACTIVE, + TINT_BACKGROUND_TAB + }; + + void Init(Profile* profile); + + // ThemeProvider implementation. + virtual SkBitmap* GetBitmapNamed(int id); + virtual SkColor GetColor(int id); + + // Set the current theme to the theme defined in |extension|. + void SetTheme(Extension* extension); + + // Reset the theme to default. + void UseDefaultTheme(); + + private: + typedef std::map<const int, std::string> ImageMap; + typedef std::map<const std::string, SkColor> ColorMap; + typedef std::map<const std::string, skia::HSL> TintMap; + + // Loads a bitmap from the theme, which may be tinted or + // otherwise modified, or an application default. + SkBitmap* LoadThemeBitmap(int id); + + // Get the specified tint - |id| is one of the TINT_* enum values. + skia::HSL GetTint(int id); + + // Tint |bitmap| with the tint specified by |hsl_id| + SkBitmap TintBitmap(const SkBitmap& bitmap, int hsl_id); + + // The following load data from specified dictionaries (either from + // preferences or from an extension manifest) and update our theme + // data appropriately. + // Allow any ResourceBundle image to be overridden. |images| should + // contain keys defined in ThemeResourceMap, and values as paths to + // the images on-disk. + void SetImageData(DictionaryValue* images, + FilePath images_path); + // Set our theme colors. The keys of |colors| are any of the kColor* + // constants, and the values are a three-item list containing 8-bit + // RGB values. + void SetColorData(DictionaryValue* colors); + // Set tint data for our images and colors. The keys of |tints| are + // any of the kTint* contstants, and the values are a three-item list + // containing real numbers in the range 0-1 (and -1 for 'null'). + void SetTintData(DictionaryValue* tints); + + // Generate any frame colors that weren't specified. + void GenerateFrameColors(); + + // Generate any frame images that weren't specified. The resulting images + // will be stored in our cache. + void GenerateFrameImages(); + + // Create any images that aren't pregenerated (e.g. background tab images). + SkBitmap* GenerateBitmap(int id); + + // Save our data - when saving images we need the original dictionary + // from the extension because it contains the text ids that we want to save. + void SaveImageData(DictionaryValue* images); + void SaveColorData(); + void SaveTintData(); + + // Let all the browser views know that themes have changed. + void NotifyThemeChanged(); + + // Load theme data from preferences. + void LoadThemePrefs(); + + // Cached images. We cache all retrieved and generated bitmaps and keep + // track of the pointers. + typedef std::map<int, SkBitmap*> ImageCache; + ImageCache image_cache_; + + ResourceBundle& rb_; + Profile* profile_; + + ImageMap images_; + ColorMap colors_; + TintMap tints_; + + DISALLOW_COPY_AND_ASSIGN(BrowserThemeProvider); +}; + +#endif // CHROME_BROWSER_THEME_PROVIDER_H_ |