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" |
12 #include "chrome/browser/gtk/gtk_chrome_button.h" | 13 #include "chrome/browser/gtk/gtk_chrome_button.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
14 #include "chrome/common/notification_details.h" | 15 #include "chrome/common/notification_details.h" |
15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
16 #include "chrome/common/notification_source.h" | 17 #include "chrome/common/notification_source.h" |
17 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "skia/ext/skia_utils_gtk.h" | 20 #include "skia/ext/skia_utils_gtk.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // broadcast new theme images and colors. | 70 // broadcast new theme images and colors. |
70 gtk_widget_realize(fake_window_); | 71 gtk_widget_realize(fake_window_); |
71 g_signal_connect(fake_window_, "style-set", G_CALLBACK(&OnStyleSet), this); | 72 g_signal_connect(fake_window_, "style-set", G_CALLBACK(&OnStyleSet), this); |
72 } | 73 } |
73 | 74 |
74 GtkThemeProvider::~GtkThemeProvider() { | 75 GtkThemeProvider::~GtkThemeProvider() { |
75 profile()->GetPrefs()->RemovePrefObserver(prefs::kUsesSystemTheme, this); | 76 profile()->GetPrefs()->RemovePrefObserver(prefs::kUsesSystemTheme, this); |
76 gtk_widget_destroy(fake_window_); | 77 gtk_widget_destroy(fake_window_); |
77 fake_label_.Destroy(); | 78 fake_label_.Destroy(); |
78 | 79 |
| 80 FreePerDisplaySurfaces(); |
| 81 |
79 // Disconnect from the destroy signal of any redisual widgets in | 82 // Disconnect from the destroy signal of any redisual widgets in |
80 // |chrome_buttons_|. | 83 // |chrome_buttons_|. |
81 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); | 84 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); |
82 it != chrome_buttons_.end(); ++it) { | 85 it != chrome_buttons_.end(); ++it) { |
83 gtk_signal_disconnect_by_data(GTK_OBJECT(*it), this); | 86 gtk_signal_disconnect_by_data(GTK_OBJECT(*it), this); |
84 } | 87 } |
85 } | 88 } |
86 | 89 |
87 void GtkThemeProvider::Init(Profile* profile) { | 90 void GtkThemeProvider::Init(Profile* profile) { |
88 profile->GetPrefs()->AddPrefObserver(prefs::kUsesSystemTheme, this); | 91 profile->GetPrefs()->AddPrefObserver(prefs::kUsesSystemTheme, this); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 color.green = (style->text[GTK_STATE_NORMAL].green + | 159 color.green = (style->text[GTK_STATE_NORMAL].green + |
157 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / | 160 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / |
158 (1 + kBgWeight); | 161 (1 + kBgWeight); |
159 color.blue = (style->text[GTK_STATE_NORMAL].blue + | 162 color.blue = (style->text[GTK_STATE_NORMAL].blue + |
160 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / | 163 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / |
161 (1 + kBgWeight); | 164 (1 + kBgWeight); |
162 | 165 |
163 return color; | 166 return color; |
164 } | 167 } |
165 | 168 |
| 169 CairoCachedSurface* GtkThemeProvider::GetSurfaceNamed( |
| 170 int id, GtkWidget* widget_on_display) { |
| 171 GdkDisplay* display = gtk_widget_get_display(widget_on_display); |
| 172 CairoCachedSurfaceMap& surface_map = per_display_surfaces_[display]; |
| 173 |
| 174 // Check to see if we already have the pixbuf in the cache. |
| 175 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); |
| 176 if (found != surface_map.end()) |
| 177 return found->second; |
| 178 |
| 179 GdkPixbuf* pixbuf = GetPixbufNamed(id); |
| 180 CairoCachedSurface* surface = new CairoCachedSurface; |
| 181 surface->UsePixbuf(pixbuf); |
| 182 |
| 183 surface_map[id] = surface; |
| 184 |
| 185 return surface; |
| 186 } |
| 187 |
166 void GtkThemeProvider::LoadThemePrefs() { | 188 void GtkThemeProvider::LoadThemePrefs() { |
167 if (use_gtk_) { | 189 if (use_gtk_) { |
168 LoadGtkValues(); | 190 LoadGtkValues(); |
169 } else { | 191 } else { |
170 BrowserThemeProvider::LoadThemePrefs(); | 192 BrowserThemeProvider::LoadThemePrefs(); |
171 } | 193 } |
172 } | 194 } |
173 | 195 |
174 void GtkThemeProvider::NotifyThemeChanged() { | 196 void GtkThemeProvider::NotifyThemeChanged() { |
175 BrowserThemeProvider::NotifyThemeChanged(); | 197 BrowserThemeProvider::NotifyThemeChanged(); |
(...skipping 25 matching lines...) Expand all Loading... |
201 int id) { | 223 int id) { |
202 if (!use_gtk_) { | 224 if (!use_gtk_) { |
203 // Prevent us from writing out our mostly unused resources in gtk theme | 225 // Prevent us from writing out our mostly unused resources in gtk theme |
204 // mode. Simply preventing us from writing this data out in gtk mode isn't | 226 // mode. Simply preventing us from writing this data out in gtk mode isn't |
205 // the best design, but this would probably be a very invasive change on | 227 // the best design, but this would probably be a very invasive change on |
206 // all three platforms otherwise. | 228 // all three platforms otherwise. |
207 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); | 229 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); |
208 } | 230 } |
209 } | 231 } |
210 | 232 |
| 233 void GtkThemeProvider::FreePlatformCaches() { |
| 234 BrowserThemeProvider::FreePlatformCaches(); |
| 235 FreePerDisplaySurfaces(); |
| 236 } |
| 237 |
211 // static | 238 // static |
212 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, | 239 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, |
213 GtkStyle* previous_style, | 240 GtkStyle* previous_style, |
214 GtkThemeProvider* provider) { | 241 GtkThemeProvider* provider) { |
215 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { | 242 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { |
216 provider->ClearAllThemeData(); | 243 provider->ClearAllThemeData(); |
217 provider->LoadGtkValues(); | 244 provider->LoadGtkValues(); |
218 provider->NotifyThemeChanged(); | 245 provider->NotifyThemeChanged(); |
219 } | 246 } |
220 } | 247 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 skia::SkColorToHSL(GdkToSkColor(color), hsl); | 382 skia::SkColorToHSL(GdkToSkColor(color), hsl); |
356 | 383 |
357 if (default_tint.s != -1) | 384 if (default_tint.s != -1) |
358 hsl.s = default_tint.s; | 385 hsl.s = default_tint.s; |
359 | 386 |
360 if (default_tint.l != -1) | 387 if (default_tint.l != -1) |
361 hsl.l = default_tint.l; | 388 hsl.l = default_tint.l; |
362 SetTint(id, hsl); | 389 SetTint(id, hsl); |
363 } | 390 } |
364 | 391 |
| 392 void GtkThemeProvider::FreePerDisplaySurfaces() { |
| 393 for (PerDisplaySurfaceMap::iterator it = per_display_surfaces_.begin(); |
| 394 it != per_display_surfaces_.end(); ++it) { |
| 395 for (CairoCachedSurfaceMap::iterator jt = it->second.begin(); |
| 396 jt != it->second.end(); ++jt) { |
| 397 delete jt->second; |
| 398 } |
| 399 } |
| 400 per_display_surfaces_.clear(); |
| 401 } |
| 402 |
365 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, | 403 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, |
366 GtkThemeProvider* provider) { | 404 GtkThemeProvider* provider) { |
367 std::vector<GtkWidget*>::iterator it = | 405 std::vector<GtkWidget*>::iterator it = |
368 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), | 406 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), |
369 button); | 407 button); |
370 if (it != provider->chrome_buttons_.end()) | 408 if (it != provider->chrome_buttons_.end()) |
371 provider->chrome_buttons_.erase(it); | 409 provider->chrome_buttons_.erase(it); |
372 } | 410 } |
OLD | NEW |