| 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 25 matching lines...) Expand all Loading... |
| 379 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); | 363 profile()->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); |
| 380 ClearAllThemeData(); | 364 ClearAllThemeData(); |
| 381 LoadGtkValues(); | 365 LoadGtkValues(); |
| 382 NotifyThemeChanged(); | 366 NotifyThemeChanged(); |
| 383 } | 367 } |
| 384 | 368 |
| 385 bool GtkThemeService::UsingDefaultTheme() const { | 369 bool GtkThemeService::UsingDefaultTheme() const { |
| 386 return !use_gtk_ && ThemeService::UsingDefaultTheme(); | 370 return !use_gtk_ && ThemeService::UsingDefaultTheme(); |
| 387 } | 371 } |
| 388 | 372 |
| 373 bool GtkThemeService::ShouldInitWithNativeTheme() { |
| 374 return profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 375 } |
| 376 |
| 389 bool GtkThemeService::UsingNativeTheme() const { | 377 bool GtkThemeService::UsingNativeTheme() const { |
| 390 return use_gtk_; | 378 return use_gtk_; |
| 391 } | 379 } |
| 392 | 380 |
| 393 GtkWidget* GtkThemeService::BuildChromeButton() { | 381 GtkWidget* GtkThemeService::BuildChromeButton() { |
| 394 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); | 382 GtkWidget* button = HoverControllerGtk::CreateChromeButton(); |
| 395 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); | 383 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button), use_gtk_); |
| 396 chrome_buttons_.push_back(button); | 384 chrome_buttons_.push_back(button); |
| 397 | 385 |
| 398 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), | 386 signals_->Connect(button, "destroy", G_CALLBACK(OnDestroyChromeButtonThunk), |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 } | 631 } |
| 644 | 632 |
| 645 void GtkThemeService::ClearAllThemeData() { | 633 void GtkThemeService::ClearAllThemeData() { |
| 646 colors_.clear(); | 634 colors_.clear(); |
| 647 tints_.clear(); | 635 tints_.clear(); |
| 648 | 636 |
| 649 ThemeService::ClearAllThemeData(); | 637 ThemeService::ClearAllThemeData(); |
| 650 } | 638 } |
| 651 | 639 |
| 652 void GtkThemeService::LoadThemePrefs() { | 640 void GtkThemeService::LoadThemePrefs() { |
| 653 if (use_gtk_) { | 641 // This takes care of calling SetNativeTheme() if necessary. |
| 654 LoadGtkValues(); | 642 ThemeService::LoadThemePrefs(); |
| 655 set_ready(); | |
| 656 } else { | |
| 657 LoadDefaultValues(); | |
| 658 ThemeService::LoadThemePrefs(); | |
| 659 } | |
| 660 | 643 |
| 661 SetXDGIconTheme(); | 644 SetXDGIconTheme(); |
| 662 RebuildMenuIconSets(); | 645 RebuildMenuIconSets(); |
| 663 } | 646 } |
| 664 | 647 |
| 665 void GtkThemeService::NotifyThemeChanged() { | 648 void GtkThemeService::NotifyThemeChanged() { |
| 666 ThemeService::NotifyThemeChanged(); | 649 ThemeService::NotifyThemeChanged(); |
| 667 | 650 |
| 668 // Notify all GtkChromeButtons of their new rendering mode: | 651 // Notify all GtkChromeButtons of their new rendering mode: |
| 669 for (std::vector<GtkWidget*>::iterator it = chrome_buttons_.begin(); | 652 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); | 1168 cairo_stroke(cr); |
| 1186 cairo_destroy(cr); | 1169 cairo_destroy(cr); |
| 1187 cairo_pattern_destroy(pattern); | 1170 cairo_pattern_destroy(pattern); |
| 1188 | 1171 |
| 1189 return TRUE; | 1172 return TRUE; |
| 1190 } | 1173 } |
| 1191 | 1174 |
| 1192 void GtkThemeService::OnUsesSystemThemeChanged() { | 1175 void GtkThemeService::OnUsesSystemThemeChanged() { |
| 1193 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); | 1176 use_gtk_ = profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme); |
| 1194 } | 1177 } |
| OLD | NEW |