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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 color.green = (style->text[GTK_STATE_NORMAL].green + | 157 color.green = (style->text[GTK_STATE_NORMAL].green + |
157 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / | 158 (style->bg[GTK_STATE_NORMAL].green * kBgWeight)) / |
158 (1 + kBgWeight); | 159 (1 + kBgWeight); |
159 color.blue = (style->text[GTK_STATE_NORMAL].blue + | 160 color.blue = (style->text[GTK_STATE_NORMAL].blue + |
160 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / | 161 (style->bg[GTK_STATE_NORMAL].blue * kBgWeight)) / |
161 (1 + kBgWeight); | 162 (1 + kBgWeight); |
162 | 163 |
163 return color; | 164 return color; |
164 } | 165 } |
165 | 166 |
| 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 |
166 void GtkThemeProvider::LoadThemePrefs() { | 186 void GtkThemeProvider::LoadThemePrefs() { |
167 if (use_gtk_) { | 187 if (use_gtk_) { |
168 LoadGtkValues(); | 188 LoadGtkValues(); |
169 } else { | 189 } else { |
170 BrowserThemeProvider::LoadThemePrefs(); | 190 BrowserThemeProvider::LoadThemePrefs(); |
171 } | 191 } |
172 } | 192 } |
173 | 193 |
174 void GtkThemeProvider::NotifyThemeChanged() { | 194 void GtkThemeProvider::NotifyThemeChanged() { |
175 BrowserThemeProvider::NotifyThemeChanged(); | 195 BrowserThemeProvider::NotifyThemeChanged(); |
(...skipping 25 matching lines...) Expand all Loading... |
201 int id) { | 221 int id) { |
202 if (!use_gtk_) { | 222 if (!use_gtk_) { |
203 // Prevent us from writing out our mostly unused resources in gtk theme | 223 // 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 | 224 // 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 | 225 // the best design, but this would probably be a very invasive change on |
206 // all three platforms otherwise. | 226 // all three platforms otherwise. |
207 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); | 227 BrowserThemeProvider::SaveThemeBitmap(resource_name, id); |
208 } | 228 } |
209 } | 229 } |
210 | 230 |
| 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 |
211 // static | 244 // static |
212 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, | 245 void GtkThemeProvider::OnStyleSet(GtkWidget* widget, |
213 GtkStyle* previous_style, | 246 GtkStyle* previous_style, |
214 GtkThemeProvider* provider) { | 247 GtkThemeProvider* provider) { |
215 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { | 248 if (provider->profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { |
216 provider->ClearAllThemeData(); | 249 provider->ClearAllThemeData(); |
217 provider->LoadGtkValues(); | 250 provider->LoadGtkValues(); |
218 provider->NotifyThemeChanged(); | 251 provider->NotifyThemeChanged(); |
219 } | 252 } |
220 } | 253 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 396 } |
364 | 397 |
365 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, | 398 void GtkThemeProvider::OnDestroyChromeButton(GtkWidget* button, |
366 GtkThemeProvider* provider) { | 399 GtkThemeProvider* provider) { |
367 std::vector<GtkWidget*>::iterator it = | 400 std::vector<GtkWidget*>::iterator it = |
368 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), | 401 find(provider->chrome_buttons_.begin(), provider->chrome_buttons_.end(), |
369 button); | 402 button); |
370 if (it != provider->chrome_buttons_.end()) | 403 if (it != provider->chrome_buttons_.end()) |
371 provider->chrome_buttons_.erase(it); | 404 provider->chrome_buttons_.erase(it); |
372 } | 405 } |
OLD | NEW |