OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/gtk/gtk_theme_service.h" | 5 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 fake_entry_.Destroy(); | 286 fake_entry_.Destroy(); |
287 fake_menu_item_.Destroy(); | 287 fake_menu_item_.Destroy(); |
288 | 288 |
289 FreeIconSets(); | 289 FreeIconSets(); |
290 | 290 |
291 // We have to call this because FreePlatformCached() in ~ThemeService | 291 // We have to call this because FreePlatformCached() in ~ThemeService |
292 // doesn't call the right virutal FreePlatformCaches. | 292 // doesn't call the right virutal FreePlatformCaches. |
293 FreePlatformCaches(); | 293 FreePlatformCaches(); |
294 } | 294 } |
295 | 295 |
296 void GtkThemeService::Init(Profile* profile) { | 296 void GtkThemeService::Init(Profile* profile) { |
pkotwicz
2013/07/19 18:33:20
The current code will sometimes use the GTK+ theme
Adrian Kuegel
2013/07/22 12:58:08
Good catch. Done.
| |
297 registrar_.Init(profile->GetPrefs()); | 297 registrar_.Init(profile->GetPrefs()); |
298 registrar_.Add(prefs::kUsesSystemTheme, | 298 registrar_.Add(prefs::kUsesSystemTheme, |
299 base::Bind(&GtkThemeService::OnUsesSystemThemeChanged, | 299 base::Bind(&GtkThemeService::OnUsesSystemThemeChanged, |
300 base::Unretained(this))); | 300 base::Unretained(this))); |
301 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 301 use_gtk_ = profile->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
302 ThemeService::Init(profile); | 302 ThemeService::Init(profile); |
303 } | 303 } |
304 | 304 |
305 gfx::ImageSkia* GtkThemeService::GetImageSkiaNamed(int id) const { | 305 gfx::ImageSkia* GtkThemeService::GetImageSkiaNamed(int id) const { |
306 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 306 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
307 // its images const. GetImageSkiaNamed() also should but has many callsites. | 307 // its images const. GetImageSkiaNamed() also should but has many callsites. |
308 return const_cast<gfx::ImageSkia*>(GetImageNamed(id).ToImageSkia()); | 308 return const_cast<gfx::ImageSkia*>(GetImageNamed(id).ToImageSkia()); |
309 } | 309 } |
310 | 310 |
311 gfx::Image GtkThemeService::GetImageNamed(int id) const { | 311 gfx::Image GtkThemeService::GetImageNamed(int id) const { |
312 // TODO(akuegel): Remove this once we have the default managed user theme. | |
313 if (ManagedUserService::ProfileIsManaged(profile())) { | |
314 if (id == IDR_THEME_FRAME) | |
315 id = IDR_MANAGED_USER_THEME_FRAME; | |
316 else if (id == IDR_THEME_FRAME_INACTIVE) | |
317 id = IDR_MANAGED_USER_THEME_FRAME_INACTIVE; | |
318 } | |
319 | |
320 // Try to get our cached version: | 312 // Try to get our cached version: |
321 ImageCache::const_iterator it = gtk_images_.find(id); | 313 ImageCache::const_iterator it = gtk_images_.find(id); |
322 if (it != gtk_images_.end()) | 314 if (it != gtk_images_.end()) |
323 return *it->second; | 315 return *it->second; |
324 | 316 |
325 if (use_gtk_ && IsOverridableImage(id)) { | 317 if (use_gtk_ && IsOverridableImage(id)) { |
326 gfx::Image* image = new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap( | 318 gfx::Image* image = new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap( |
327 GenerateGtkThemeBitmap(id))); | 319 GenerateGtkThemeBitmap(id))); |
328 gtk_images_[id] = image; | 320 gtk_images_[id] = image; |
329 return *image; | 321 return *image; |
330 } | 322 } |
331 | 323 |
332 return ThemeService::GetImageNamed(id); | 324 return ThemeService::GetImageNamed(id); |
333 } | 325 } |
334 | 326 |
335 SkColor GtkThemeService::GetColor(int id) const { | 327 SkColor GtkThemeService::GetColor(int id) const { |
336 // TODO(akuegel): Remove this once we have the default managed user theme. | |
337 if (ManagedUserService::ProfileIsManaged(profile())) { | |
338 if (id == ThemeProperties::COLOR_FRAME) | |
339 id = ThemeProperties::COLOR_FRAME_MANAGED_USER; | |
340 else if (id == ThemeProperties::COLOR_FRAME_INACTIVE) | |
341 id = ThemeProperties::COLOR_FRAME_MANAGED_USER_INACTIVE; | |
342 } | |
343 | |
344 if (use_gtk_) { | 328 if (use_gtk_) { |
345 ColorMap::const_iterator it = colors_.find(id); | 329 ColorMap::const_iterator it = colors_.find(id); |
346 if (it != colors_.end()) | 330 if (it != colors_.end()) |
347 return it->second; | 331 return it->second; |
348 } | 332 } |
349 | 333 |
350 return ThemeService::GetColor(id); | 334 return ThemeService::GetColor(id); |
351 } | 335 } |
352 | 336 |
353 bool GtkThemeService::HasCustomImage(int id) const { | 337 bool GtkThemeService::HasCustomImage(int id) const { |
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 cairo_stroke(cr); | 1169 cairo_stroke(cr); |
1186 cairo_destroy(cr); | 1170 cairo_destroy(cr); |
1187 cairo_pattern_destroy(pattern); | 1171 cairo_pattern_destroy(pattern); |
1188 | 1172 |
1189 return TRUE; | 1173 return TRUE; |
1190 } | 1174 } |
1191 | 1175 |
1192 void GtkThemeService::OnUsesSystemThemeChanged() { | 1176 void GtkThemeService::OnUsesSystemThemeChanged() { |
1193 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 1177 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
1194 } | 1178 } |
OLD | NEW |