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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
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); | |
302 ThemeService::Init(profile); | 301 ThemeService::Init(profile); |
303 } | 302 } |
304 | 303 |
305 gfx::ImageSkia* GtkThemeService::GetImageSkiaNamed(int id) const { | 304 gfx::ImageSkia* GtkThemeService::GetImageSkiaNamed(int id) const { |
306 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns | 305 // TODO(pkotwicz): Remove this const cast. The gfx::Image interface returns |
307 // its images const. GetImageSkiaNamed() also should but has many callsites. | 306 // its images const. GetImageSkiaNamed() also should but has many callsites. |
308 return const_cast<gfx::ImageSkia*>(GetImageNamed(id).ToImageSkia()); | 307 return const_cast<gfx::ImageSkia*>(GetImageNamed(id).ToImageSkia()); |
309 } | 308 } |
310 | 309 |
311 gfx::Image GtkThemeService::GetImageNamed(int id) const { | 310 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: | 311 // Try to get our cached version: |
321 ImageCache::const_iterator it = gtk_images_.find(id); | 312 ImageCache::const_iterator it = gtk_images_.find(id); |
322 if (it != gtk_images_.end()) | 313 if (it != gtk_images_.end()) |
323 return *it->second; | 314 return *it->second; |
324 | 315 |
325 if (use_gtk_ && IsOverridableImage(id)) { | 316 if (use_gtk_ && IsOverridableImage(id)) { |
326 gfx::Image* image = new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap( | 317 gfx::Image* image = new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap( |
327 GenerateGtkThemeBitmap(id))); | 318 GenerateGtkThemeBitmap(id))); |
328 gtk_images_[id] = image; | 319 gtk_images_[id] = image; |
329 return *image; | 320 return *image; |
330 } | 321 } |
331 | 322 |
332 return ThemeService::GetImageNamed(id); | 323 return ThemeService::GetImageNamed(id); |
333 } | 324 } |
334 | 325 |
335 SkColor GtkThemeService::GetColor(int id) const { | 326 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_) { | 327 if (use_gtk_) { |
345 ColorMap::const_iterator it = colors_.find(id); | 328 ColorMap::const_iterator it = colors_.find(id); |
346 if (it != colors_.end()) | 329 if (it != colors_.end()) |
347 return it->second; | 330 return it->second; |
348 } | 331 } |
349 | 332 |
350 return ThemeService::GetColor(id); | 333 return ThemeService::GetColor(id); |
351 } | 334 } |
352 | 335 |
353 bool GtkThemeService::HasCustomImage(int id) const { | 336 bool GtkThemeService::HasCustomImage(int id) const { |
(...skipping 10 matching lines...) Expand all Loading... |
364 } | 347 } |
365 | 348 |
366 void GtkThemeService::SetTheme(const extensions::Extension* extension) { | 349 void GtkThemeService::SetTheme(const extensions::Extension* extension) { |
367 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 350 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
368 LoadDefaultValues(); | 351 LoadDefaultValues(); |
369 ThemeService::SetTheme(extension); | 352 ThemeService::SetTheme(extension); |
370 } | 353 } |
371 | 354 |
372 void GtkThemeService::UseDefaultTheme() { | 355 void GtkThemeService::UseDefaultTheme() { |
373 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); | 356 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, false); |
| 357 use_gtk_ = false; |
374 LoadDefaultValues(); | 358 LoadDefaultValues(); |
375 ThemeService::UseDefaultTheme(); | 359 ThemeService::UseDefaultTheme(); |
376 } | 360 } |
377 | 361 |
378 void GtkThemeService::SetNativeTheme() { | 362 void GtkThemeService::SetNativeTheme() { |
379 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 363 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
| 364 use_gtk_ = true; |
380 ClearAllThemeData(); | 365 ClearAllThemeData(); |
381 LoadGtkValues(); | 366 LoadGtkValues(); |
382 NotifyThemeChanged(); | 367 NotifyThemeChanged(); |
383 } | 368 } |
384 | 369 |
385 bool GtkThemeService::UsingDefaultTheme() const { | 370 bool GtkThemeService::UsingDefaultTheme() const { |
386 return !use_gtk_ && ThemeService::UsingDefaultTheme(); | 371 return !use_gtk_ && ThemeService::UsingDefaultTheme(); |
387 } | 372 } |
388 | 373 |
| 374 bool GtkThemeService::ShouldInitWithNativeTheme() const { |
| 375 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 376 } |
| 377 |
389 bool GtkThemeService::UsingNativeTheme() const { | 378 bool GtkThemeService::UsingNativeTheme() const { |
390 return use_gtk_; | 379 return use_gtk_; |
391 } | 380 } |
392 | 381 |
393 GtkWidget* GtkThemeService::BuildChromeButton() { | 382 GtkWidget* GtkThemeService::BuildChromeButton() { |
394 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); | 383 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); |
395 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); | 384 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); |
396 chrome_buttons_.push_back(button); | 385 chrome_buttons_.push_back(button); |
397 | 386 |
398 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), | 387 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 } | 632 } |
644 | 633 |
645 void GtkThemeService::ClearAllThemeData() { | 634 void GtkThemeService::ClearAllThemeData() { |
646 colors_.clear(); | 635 colors_.clear(); |
647 tints_.clear(); | 636 tints_.clear(); |
648 | 637 |
649 ThemeService::ClearAllThemeData(); | 638 ThemeService::ClearAllThemeData(); |
650 } | 639 } |
651 | 640 |
652 void GtkThemeService::LoadThemePrefs() { | 641 void GtkThemeService::LoadThemePrefs() { |
653 if (use_gtk_) { | 642 // This takes care of calling SetNativeTheme() if necessary. |
654 LoadGtkValues(); | 643 ThemeService::LoadThemePrefs(); |
655 set_ready(); | |
656 } else { | |
657 LoadDefaultValues(); | |
658 ThemeService::LoadThemePrefs(); | |
659 } | |
660 | 644 |
661 SetXDGIconTheme(); | 645 SetXDGIconTheme(); |
662 RebuildMenuIconSets(); | 646 RebuildMenuIconSets(); |
663 } | 647 } |
664 | 648 |
665 void GtkThemeService::NotifyThemeChanged() { | 649 void GtkThemeService::NotifyThemeChanged() { |
666 ThemeService::NotifyThemeChanged(); | 650 ThemeService::NotifyThemeChanged(); |
667 | 651 |
668 // Notify all GtkChromeButtons of their new rendering mode: | 652 // Notify all GtkChromeButtons of their new rendering mode: |
669 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); | 653 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); |
(...skipping 515 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 |