Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/gtk/theme_service_gtk.cc

Issue 9855028: gtk: Fix memory leak in ThemeServiceGtk::LoadGtkValues. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix other leaks Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/theme_service_gtk.h" 5 #include "chrome/browser/ui/gtk/theme_service_gtk.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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK, 772 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK,
773 link_color); 773 link_color);
774 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE, 774 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE,
775 link_color); 775 link_color);
776 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK, 776 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK,
777 link_color); 777 link_color);
778 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE, 778 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE,
779 link_color); 779 link_color);
780 780
781 if (!gdk_color_equal(link_color, &kDefaultLinkColor))
John Knottenbelt 2012/03/27 14:45:47 We need to compare address, rather than value. Al
tfarina 2012/03/27 15:29:06 Done.
782 gdk_color_free(const_cast<GdkColor*>(link_color));
783
781 // Generate the colors that we pass to WebKit. 784 // Generate the colors that we pass to WebKit.
782 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color); 785 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color);
783 GdkColor thumb_active_color, thumb_inactive_color, track_color; 786 GdkColor thumb_active_color, thumb_inactive_color, track_color;
784 ThemeServiceGtk::GetScrollbarColors(&thumb_active_color, 787 ThemeServiceGtk::GetScrollbarColors(&thumb_active_color,
785 &thumb_inactive_color, 788 &thumb_inactive_color,
786 &track_color); 789 &track_color);
787 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color); 790 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color);
788 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color); 791 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color);
789 track_color_ = gfx::GdkColorToSkColor(track_color); 792 track_color_ = gfx::GdkColorToSkColor(track_color);
790 793
791 // Some GTK themes only define the text selection colors on the GtkEntry 794 // Some GTK themes only define the text selection colors on the GtkEntry
792 // class, so we need to use that for getting selection colors. 795 // class, so we need to use that for getting selection colors.
793 active_selection_bg_color_ = 796 active_selection_bg_color_ =
794 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); 797 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]);
795 active_selection_fg_color_ = 798 active_selection_fg_color_ =
796 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); 799 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]);
797 inactive_selection_bg_color_ = 800 inactive_selection_bg_color_ =
798 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); 801 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]);
799 inactive_selection_fg_color_ = 802 inactive_selection_fg_color_ =
800 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); 803 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]);
801 } 804 }
802 805
803 GdkColor ThemeServiceGtk::BuildFrameColors(GtkStyle* frame_style) { 806 GdkColor ThemeServiceGtk::BuildFrameColors(GtkStyle* frame_style) {
804 const GdkColor* theme_frame = NULL; 807 GdkColor* theme_frame = NULL;
805 const GdkColor* theme_inactive_frame = NULL; 808 GdkColor* theme_inactive_frame = NULL;
806 const GdkColor* theme_incognito_frame = NULL; 809 GdkColor* theme_incognito_frame = NULL;
807 const GdkColor* theme_incognito_inactive_frame = NULL; 810 GdkColor* theme_incognito_inactive_frame = NULL;
808 gtk_widget_style_get(GTK_WIDGET(fake_frame_), 811 gtk_widget_style_get(GTK_WIDGET(fake_frame_),
809 "frame-color", &theme_frame, 812 "frame-color", &theme_frame,
810 "inactive-frame-color", &theme_inactive_frame, 813 "inactive-frame-color", &theme_inactive_frame,
811 "incognito-frame-color", &theme_incognito_frame, 814 "incognito-frame-color", &theme_incognito_frame,
812 "incognito-inactive-frame-color", 815 "incognito-inactive-frame-color",
813 &theme_incognito_inactive_frame, 816 &theme_incognito_inactive_frame,
814 NULL); 817 NULL);
815 818
816 GdkColor frame_color = BuildAndSetFrameColor( 819 GdkColor frame_color = BuildAndSetFrameColor(
817 &frame_style->bg[GTK_STATE_SELECTED], 820 &frame_style->bg[GTK_STATE_SELECTED],
818 theme_frame, 821 theme_frame,
819 kDefaultFrameShift, 822 kDefaultFrameShift,
820 ThemeService::COLOR_FRAME, 823 ThemeService::COLOR_FRAME,
821 ThemeService::TINT_FRAME); 824 ThemeService::TINT_FRAME);
825 gdk_color_free(theme_frame);
John Knottenbelt 2012/03/27 14:45:47 We need to check for NULL here and in the other ca
tfarina 2012/03/27 15:29:06 Done.
822 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color); 826 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color);
823 827
824 BuildAndSetFrameColor( 828 BuildAndSetFrameColor(
825 &frame_style->bg[GTK_STATE_INSENSITIVE], 829 &frame_style->bg[GTK_STATE_INSENSITIVE],
826 theme_inactive_frame, 830 theme_inactive_frame,
827 kDefaultFrameShift, 831 kDefaultFrameShift,
828 ThemeService::COLOR_FRAME_INACTIVE, 832 ThemeService::COLOR_FRAME_INACTIVE,
829 ThemeService::TINT_FRAME_INACTIVE); 833 ThemeService::TINT_FRAME_INACTIVE);
834 gdk_color_free(theme_inactive_frame);
830 835
831 BuildAndSetFrameColor( 836 BuildAndSetFrameColor(
832 &frame_color, 837 &frame_color,
833 theme_incognito_frame, 838 theme_incognito_frame,
834 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO), 839 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO),
835 ThemeService::COLOR_FRAME_INCOGNITO, 840 ThemeService::COLOR_FRAME_INCOGNITO,
836 ThemeService::TINT_FRAME_INCOGNITO); 841 ThemeService::TINT_FRAME_INCOGNITO);
842 gdk_color_free(theme_incognito_frame);
837 843
838 BuildAndSetFrameColor( 844 BuildAndSetFrameColor(
839 &frame_color, 845 &frame_color,
840 theme_incognito_inactive_frame, 846 theme_incognito_inactive_frame,
841 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), 847 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE),
842 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, 848 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE,
843 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); 849 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE);
850 gdk_color_free(theme_incognito_inactive_frame);
844 851
845 return frame_color; 852 return frame_color;
846 } 853 }
847 854
848 void ThemeServiceGtk::LoadDefaultValues() { 855 void ThemeServiceGtk::LoadDefaultValues() {
849 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); 856 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0);
850 thumb_active_color_ = SkColorSetRGB(244, 244, 244); 857 thumb_active_color_ = SkColorSetRGB(244, 244, 244);
851 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); 858 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234);
852 track_color_ = SkColorSetRGB(211, 211, 211); 859 track_color_ = SkColorSetRGB(211, 211, 211);
853 860
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // We use two colors: the main color (passed in) and a lightened version of 993 // We use two colors: the main color (passed in) and a lightened version of
987 // that color (which is supposed to match the light gradient at the top of 994 // that color (which is supposed to match the light gradient at the top of
988 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). 995 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird).
989 ColorMap::const_iterator it = colors_.find(color_id); 996 ColorMap::const_iterator it = colors_.find(color_id);
990 DCHECK(it != colors_.end()); 997 DCHECK(it != colors_.end());
991 SkColor base = it->second; 998 SkColor base = it->second;
992 999
993 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); 1000 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true);
994 1001
995 int gradient_size; 1002 int gradient_size;
996 const GdkColor* gradient_top_color = NULL; 1003 GdkColor* gradient_top_color = NULL;
997 gtk_widget_style_get(GTK_WIDGET(fake_frame_), 1004 gtk_widget_style_get(GTK_WIDGET(fake_frame_),
998 "frame-gradient-size", &gradient_size, 1005 "frame-gradient-size", &gradient_size,
999 gradient_name, &gradient_top_color, 1006 gradient_name, &gradient_top_color,
1000 NULL); 1007 NULL);
1001 if (gradient_size) { 1008 if (gradient_size) {
1002 SkColor lighter = gradient_top_color ? 1009 SkColor lighter = gradient_top_color ?
1003 gfx::GdkColorToSkColor(*gradient_top_color) : 1010 gfx::GdkColorToSkColor(*gradient_top_color) :
1004 color_utils::HSLShift(base, kGtkFrameShift); 1011 color_utils::HSLShift(base, kGtkFrameShift);
1012 gdk_color_free(gradient_top_color);
1005 SkShader* shader = gfx::CreateGradientShader( 1013 SkShader* shader = gfx::CreateGradientShader(
1006 0, gradient_size, lighter, base); 1014 0, gradient_size, lighter, base);
1007 SkPaint paint; 1015 SkPaint paint;
1008 paint.setStyle(SkPaint::kFill_Style); 1016 paint.setStyle(SkPaint::kFill_Style);
1009 paint.setAntiAlias(true); 1017 paint.setAntiAlias(true);
1010 paint.setShader(shader); 1018 paint.setShader(shader);
1011 shader->unref(); 1019 shader->unref();
1012 1020
1013 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); 1021 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint);
1014 } 1022 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 cairo_new_path(cr); 1134 cairo_new_path(cr);
1127 cairo_set_line_width(cr, 1.0); 1135 cairo_set_line_width(cr, 1.0);
1128 cairo_move_to(cr, start_x, allocation.y); 1136 cairo_move_to(cr, start_x, allocation.y);
1129 cairo_line_to(cr, start_x, allocation.y + allocation.height); 1137 cairo_line_to(cr, start_x, allocation.y + allocation.height);
1130 cairo_stroke(cr); 1138 cairo_stroke(cr);
1131 cairo_destroy(cr); 1139 cairo_destroy(cr);
1132 cairo_pattern_destroy(pattern); 1140 cairo_pattern_destroy(pattern);
1133 1141
1134 return TRUE; 1142 return TRUE;
1135 } 1143 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698