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 #include "chrome/browser/gtk/gtk_theme_provider.h" | 5 #include "chrome/browser/gtk/gtk_theme_provider.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/gfx/gtk_util.h" | 9 #include "base/gfx/gtk_util.h" |
10 #include "chrome/browser/metrics/user_metrics.h" | 10 #include "chrome/browser/metrics/user_metrics.h" |
11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
12 #include "chrome/browser/gtk/cairo_cached_surface.h" | |
13 #include "chrome/browser/gtk/gtk_chrome_button.h" | 12 #include "chrome/browser/gtk/gtk_chrome_button.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
15 #include "chrome/common/notification_details.h" | 14 #include "chrome/common/notification_details.h" |
16 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/notification_source.h" | 16 #include "chrome/common/notification_source.h" |
18 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
19 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
20 #include "skia/ext/skia_utils_gtk.h" | 19 #include "skia/ext/skia_utils_gtk.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "third_party/skia/include/core/SkCanvas.h" | 21 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 color.green = (style->text[GTK_STATE_NORMAL].green + | 156 color.green = (style->text[GTK_STATE_NORMAL].green + |
158 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / | 157 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / |
159 (1 + kBgWeight); | 158 (1 + kBgWeight); |
160 color.blue = (style->text[GTK_STATE_NORMAL].blue + | 159 color.blue = (style->text[GTK_STATE_NORMAL].blue + |
161 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / | 160 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / |
162 (1 + kBgWeight); | 161 (1 + kBgWeight); |
163 | 162 |
164 return color; | 163 return color; |
165 } | 164 } |
166 | 165 |
167 CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed( | |
168 int id, GtkWidget* widget_on_display) { | |
169 GdkDisplay* display = gtk_widget_get_display(widget_on_display); | |
170 CairoCachedSurfaceMap& surface_map = per_display_surfaces_[display]; | |
171 | |
172 // Check to see if we already have the pixbuf in the cache. | |
173 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); | |
174 if (found != surface_map.end()) | |
175 return found->second; | |
176 | |
177 GdkPixbuf* pixbuf = GetPixbufNamed(id); | |
178 CairoCachedSurface* surface = new CairoCachedSurface; | |
179 surface->UsePixbuf(pixbuf); | |
180 | |
181 surface_map[id] = surface; | |
182 | |
183 return surface; | |
184 } | |
185 | |
186 void GtkThemeProvider::LoadThemePrefs() { | 166 void GtkThemeProvider::LoadThemePrefs() { |
187 if (use_gtk_) { | 167 if (use_gtk_) { |
188 LoadGtkValues(); | 168 LoadGtkValues(); |
189 } else { | 169 } else { |
190 BrowserThemeProvider::LoadThemePrefs(); | 170 BrowserThemeProvider::LoadThemePrefs(); |
191 } | 171 } |
192 } | 172 } |
193 | 173 |
194 void GtkThemeProvider::NotifyThemeChanged() { | 174 void GtkThemeProvider::NotifyThemeChanged() { |
195 BrowserThemeProvider::NotifyThemeChanged(); | 175 BrowserThemeProvider::NotifyThemeChanged(); |
(...skipping 25 matching lines...) Expand all Loading... |
221 int id) { | 201 int id) { |
222 if (!use_gtk_) { | 202 if (!use_gtk_) { |
223 // Prevent us from writing out our mostly unused resources in gtk theme | 203 // Prevent us from writing out our mostly unused resources in gtk theme |
224 // mode. Simply preventing us from writing this data out in gtk mode isn't | 204 // mode. Simply preventing us from writing this data out in gtk mode isn't |
225 // the best design, but this would probably be a very invasive change on | 205 // the best design, but this would probably be a very invasive change on |
226 // all three platforms otherwise. | 206 // all three platforms otherwise. |
227 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); | 207 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); |
228 } | 208 } |
229 } | 209 } |
230 | 210 |
231 void GtkThemeProvider::FreePlatformCaches() { | |
232 BrowserThemeProvider::FreePlatformCaches(); | |
233 | |
234 for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin(); | |
235 it != per_display_surfaces_.end(); ++it) { | |
236 for (CairoCachedSurfaceMap::iterator jt = it->second.begin(); | |
237 jt != it->second.end(); ++jt) { | |
238 delete jt->second; | |
239 } | |
240 } | |
241 per_display_surfaces_.clear(); | |
242 } | |
243 | |
244 // static | 211 // static |
245 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, | 212 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, |
246 GtkStyle* previous_style, | 213 GtkStyle* previous_style, |
247 GtkThemeProvider* provider) { | 214 GtkThemeProvider* provider) { |
248 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { | 215 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { |
249 provider->ClearAllThemeData(); | 216 provider->ClearAllThemeData(); |
250 provider->LoadGtkValues(); | 217 provider->LoadGtkValues(); |
251 provider->NotifyThemeChanged(); | 218 provider->NotifyThemeChanged(); |
252 } | 219 } |
253 } | 220 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 363 } |
397 | 364 |
398 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, | 365 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, |
399 GtkThemeProvider* provider) { | 366 GtkThemeProvider* provider) { |
400 std::vector<GtkWidget*>::iterator it = | 367 std::vector<GtkWidget*>::iterator it = |
401 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), | 368 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), |
402 button); | 369 button); |
403 if (it != provider->chrome_buttons_.end()) | 370 if (it != provider->chrome_buttons_.end()) |
404 provider->chrome_buttons_.erase(it); | 371 provider->chrome_buttons_.erase(it); |
405 } | 372 } |
OLD | NEW |