| 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_GTK_GTK_THEME_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 6 #define CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Calls |observer|.Observe() for the browser theme with this provider as the | 34 // Calls |observer|.Observe() for the browser theme with this provider as the |
| 35 // source. | 35 // source. |
| 36 void InitThemesFor(NotificationObserver* observer); | 36 void InitThemesFor(NotificationObserver* observer); |
| 37 | 37 |
| 38 // Overridden from BrowserThemeProvider: | 38 // Overridden from BrowserThemeProvider: |
| 39 // | 39 // |
| 40 // Sets that we aren't using the system theme, then calls | 40 // Sets that we aren't using the system theme, then calls |
| 41 // BrowserThemeProvider's implementation. | 41 // BrowserThemeProvider's implementation. |
| 42 virtual void Init(Profile* profile); | 42 virtual void Init(Profile* profile); |
| 43 virtual SkBitmap* GetBitmapNamed(int id) const; |
| 44 virtual SkColor GetColor(int id) const; |
| 45 virtual bool HasCustomImage(int id) const; |
| 43 virtual void SetTheme(Extension* extension); | 46 virtual void SetTheme(Extension* extension); |
| 44 virtual void UseDefaultTheme(); | 47 virtual void UseDefaultTheme(); |
| 45 virtual void SetNativeTheme(); | 48 virtual void SetNativeTheme(); |
| 46 | 49 |
| 47 // Overridden from NotificationObserver: | 50 // Overridden from NotificationObserver: |
| 48 virtual void Observe(NotificationType type, | 51 virtual void Observe(NotificationType type, |
| 49 const NotificationSource& source, | 52 const NotificationSource& source, |
| 50 const NotificationDetails& details); | 53 const NotificationDetails& details); |
| 51 | 54 |
| 52 // Creates a GtkChromeButton instance, registered with this theme provider, | 55 // Creates a GtkChromeButton instance, registered with this theme provider, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 // (hopefully) live on the X server, instead of the client so we don't have | 75 // (hopefully) live on the X server, instead of the client so we don't have |
| 73 // to send the image to the server on each expose. | 76 // to send the image to the server on each expose. |
| 74 CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); | 77 CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); |
| 75 | 78 |
| 76 // These functions do not add a ref to the returned pixbuf, and it should not
be | 79 // These functions do not add a ref to the returned pixbuf, and it should not
be |
| 77 // unreffed. | 80 // unreffed. |
| 78 // If |native| is true, get the GTK_STOCK version of the icon. | 81 // If |native| is true, get the GTK_STOCK version of the icon. |
| 79 static GdkPixbuf* GetFolderIcon(bool native); | 82 static GdkPixbuf* GetFolderIcon(bool native); |
| 80 static GdkPixbuf* GetDefaultFavicon(bool native); | 83 static GdkPixbuf* GetDefaultFavicon(bool native); |
| 81 | 84 |
| 82 protected: | 85 private: |
| 83 // Possibly creates a theme specific version of theme_toolbar_default. | 86 typedef std::map<int, SkColor> ColorMap; |
| 84 // (minimally acceptable version right now, which is just a fill of the bg | 87 typedef std::map<int, color_utils::HSL> TintMap; |
| 85 // color; this should instead invoke gtk_draw_box(...) for complex theme | 88 typedef std::map<int, SkBitmap*> ImageCache; |
| 86 // engines.) | |
| 87 virtual SkBitmap* LoadThemeBitmap(int id) const; | |
| 88 | 89 |
| 89 private: | |
| 90 // Load theme data from preferences, possibly picking colors from GTK. | 90 // Load theme data from preferences, possibly picking colors from GTK. |
| 91 virtual void LoadThemePrefs(); | 91 virtual void LoadThemePrefs(); |
| 92 | 92 |
| 93 // Let all the browser views know that themes have changed. | 93 // Let all the browser views know that themes have changed. |
| 94 virtual void NotifyThemeChanged(); | 94 virtual void NotifyThemeChanged(); |
| 95 | 95 |
| 96 // If use_gtk_ is true, completely ignores this call. Otherwise passes it to | |
| 97 // the superclass. | |
| 98 virtual void SaveThemeBitmap(const std::string resource_name, int id) const; | |
| 99 | |
| 100 // Additionally frees the CairoCachedSurfaces. | 96 // Additionally frees the CairoCachedSurfaces. |
| 101 virtual void FreePlatformCaches(); | 97 virtual void FreePlatformCaches(); |
| 102 | 98 |
| 103 // Handles signal from GTK that our theme has been changed. | 99 // Handles signal from GTK that our theme has been changed. |
| 104 static void OnStyleSet(GtkWidget* widget, | 100 static void OnStyleSet(GtkWidget* widget, |
| 105 GtkStyle* previous_style, | 101 GtkStyle* previous_style, |
| 106 GtkThemeProvider* provider); | 102 GtkThemeProvider* provider); |
| 107 | 103 |
| 108 void LoadGtkValues(); | 104 void LoadGtkValues(); |
| 109 | 105 |
| 110 // Sets the underlying theme colors/tints from a GTK color. | 106 // Sets the underlying theme colors/tints from a GTK color. |
| 111 void SetThemeColorFromGtk(const char* id, GdkColor* color); | 107 void SetThemeColorFromGtk(int id, GdkColor* color); |
| 112 void SetThemeTintFromGtk(const char* id, GdkColor* color, | 108 void SetThemeTintFromGtk(int id, GdkColor* color); |
| 113 const color_utils::HSL& default_tint); | 109 void BuildTintedFrameColor(int color_id, int tint_id); |
| 110 void SetTintToExactColor(int id, GdkColor* color); |
| 114 | 111 |
| 115 // Split out from FreePlatformCaches so it can be called in our destructor; | 112 // Split out from FreePlatformCaches so it can be called in our destructor; |
| 116 // FreePlatformCaches() is called from the BrowserThemeProvider's destructor, | 113 // FreePlatformCaches() is called from the BrowserThemeProvider's destructor, |
| 117 // but by the time ~BrowserThemeProvider() is run, the vtable no longer | 114 // but by the time ~BrowserThemeProvider() is run, the vtable no longer |
| 118 // points to GtkThemeProvider's version. | 115 // points to GtkThemeProvider's version. |
| 119 void FreePerDisplaySurfaces(); | 116 void FreePerDisplaySurfaces(); |
| 120 | 117 |
| 118 // Lazily generates each bitmap used in the gtk theme. |
| 119 SkBitmap* GenerateGtkThemeBitmap(int id) const; |
| 120 |
| 121 // Tints IDR_THEME_FRAME based based on |tint_id|. Used during lazy |
| 122 // generation of the gtk theme bitmaps. |
| 123 SkBitmap* GenerateFrameImage(int tint_id) const; |
| 124 |
| 125 // Takes the base frame image |base_id| and tints it with |tint_id|. |
| 126 SkBitmap* GenerateTabImage(int base_id) const; |
| 127 |
| 121 // A notification from the GtkChromeButton GObject destructor that we should | 128 // A notification from the GtkChromeButton GObject destructor that we should |
| 122 // remove it from our internal list. | 129 // remove it from our internal list. |
| 123 static void OnDestroyChromeButton(GtkWidget* button, | 130 static void OnDestroyChromeButton(GtkWidget* button, |
| 124 GtkThemeProvider* provider); | 131 GtkThemeProvider* provider); |
| 125 | 132 |
| 126 // Whether we should be using gtk rendering. | 133 // Whether we should be using gtk rendering. |
| 127 bool use_gtk_; | 134 bool use_gtk_; |
| 128 | 135 |
| 129 // GtkWidgets that exist only so we can look at their properties (and take | 136 // GtkWidgets that exist only so we can look at their properties (and take |
| 130 // their colors). | 137 // their colors). |
| 131 GtkWidget* fake_window_; | 138 GtkWidget* fake_window_; |
| 132 OwnedWidgetGtk fake_label_; | 139 OwnedWidgetGtk fake_label_; |
| 133 | 140 |
| 134 // A list of all GtkChromeButton instances. We hold on to these to notify | 141 // A list of all GtkChromeButton instances. We hold on to these to notify |
| 135 // them of theme changes. | 142 // them of theme changes. |
| 136 std::vector<GtkWidget*> chrome_buttons_; | 143 std::vector<GtkWidget*> chrome_buttons_; |
| 137 | 144 |
| 145 // Tints and colors calculated by LoadGtkValues() that are given to the |
| 146 // caller while |use_gtk_| is true. |
| 147 ColorMap colors_; |
| 148 TintMap tints_; |
| 149 |
| 150 // Image cache of lazily created images, created when requested by |
| 151 // GetBitmapNamed(). |
| 152 mutable ImageCache gtk_images_; |
| 153 |
| 138 // Cairo surfaces for each GdkDisplay. | 154 // Cairo surfaces for each GdkDisplay. |
| 139 typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; | 155 typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; |
| 140 typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; | 156 typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; |
| 141 PerDisplaySurfaceMap per_display_surfaces_; | 157 PerDisplaySurfaceMap per_display_surfaces_; |
| 142 | 158 |
| 143 // This is a dummy widget that only exists so we have something to pass to | 159 // This is a dummy widget that only exists so we have something to pass to |
| 144 // gtk_widget_render_icon(). | 160 // gtk_widget_render_icon(). |
| 145 static GtkWidget* icon_widget_; | 161 static GtkWidget* icon_widget_; |
| 146 | 162 |
| 147 // The default folder icon and default bookmark icon for the GTK theme. | 163 // The default folder icon and default bookmark icon for the GTK theme. |
| 148 // These are static because the system can only have one theme at a time. | 164 // These are static because the system can only have one theme at a time. |
| 149 // They are cached when they are requested the first time, and cleared when | 165 // They are cached when they are requested the first time, and cleared when |
| 150 // the system theme changes. | 166 // the system theme changes. |
| 151 static GdkPixbuf* default_folder_icon_; | 167 static GdkPixbuf* default_folder_icon_; |
| 152 static GdkPixbuf* default_bookmark_icon_; | 168 static GdkPixbuf* default_bookmark_icon_; |
| 153 }; | 169 }; |
| 154 | 170 |
| 155 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 171 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
| OLD | NEW |