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