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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 shift); | 239 shift); |
240 frame_color->pixel = 0; | 240 frame_color->pixel = 0; |
241 frame_color->red = SkColorGetR(shifted) * ui::kSkiaToGDKMultiplier; | 241 frame_color->red = SkColorGetR(shifted) * ui::kSkiaToGDKMultiplier; |
242 frame_color->green = SkColorGetG(shifted) * ui::kSkiaToGDKMultiplier; | 242 frame_color->green = SkColorGetG(shifted) * ui::kSkiaToGDKMultiplier; |
243 frame_color->blue = SkColorGetB(shifted) * ui::kSkiaToGDKMultiplier; | 243 frame_color->blue = SkColorGetB(shifted) * ui::kSkiaToGDKMultiplier; |
244 } | 244 } |
245 | 245 |
246 } // namespace | 246 } // namespace |
247 | 247 |
248 GtkWidget* GtkThemeService::icon_widget_ = NULL; | 248 GtkWidget* GtkThemeService::icon_widget_ = NULL; |
249 gfx::Image* GtkThemeService::default_folder_icon_ = NULL; | 249 base::LazyInstance<gfx::Image> GtkThemeService::default_folder_icon_ = |
250 gfx::Image* GtkThemeService::default_bookmark_icon_ = NULL; | 250 LAZY_INSTANCE_INITIALIZER; |
| 251 base::LazyInstance<gfx::Image> GtkThemeService::default_bookmark_icon_ = |
| 252 LAZY_INSTANCE_INITIALIZER; |
251 | 253 |
252 // static | 254 // static |
253 GtkThemeService* GtkThemeService::GetFrom(Profile* profile) { | 255 GtkThemeService* GtkThemeService::GetFrom(Profile* profile) { |
254 return static_cast<GtkThemeService*>( | 256 return static_cast<GtkThemeService*>( |
255 ThemeServiceFactory::GetForProfile(profile)); | 257 ThemeServiceFactory::GetForProfile(profile)); |
256 } | 258 } |
257 | 259 |
258 GtkThemeService::GtkThemeService() | 260 GtkThemeService::GtkThemeService() |
259 : ThemeService(), | 261 : ThemeService(), |
260 use_gtk_(false), | 262 use_gtk_(false), |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 *thumb_active_color = *theme_thumb_active; | 564 *thumb_active_color = *theme_thumb_active; |
563 | 565 |
564 if (theme_thumb_inactive) | 566 if (theme_thumb_inactive) |
565 *thumb_inactive_color = *theme_thumb_inactive; | 567 *thumb_inactive_color = *theme_thumb_inactive; |
566 | 568 |
567 if (theme_trough_color) | 569 if (theme_trough_color) |
568 *track_color = *theme_trough_color; | 570 *track_color = *theme_trough_color; |
569 } | 571 } |
570 | 572 |
571 // static | 573 // static |
572 gfx::Image* GtkThemeService::GetFolderIcon(bool native) { | 574 gfx::Image GtkThemeService::GetFolderIcon(bool native) { |
573 if (native) { | 575 if (native) { |
574 if (!icon_widget_) | 576 if (!icon_widget_) |
575 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 577 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
576 // We never release our ref, so we will leak this on program shutdown. | 578 |
577 if (!default_folder_icon_) { | 579 if (default_folder_icon_.Get().IsEmpty()) { |
| 580 // This seems to leak. |
578 GdkPixbuf* pixbuf = gtk_widget_render_icon( | 581 GdkPixbuf* pixbuf = gtk_widget_render_icon( |
579 icon_widget_, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); | 582 icon_widget_, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); |
580 if (pixbuf) | 583 if (pixbuf) { |
581 default_folder_icon_ = new gfx::Image(pixbuf); | 584 default_folder_icon_.Get() = gfx::Image(pixbuf); |
| 585 g_object_unref(pixbuf); |
| 586 } |
582 } | 587 } |
583 if (default_folder_icon_) | 588 if (!default_folder_icon_.Get().IsEmpty()) |
584 return default_folder_icon_; | 589 return default_folder_icon_.Get(); |
585 } | 590 } |
586 | 591 |
587 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 592 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
588 IDR_BOOKMARK_BAR_FOLDER); | 593 IDR_BOOKMARK_BAR_FOLDER); |
589 } | 594 } |
590 | 595 |
591 // static | 596 // static |
592 gfx::Image* GtkThemeService::GetDefaultFavicon(bool native) { | 597 gfx::Image GtkThemeService::GetDefaultFavicon(bool native) { |
593 if (native) { | 598 if (native) { |
594 if (!icon_widget_) | 599 if (!icon_widget_) |
595 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 600 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
596 // We never release our ref, so we will leak this on program shutdown. | 601 |
597 if (!default_bookmark_icon_) { | 602 if (default_bookmark_icon_.Get().IsEmpty()) { |
| 603 // This seems to leak. |
598 GdkPixbuf* pixbuf = gtk_widget_render_icon( | 604 GdkPixbuf* pixbuf = gtk_widget_render_icon( |
599 icon_widget_, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); | 605 icon_widget_, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); |
600 if (pixbuf) | 606 if (pixbuf) { |
601 default_bookmark_icon_ = new gfx::Image(pixbuf); | 607 default_bookmark_icon_.Get() = gfx::Image(pixbuf); |
| 608 g_object_unref(pixbuf); |
| 609 } |
602 } | 610 } |
603 if (default_bookmark_icon_) | 611 if (!default_bookmark_icon_.Get().IsEmpty()) |
604 return default_bookmark_icon_; | 612 return default_bookmark_icon_.Get(); |
605 } | 613 } |
606 | 614 |
607 return &ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 615 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
608 IDR_DEFAULT_FAVICON); | 616 IDR_DEFAULT_FAVICON); |
609 } | 617 } |
610 | 618 |
611 // static | 619 // static |
612 bool GtkThemeService::DefaultUsesSystemTheme() { | 620 bool GtkThemeService::DefaultUsesSystemTheme() { |
613 scoped_ptr<base::Environment> env(base::Environment::Create()); | 621 scoped_ptr<base::Environment> env(base::Environment::Create()); |
614 | 622 |
615 switch (base::nix::GetDesktopEnvironment(env.get())) { | 623 switch (base::nix::GetDesktopEnvironment(env.get())) { |
616 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 624 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
617 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 625 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 } | 677 } |
670 } | 678 } |
671 | 679 |
672 void GtkThemeService::FreePlatformCaches() { | 680 void GtkThemeService::FreePlatformCaches() { |
673 ThemeService::FreePlatformCaches(); | 681 ThemeService::FreePlatformCaches(); |
674 STLDeleteValues(>k_images_); | 682 STLDeleteValues(>k_images_); |
675 } | 683 } |
676 | 684 |
677 void GtkThemeService::OnStyleSet(GtkWidget* widget, | 685 void GtkThemeService::OnStyleSet(GtkWidget* widget, |
678 GtkStyle* previous_style) { | 686 GtkStyle* previous_style) { |
679 gfx::Image* default_folder_icon = default_folder_icon_; | 687 default_folder_icon_.Get() = gfx::Image(); |
680 gfx::Image* default_bookmark_icon = default_bookmark_icon_; | 688 default_bookmark_icon_.Get() = gfx::Image(); |
681 default_folder_icon_ = NULL; | |
682 default_bookmark_icon_ = NULL; | |
683 | 689 |
684 if (profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { | 690 if (profile()->GetPrefs()->GetBoolean(prefs::kUsesSystemTheme)) { |
685 ClearAllThemeData(); | 691 ClearAllThemeData(); |
686 LoadGtkValues(); | 692 LoadGtkValues(); |
687 NotifyThemeChanged(); | 693 NotifyThemeChanged(); |
688 } | 694 } |
689 | 695 |
690 RebuildMenuIconSets(); | 696 RebuildMenuIconSets(); |
691 | |
692 // Free the old icons only after the theme change notification has gone | |
693 // through. | |
694 if (default_folder_icon) | |
695 delete default_folder_icon; | |
696 if (default_bookmark_icon) | |
697 delete default_bookmark_icon; | |
698 } | 697 } |
699 | 698 |
700 void GtkThemeService::LoadGtkValues() { | 699 void GtkThemeService::LoadGtkValues() { |
701 // Before we start setting images and values, we have to clear out old, stale | 700 // Before we start setting images and values, we have to clear out old, stale |
702 // values. (If we don't do this, we'll regress startup time in the case where | 701 // values. (If we don't do this, we'll regress startup time in the case where |
703 // someone installs a heavyweight theme, then goes back to GTK.) | 702 // someone installs a heavyweight theme, then goes back to GTK.) |
704 profile()->GetPrefs()->ClearPref(prefs::kCurrentThemeImages); | 703 profile()->GetPrefs()->ClearPref(prefs::kCurrentThemeImages); |
705 | 704 |
706 GtkStyle* frame_style = gtk_rc_get_style(fake_frame_); | 705 GtkStyle* frame_style = gtk_rc_get_style(fake_frame_); |
707 | 706 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 cairo_new_path(cr); | 1150 cairo_new_path(cr); |
1152 cairo_set_line_width(cr, 1.0); | 1151 cairo_set_line_width(cr, 1.0); |
1153 cairo_move_to(cr, start_x, allocation.y); | 1152 cairo_move_to(cr, start_x, allocation.y); |
1154 cairo_line_to(cr, start_x, allocation.y + allocation.height); | 1153 cairo_line_to(cr, start_x, allocation.y + allocation.height); |
1155 cairo_stroke(cr); | 1154 cairo_stroke(cr); |
1156 cairo_destroy(cr); | 1155 cairo_destroy(cr); |
1157 cairo_pattern_destroy(pattern); | 1156 cairo_pattern_destroy(pattern); |
1158 | 1157 |
1159 return TRUE; | 1158 return TRUE; |
1160 } | 1159 } |
OLD | NEW |