diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 23:23:08 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 23:23:08 +0000 |
commit | 5fdafb2f68bd61ef92d10194402348d1e5839015 (patch) | |
tree | fb8583216c733e2a2218501646cf8c72fec35bb1 /chrome/browser/gtk/gtk_theme_provider.h | |
parent | 0735266658f996210b6f43142ce7f4c55f47ae13 (diff) | |
download | chromium_src-5fdafb2f68bd61ef92d10194402348d1e5839015.zip chromium_src-5fdafb2f68bd61ef92d10194402348d1e5839015.tar.gz chromium_src-5fdafb2f68bd61ef92d10194402348d1e5839015.tar.bz2 |
GTK Themes: Refactored to use notifications instead of manual plumbing.
- Removes large amounts of plumbing because:
- All GtkChromeButtons are constructed from GtkThemeProvider which keeps a reference to all live buttons and sends them theme change notifications.
- CustomDrawButtons now subscribe themselves to the BROWSER_THEME_CHANGED notification; this gets rid of a LOT of plubming.
- Removes the GtkThemeProperties struct; just pass the theme provider around.
- Move all the constants from the themes namespace to class statics, per tony's suggestion
Review URL: http://codereview.chromium.org/149547
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20561 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/gtk_theme_provider.h')
-rw-r--r-- | chrome/browser/gtk/gtk_theme_provider.h | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/chrome/browser/gtk/gtk_theme_provider.h b/chrome/browser/gtk/gtk_theme_provider.h index 408ba0c..ae3537e 100644 --- a/chrome/browser/gtk/gtk_theme_provider.h +++ b/chrome/browser/gtk/gtk_theme_provider.h @@ -5,7 +5,10 @@ #ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ #define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ +#include <vector> + #include "chrome/browser/browser_theme_provider.h" +#include "chrome/common/notification_observer.h" #include "skia/ext/skia_utils.h" @@ -15,26 +18,52 @@ typedef struct _GtkStyle GtkStyle; typedef struct _GtkWidget GtkWidget; // Specialization of BrowserThemeProvider which supplies system colors. -class GtkThemeProvider : public BrowserThemeProvider { +class GtkThemeProvider : public BrowserThemeProvider, + public NotificationObserver { public: + // Returns GtkThemeProvider, casted from our superclass. + static GtkThemeProvider* GetFrom(Profile* profile); + GtkThemeProvider(); virtual ~GtkThemeProvider(); + // Calls |observer|.Observe() for the browser theme with this provider as the + // source. + void InitThemesFor(NotificationObserver* observer); + // Overridden from BrowserThemeProvider: // // Sets that we aren't using the system theme, then calls // BrowserThemeProvider's implementation. + virtual void Init(Profile* profile); virtual void SetTheme(Extension* extension); virtual void UseDefaultTheme(); virtual void SetNativeTheme(); + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + // Creates a GtkChromeButton instance, registered with this theme provider, + // with a "destroy" signal to remove it from our internal list when it goes + // away. + GtkWidget* BuildChromeButton(); + // Whether we should use the GTK system theme. - static bool UseSystemThemeGraphics(Profile* profile); + bool UseGtkTheme(); + + // A wrapper around ThemeProvider::GetColor, transforming the result to a + // GdkColor. + GdkColor GetGdkColor(int id); private: // Load theme data from preferences, possibly picking colors from GTK. virtual void LoadThemePrefs(); + // Let all the browser views know that themes have changed. + virtual void NotifyThemeChanged(); + // Possibly creates a theme specific version of theme_toolbar_default. // (minimally acceptable version right now, which is just a fill of the bg // color; this should instead invoke gtk_draw_box(...) for complex theme @@ -53,25 +82,21 @@ class GtkThemeProvider : public BrowserThemeProvider { void SetThemeTintFromGtk(const char* id, GdkColor* color, const skia::HSL& default_tint); + // A notification from the GtkChromeButton GObject destructor that we should + // remove it from our internal list. + static void OnDestroyChromeButton(GtkWidget* button, + GtkThemeProvider* provider); + + // Whether we should be using gtk rendering. + bool use_gtk_; + // A GtkWidget that exists only so we can look at its properties (and take // its colors). GtkWidget* fake_window_; -}; - -// A Helper struct used throughout the GTK themeing code. It retrieves settings -// from the Profile once at creation time, instead of at every access time. A -// large motivation for making this struct is so that we only have to pass one -// parameter around when configuring things due to a theme event. This way, we -// can use a lot of GTK convenience features likt gtk_container_foreach(). -struct GtkThemeProperties { - GtkThemeProperties(Profile* profile); - - // A wrapper around ThemeProvider::GetColor, transforming the result to a - // GdkColor. - GdkColor GetGdkColor(int id); - bool use_gtk_rendering; - ThemeProvider* provider; + // A list of all GtkChromeButton instances. We hold on to these to notify + // them of theme changes. + std::vector<GtkWidget*> chrome_buttons_; }; #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |