Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/ui/gtk/theme_service_gtk.h

Issue 10337010: Revert r123782. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/gtk/task_manager_gtk.cc ('k') | chrome/browser/ui/gtk/theme_service_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_GTK_THEME_SERVICE_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_THEME_SERVICE_GTK_H_
7 #pragma once
8
9 #include <map>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/prefs/pref_change_registrar.h"
15 #include "chrome/browser/themes/theme_service.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "ui/base/glib/glib_integers.h"
18 #include "ui/base/gtk/gtk_signal.h"
19 #include "ui/base/gtk/owned_widget_gtk.h"
20 #include "ui/gfx/color_utils.h"
21
22 class Profile;
23
24 namespace gfx {
25 class CairoCachedSurface;
26 }
27
28 namespace ui {
29 class GtkSignalRegistrar;
30 }
31
32 typedef struct _GdkDisplay GdkDisplay;
33 typedef struct _GdkEventExpose GdkEventExpose;
34 typedef struct _GdkPixbuf GdkPixbuf;
35 typedef struct _GtkIconSet GtkIconSet;
36 typedef struct _GtkStyle GtkStyle;
37 typedef struct _GtkWidget GtkWidget;
38
39 // Specialization of ThemeService which supplies system colors.
40 class ThemeServiceGtk : public ThemeService {
41 public:
42 // A list of integer keys for a separate PerDisplaySurfaceMap that keeps
43 // what would otherwise be static icons on the X11 server.
44 enum CairoDefaultIcon {
45 NATIVE_FAVICON = 1,
46 CHROME_FAVICON,
47 NATIVE_FOLDER,
48 CHROME_FOLDER
49 };
50
51 // Returns ThemeServiceGtk, casted from our superclass.
52 static ThemeServiceGtk* GetFrom(Profile* profile);
53
54 ThemeServiceGtk();
55 virtual ~ThemeServiceGtk();
56
57 // Calls |observer|.Observe() for the browser theme with this provider as the
58 // source.
59 void InitThemesFor(content::NotificationObserver* observer);
60
61 // Overridden from ThemeService:
62 //
63 // Sets that we aren't using the system theme, then calls
64 // ThemeService's implementation.
65 virtual void Init(Profile* profile) OVERRIDE;
66 virtual SkBitmap* GetBitmapNamed(int id) const OVERRIDE;
67 virtual const gfx::Image* GetImageNamed(int id) const OVERRIDE;
68 virtual SkColor GetColor(int id) const OVERRIDE;
69 virtual bool HasCustomImage(int id) const OVERRIDE;
70 virtual void SetTheme(const Extension* extension) OVERRIDE;
71 virtual void UseDefaultTheme() OVERRIDE;
72 virtual void SetNativeTheme() OVERRIDE;
73 virtual bool UsingDefaultTheme() const OVERRIDE;
74 virtual bool UsingNativeTheme() const OVERRIDE;
75
76 // Overridden from ThemeService, content::NotificationObserver:
77 virtual void Observe(int type,
78 const content::NotificationSource& source,
79 const content::NotificationDetails& details) OVERRIDE;
80
81 // Creates a GtkChromeButton instance, registered with this theme provider,
82 // with a "destroy" signal to remove it from our internal list when it goes
83 // away.
84 GtkWidget* BuildChromeButton();
85
86 // Creates a GtkChromeLinkButton instance. We update its state as theme
87 // changes, and listen for its destruction.
88 GtkWidget* BuildChromeLinkButton(const std::string& text);
89
90 // Builds a GtkLabel that is |color| in chrome theme mode, and the normal
91 // text color in gtk-mode. Like the previous two calls, listens for the
92 // object's destruction.
93 GtkWidget* BuildLabel(const std::string& text, GdkColor color);
94
95 // Creates a theme-aware vertical separator widget.
96 GtkWidget* CreateToolbarSeparator();
97
98 // A wrapper around ui::ThemeProvider::GetColor, transforming the result to a
99 // GdkColor.
100 GdkColor GetGdkColor(int id) const;
101
102 // A weighted average between the text color and the background color of a
103 // label. Used for borders between GTK stuff and the webcontent.
104 GdkColor GetBorderColor() const;
105
106 // Returns a set of icons tinted for different GtkStateTypes based on the
107 // label colors for the IDR resource |id|.
108 GtkIconSet* GetIconSetForId(int id) const;
109
110 // This method returns the colors webkit will use for the scrollbars. When no
111 // colors are specified by the GTK+ theme, this function averages of the
112 // thumb part and of the track colors.
113 void GetScrollbarColors(GdkColor* thumb_active_color,
114 GdkColor* thumb_inactive_color,
115 GdkColor* track_color);
116
117 // Expose the inner label. Only used for testing.
118 GtkWidget* fake_label() { return fake_label_.get(); }
119
120 // Returns colors that we pass to webkit to match the system theme.
121 SkColor get_focus_ring_color() const { return focus_ring_color_; }
122 SkColor get_thumb_active_color() const { return thumb_active_color_; }
123 SkColor get_thumb_inactive_color() const { return thumb_inactive_color_; }
124 SkColor get_track_color() const { return track_color_; }
125 SkColor get_active_selection_bg_color() const {
126 return active_selection_bg_color_;
127 }
128 SkColor get_active_selection_fg_color() const {
129 return active_selection_fg_color_;
130 }
131 SkColor get_inactive_selection_bg_color() const {
132 return inactive_selection_bg_color_;
133 }
134 SkColor get_inactive_selection_fg_color() const {
135 return inactive_selection_fg_color_;
136 }
137
138 // These functions return an image that is not owned by the caller and should
139 // not be deleted. If |native| is true, get the GTK_STOCK version of the
140 // icon.
141 static gfx::Image* GetFolderIcon(bool native);
142 static gfx::Image* GetDefaultFavicon(bool native);
143
144 // Whether we use the GTK theme by default in the current desktop
145 // environment. Returns true when we GTK defaults to on.
146 static bool DefaultUsesSystemTheme();
147
148 private:
149 typedef std::map<int, SkColor> ColorMap;
150 typedef std::map<int, color_utils::HSL> TintMap;
151 typedef std::map<int, gfx::Image*> ImageCache;
152
153 // Clears all the GTK color overrides.
154 virtual void ClearAllThemeData() OVERRIDE;
155
156 // Load theme data from preferences, possibly picking colors from GTK.
157 virtual void LoadThemePrefs() OVERRIDE;
158
159 // Let all the browser views know that themes have changed.
160 virtual void NotifyThemeChanged() OVERRIDE;
161
162 // Additionally frees the CairoCachedSurfaces.
163 virtual void FreePlatformCaches() OVERRIDE;
164
165 // Extracts colors and tints from the GTK theme, both for the
166 // ThemeService interface and the colors we send to webkit.
167 void LoadGtkValues();
168
169 // Reads in explicit theme frame colors from the ChromeGtkFrame style class
170 // or generates them per our fallback algorithm.
171 GdkColor BuildFrameColors(GtkStyle* frame_style);
172
173 // Sets the values that we send to webkit to safe defaults.
174 void LoadDefaultValues();
175
176 // Builds all of the tinted menus images needed for custom buttons. This is
177 // always called on style-set even if we aren't using the gtk-theme because
178 // the menus are always rendered with gtk colors.
179 void RebuildMenuIconSets();
180
181 // Sets the underlying theme colors/tints from a GTK color.
182 void SetThemeColorFromGtk(int id, const GdkColor* color);
183 void SetThemeTintFromGtk(int id, const GdkColor* color);
184
185 // Creates and returns a frame color, either using |gtk_base| verbatim if
186 // non-NULL, or tinting |base| with |tint|. Also sets |color_id| and
187 // |tint_id| to the returned color.
188 GdkColor BuildAndSetFrameColor(const GdkColor* base,
189 const GdkColor* gtk_base,
190 const color_utils::HSL& tint,
191 int color_id,
192 int tint_id);
193
194 // Frees all the created GtkIconSets we use for the chrome menu.
195 void FreeIconSets();
196
197 // Lazily generates each bitmap used in the gtk theme.
198 SkBitmap* GenerateGtkThemeBitmap(int id) const;
199
200 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this
201 // creates a theme configurable gradient ending with |color_id| at the
202 // bottom, and |gradient_name| at the top if that color is specified in the
203 // theme.
204 SkBitmap* GenerateFrameImage(int color_id,
205 const char* gradient_name) const;
206
207 // Takes the base frame image |base_id| and tints it with |tint_id|.
208 SkBitmap* GenerateTabImage(int base_id) const;
209
210 // Tints an icon based on tint.
211 SkBitmap* GenerateTintedIcon(int base_id,
212 const color_utils::HSL& tint) const;
213
214 // Returns the tint for buttons that contrasts with the normal window
215 // background color.
216 void GetNormalButtonTintHSL(color_utils::HSL* tint) const;
217
218 // Returns a tint that's the color of the current normal text in an entry.
219 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const;
220
221 // Returns a tint that's the color of the current highlighted text in an
222 // entry.
223 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const;
224
225 // Handles signal from GTK that our theme has been changed.
226 CHROMEGTK_CALLBACK_1(ThemeServiceGtk, void, OnStyleSet, GtkStyle*);
227
228 // A notification from various GObject destructors that we should
229 // remove it from our internal list.
230 CHROMEGTK_CALLBACK_0(ThemeServiceGtk, void, OnDestroyChromeButton);
231 CHROMEGTK_CALLBACK_0(ThemeServiceGtk, void, OnDestroyChromeLinkButton);
232 CHROMEGTK_CALLBACK_0(ThemeServiceGtk, void, OnDestroyLabel);
233
234 CHROMEGTK_CALLBACK_1(ThemeServiceGtk, gboolean, OnSeparatorExpose,
235 GdkEventExpose*);
236
237 // Whether we should be using gtk rendering.
238 bool use_gtk_;
239
240 // GtkWidgets that exist only so we can look at their properties (and take
241 // their colors).
242 GtkWidget* fake_window_;
243 GtkWidget* fake_frame_;
244 ui::OwnedWidgetGtk fake_label_;
245 ui::OwnedWidgetGtk fake_entry_;
246 ui::OwnedWidgetGtk fake_menu_item_;
247
248 // A list of diferent types of widgets that we hold on to these to notify
249 // them of theme changes. We do not own these and listen for their
250 // destruction via OnDestory{ChromeButton,ChromeLinkButton,Label}.
251 std::vector<GtkWidget*> chrome_buttons_;
252 std::vector<GtkWidget*> link_buttons_;
253 std::map<GtkWidget*, GdkColor> labels_;
254
255 // Tracks all the signals we have connected to on various widgets.
256 scoped_ptr<ui::GtkSignalRegistrar> signals_;
257
258 // Tints and colors calculated by LoadGtkValues() that are given to the
259 // caller while |use_gtk_| is true.
260 ColorMap colors_;
261 TintMap tints_;
262
263 // Colors used to tint certain icons.
264 color_utils::HSL button_tint_;
265 color_utils::HSL entry_tint_;
266 color_utils::HSL selected_entry_tint_;
267
268 // Colors that we pass to WebKit. These are generated each time the theme
269 // changes.
270 SkColor focus_ring_color_;
271 SkColor thumb_active_color_;
272 SkColor thumb_inactive_color_;
273 SkColor track_color_;
274 SkColor active_selection_bg_color_;
275 SkColor active_selection_fg_color_;
276 SkColor inactive_selection_bg_color_;
277 SkColor inactive_selection_fg_color_;
278
279 // A GtkIconSet that has the tinted icons for the NORMAL and PRELIGHT states
280 // of the IDR_FULLSCREEN_MENU_BUTTON tinted to the respective menu item label
281 // colors.
282 GtkIconSet* fullscreen_icon_set_;
283
284 // Image cache of lazily created images, created when requested by
285 // GetBitmapNamed().
286 mutable ImageCache gtk_images_;
287
288 PrefChangeRegistrar registrar_;
289
290 // This is a dummy widget that only exists so we have something to pass to
291 // gtk_widget_render_icon().
292 static GtkWidget* icon_widget_;
293
294 // The default folder icon and default bookmark icon for the GTK theme.
295 // These are static because the system can only have one theme at a time.
296 // They are cached when they are requested the first time, and cleared when
297 // the system theme changes.
298 static gfx::Image* default_folder_icon_;
299 static gfx::Image* default_bookmark_icon_;
300 };
301
302 #endif // CHROME_BROWSER_UI_GTK_THEME_SERVICE_GTK_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/task_manager_gtk.cc ('k') | chrome/browser/ui/gtk/theme_service_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698