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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 GdkColor GetGdkColor(int id) const; | 65 GdkColor GetGdkColor(int id) const; |
66 | 66 |
67 // A weighted average between the text color and the background color of a | 67 // A weighted average between the text color and the background color of a |
68 // label. Used for borders between GTK stuff and the webcontent. | 68 // label. Used for borders between GTK stuff and the webcontent. |
69 GdkColor GetBorderColor() const; | 69 GdkColor GetBorderColor() const; |
70 | 70 |
71 // This method returns averages of the thumb part and of the track colors. | 71 // This method returns averages of the thumb part and of the track colors. |
72 // Used when rendering scrollbars. | 72 // Used when rendering scrollbars. |
73 static void GetScrollbarColors(GdkColor* thumb_active_color, | 73 static void GetScrollbarColors(GdkColor* thumb_active_color, |
74 GdkColor* thumb_inactive_color, | 74 GdkColor* thumb_inactive_color, |
75 GdkColor* track_color, | 75 GdkColor* track_color); |
76 bool use_gtk_theme); | |
77 | 76 |
78 // Expose the inner label. Only used for testing. | 77 // Expose the inner label. Only used for testing. |
79 GtkWidget* fake_label() { return fake_label_.get(); } | 78 GtkWidget* fake_label() { return fake_label_.get(); } |
80 | 79 |
81 // Returns a CairoCachedSurface for a particular Display. CairoCachedSurfaces | 80 // Returns a CairoCachedSurface for a particular Display. CairoCachedSurfaces |
82 // (hopefully) live on the X server, instead of the client so we don't have | 81 // (hopefully) live on the X server, instead of the client so we don't have |
83 // to send the image to the server on each expose. | 82 // to send the image to the server on each expose. |
84 CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); | 83 CairoCachedSurface* GetSurfaceNamed(int id, GtkWidget* widget_on_display); |
85 | 84 |
86 // These functions do not add a ref to the returned pixbuf, and it should not
be | 85 // Returns colors that we pass to webkit to match the system theme. |
87 // unreffed. | 86 const SkColor& get_focus_ring_color() const { return focus_ring_color_; } |
88 // If |native| is true, get the GTK_STOCK version of the icon. | 87 const SkColor& get_thumb_active_color() const { return thumb_active_color_; } |
| 88 const SkColor& get_thumb_inactive_color() const { |
| 89 return thumb_inactive_color_; |
| 90 } |
| 91 const SkColor& get_track_color() const { return track_color_; } |
| 92 |
| 93 // These functions do not add a ref to the returned pixbuf, and it should not |
| 94 // be unreffed. If |native| is true, get the GTK_STOCK version of the icon. |
89 static GdkPixbuf* GetFolderIcon(bool native); | 95 static GdkPixbuf* GetFolderIcon(bool native); |
90 static GdkPixbuf* GetDefaultFavicon(bool native); | 96 static GdkPixbuf* GetDefaultFavicon(bool native); |
91 | 97 |
92 private: | 98 private: |
93 typedef std::map<int, SkColor> ColorMap; | 99 typedef std::map<int, SkColor> ColorMap; |
94 typedef std::map<int, color_utils::HSL> TintMap; | 100 typedef std::map<int, color_utils::HSL> TintMap; |
95 typedef std::map<int, SkBitmap*> ImageCache; | 101 typedef std::map<int, SkBitmap*> ImageCache; |
96 | 102 |
97 // Load theme data from preferences, possibly picking colors from GTK. | 103 // Load theme data from preferences, possibly picking colors from GTK. |
98 virtual void LoadThemePrefs(); | 104 virtual void LoadThemePrefs(); |
99 | 105 |
100 // Let all the browser views know that themes have changed. | 106 // Let all the browser views know that themes have changed. |
101 virtual void NotifyThemeChanged(); | 107 virtual void NotifyThemeChanged(); |
102 | 108 |
103 // Additionally frees the CairoCachedSurfaces. | 109 // Additionally frees the CairoCachedSurfaces. |
104 virtual void FreePlatformCaches(); | 110 virtual void FreePlatformCaches(); |
105 | 111 |
106 // Handles signal from GTK that our theme has been changed. | 112 // Handles signal from GTK that our theme has been changed. |
107 static void OnStyleSet(GtkWidget* widget, | 113 static void OnStyleSet(GtkWidget* widget, |
108 GtkStyle* previous_style, | 114 GtkStyle* previous_style, |
109 GtkThemeProvider* provider); | 115 GtkThemeProvider* provider); |
110 | 116 |
| 117 // Extracts colors and tints from the GTK theme, both for the |
| 118 // BrowserThemeProvider interface and the colors we send to webkit. |
111 void LoadGtkValues(); | 119 void LoadGtkValues(); |
112 | 120 |
| 121 // Sets the values that we send to webkit to safe defaults. |
| 122 void LoadDefaultValues(); |
| 123 |
113 // Sets the underlying theme colors/tints from a GTK color. | 124 // Sets the underlying theme colors/tints from a GTK color. |
114 void SetThemeColorFromGtk(int id, GdkColor* color); | 125 void SetThemeColorFromGtk(int id, GdkColor* color); |
115 void SetThemeTintFromGtk(int id, GdkColor* color); | 126 void SetThemeTintFromGtk(int id, GdkColor* color); |
116 void BuildTintedFrameColor(int color_id, int tint_id); | 127 void BuildTintedFrameColor(int color_id, int tint_id); |
117 void SetTintToExactColor(int id, GdkColor* color); | 128 void SetTintToExactColor(int id, GdkColor* color); |
118 | 129 |
119 // Split out from FreePlatformCaches so it can be called in our destructor; | 130 // Split out from FreePlatformCaches so it can be called in our destructor; |
120 // FreePlatformCaches() is called from the BrowserThemeProvider's destructor, | 131 // FreePlatformCaches() is called from the BrowserThemeProvider's destructor, |
121 // but by the time ~BrowserThemeProvider() is run, the vtable no longer | 132 // but by the time ~BrowserThemeProvider() is run, the vtable no longer |
122 // points to GtkThemeProvider's version. | 133 // points to GtkThemeProvider's version. |
(...skipping 24 matching lines...) Expand all Loading... |
147 | 158 |
148 // A list of all GtkChromeButton instances. We hold on to these to notify | 159 // A list of all GtkChromeButton instances. We hold on to these to notify |
149 // them of theme changes. | 160 // them of theme changes. |
150 std::vector<GtkWidget*> chrome_buttons_; | 161 std::vector<GtkWidget*> chrome_buttons_; |
151 | 162 |
152 // Tints and colors calculated by LoadGtkValues() that are given to the | 163 // Tints and colors calculated by LoadGtkValues() that are given to the |
153 // caller while |use_gtk_| is true. | 164 // caller while |use_gtk_| is true. |
154 ColorMap colors_; | 165 ColorMap colors_; |
155 TintMap tints_; | 166 TintMap tints_; |
156 | 167 |
| 168 // Colors that we pass to WebKit. These are generated each time the theme |
| 169 // changes. |
| 170 SkColor focus_ring_color_; |
| 171 SkColor thumb_active_color_; |
| 172 SkColor thumb_inactive_color_; |
| 173 SkColor track_color_; |
| 174 |
157 // Image cache of lazily created images, created when requested by | 175 // Image cache of lazily created images, created when requested by |
158 // GetBitmapNamed(). | 176 // GetBitmapNamed(). |
159 mutable ImageCache gtk_images_; | 177 mutable ImageCache gtk_images_; |
160 | 178 |
161 // Cairo surfaces for each GdkDisplay. | 179 // Cairo surfaces for each GdkDisplay. |
162 typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; | 180 typedef std::map<int, CairoCachedSurface*> CairoCachedSurfaceMap; |
163 typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; | 181 typedef std::map<GdkDisplay*, CairoCachedSurfaceMap> PerDisplaySurfaceMap; |
164 PerDisplaySurfaceMap per_display_surfaces_; | 182 PerDisplaySurfaceMap per_display_surfaces_; |
165 | 183 |
166 // This is a dummy widget that only exists so we have something to pass to | 184 // This is a dummy widget that only exists so we have something to pass to |
167 // gtk_widget_render_icon(). | 185 // gtk_widget_render_icon(). |
168 static GtkWidget* icon_widget_; | 186 static GtkWidget* icon_widget_; |
169 | 187 |
170 // The default folder icon and default bookmark icon for the GTK theme. | 188 // The default folder icon and default bookmark icon for the GTK theme. |
171 // These are static because the system can only have one theme at a time. | 189 // These are static because the system can only have one theme at a time. |
172 // They are cached when they are requested the first time, and cleared when | 190 // They are cached when they are requested the first time, and cleared when |
173 // the system theme changes. | 191 // the system theme changes. |
174 static GdkPixbuf* default_folder_icon_; | 192 static GdkPixbuf* default_folder_icon_; |
175 static GdkPixbuf* default_bookmark_icon_; | 193 static GdkPixbuf* default_bookmark_icon_; |
176 }; | 194 }; |
177 | 195 |
178 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ | 196 #endif // CHROME_BROWSER_GTK_GTK_THEME_PROVIDER_H_ |
OLD | NEW |