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/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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 &frame_color); | 759 &frame_color); |
760 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION, | 760 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION, |
761 &toolbar_color); | 761 &toolbar_color); |
762 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_TEXT, | 762 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_TEXT, |
763 &label_color); | 763 &label_color); |
764 | 764 |
765 // Override the link color if the theme provides it. | 765 // Override the link color if the theme provides it. |
766 const GdkColor* link_color = NULL; | 766 const GdkColor* link_color = NULL; |
767 gtk_widget_style_get(GTK_WIDGET(fake_window_), | 767 gtk_widget_style_get(GTK_WIDGET(fake_window_), |
768 "link-color", &link_color, NULL); | 768 "link-color", &link_color, NULL); |
769 if (!link_color) | 769 |
| 770 bool is_default_link_color = false; |
| 771 if (!link_color) { |
770 link_color = &kDefaultLinkColor; | 772 link_color = &kDefaultLinkColor; |
| 773 is_default_link_color = true; |
| 774 } |
771 | 775 |
772 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK, | 776 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK, |
773 link_color); | 777 link_color); |
774 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE, | 778 SetThemeColorFromGtk(ThemeService::COLOR_NTP_LINK_UNDERLINE, |
775 link_color); | 779 link_color); |
776 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK, | 780 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK, |
777 link_color); | 781 link_color); |
778 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE, | 782 SetThemeColorFromGtk(ThemeService::COLOR_NTP_SECTION_LINK_UNDERLINE, |
779 link_color); | 783 link_color); |
780 | 784 |
| 785 if (link_color && !is_default_link_color) |
| 786 gdk_color_free(const_cast<GdkColor*>(link_color)); |
| 787 |
781 // Generate the colors that we pass to WebKit. | 788 // Generate the colors that we pass to WebKit. |
782 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color); | 789 focus_ring_color_ = gfx::GdkColorToSkColor(frame_color); |
783 GdkColor thumb_active_color, thumb_inactive_color, track_color; | 790 GdkColor thumb_active_color, thumb_inactive_color, track_color; |
784 ThemeServiceGtk::GetScrollbarColors(&thumb_active_color, | 791 ThemeServiceGtk::GetScrollbarColors(&thumb_active_color, |
785 &thumb_inactive_color, | 792 &thumb_inactive_color, |
786 &track_color); | 793 &track_color); |
787 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color); | 794 thumb_active_color_ = gfx::GdkColorToSkColor(thumb_active_color); |
788 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color); | 795 thumb_inactive_color_ = gfx::GdkColorToSkColor(thumb_inactive_color); |
789 track_color_ = gfx::GdkColorToSkColor(track_color); | 796 track_color_ = gfx::GdkColorToSkColor(track_color); |
790 | 797 |
791 // Some GTK themes only define the text selection colors on the GtkEntry | 798 // Some GTK themes only define the text selection colors on the GtkEntry |
792 // class, so we need to use that for getting selection colors. | 799 // class, so we need to use that for getting selection colors. |
793 active_selection_bg_color_ = | 800 active_selection_bg_color_ = |
794 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); | 801 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_SELECTED]); |
795 active_selection_fg_color_ = | 802 active_selection_fg_color_ = |
796 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); | 803 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_SELECTED]); |
797 inactive_selection_bg_color_ = | 804 inactive_selection_bg_color_ = |
798 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); | 805 gfx::GdkColorToSkColor(entry_style->base[GTK_STATE_ACTIVE]); |
799 inactive_selection_fg_color_ = | 806 inactive_selection_fg_color_ = |
800 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); | 807 gfx::GdkColorToSkColor(entry_style->text[GTK_STATE_ACTIVE]); |
801 } | 808 } |
802 | 809 |
803 GdkColor ThemeServiceGtk::BuildFrameColors(GtkStyle* frame_style) { | 810 GdkColor ThemeServiceGtk::BuildFrameColors(GtkStyle* frame_style) { |
804 const GdkColor* theme_frame = NULL; | 811 GdkColor* theme_frame = NULL; |
805 const GdkColor* theme_inactive_frame = NULL; | 812 GdkColor* theme_inactive_frame = NULL; |
806 const GdkColor* theme_incognito_frame = NULL; | 813 GdkColor* theme_incognito_frame = NULL; |
807 const GdkColor* theme_incognito_inactive_frame = NULL; | 814 GdkColor* theme_incognito_inactive_frame = NULL; |
808 gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 815 gtk_widget_style_get(GTK_WIDGET(fake_frame_), |
809 "frame-color", &theme_frame, | 816 "frame-color", &theme_frame, |
810 "inactive-frame-color", &theme_inactive_frame, | 817 "inactive-frame-color", &theme_inactive_frame, |
811 "incognito-frame-color", &theme_incognito_frame, | 818 "incognito-frame-color", &theme_incognito_frame, |
812 "incognito-inactive-frame-color", | 819 "incognito-inactive-frame-color", |
813 &theme_incognito_inactive_frame, | 820 &theme_incognito_inactive_frame, |
814 NULL); | 821 NULL); |
815 | 822 |
816 GdkColor frame_color = BuildAndSetFrameColor( | 823 GdkColor frame_color = BuildAndSetFrameColor( |
817 &frame_style->bg[GTK_STATE_SELECTED], | 824 &frame_style->bg[GTK_STATE_SELECTED], |
818 theme_frame, | 825 theme_frame, |
819 kDefaultFrameShift, | 826 kDefaultFrameShift, |
820 ThemeService::COLOR_FRAME, | 827 ThemeService::COLOR_FRAME, |
821 ThemeService::TINT_FRAME); | 828 ThemeService::TINT_FRAME); |
| 829 if (theme_frame) |
| 830 gdk_color_free(theme_frame); |
822 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color); | 831 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color); |
823 | 832 |
824 BuildAndSetFrameColor( | 833 BuildAndSetFrameColor( |
825 &frame_style->bg[GTK_STATE_INSENSITIVE], | 834 &frame_style->bg[GTK_STATE_INSENSITIVE], |
826 theme_inactive_frame, | 835 theme_inactive_frame, |
827 kDefaultFrameShift, | 836 kDefaultFrameShift, |
828 ThemeService::COLOR_FRAME_INACTIVE, | 837 ThemeService::COLOR_FRAME_INACTIVE, |
829 ThemeService::TINT_FRAME_INACTIVE); | 838 ThemeService::TINT_FRAME_INACTIVE); |
| 839 if (theme_inactive_frame) |
| 840 gdk_color_free(theme_inactive_frame); |
830 | 841 |
831 BuildAndSetFrameColor( | 842 BuildAndSetFrameColor( |
832 &frame_color, | 843 &frame_color, |
833 theme_incognito_frame, | 844 theme_incognito_frame, |
834 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO), | 845 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO), |
835 ThemeService::COLOR_FRAME_INCOGNITO, | 846 ThemeService::COLOR_FRAME_INCOGNITO, |
836 ThemeService::TINT_FRAME_INCOGNITO); | 847 ThemeService::TINT_FRAME_INCOGNITO); |
| 848 if (theme_incognito_frame) |
| 849 gdk_color_free(theme_incognito_frame); |
837 | 850 |
838 BuildAndSetFrameColor( | 851 BuildAndSetFrameColor( |
839 &frame_color, | 852 &frame_color, |
840 theme_incognito_inactive_frame, | 853 theme_incognito_inactive_frame, |
841 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), | 854 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), |
842 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, | 855 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, |
843 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); | 856 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); |
| 857 if (theme_incognito_inactive_frame) |
| 858 gdk_color_free(theme_incognito_inactive_frame); |
844 | 859 |
845 return frame_color; | 860 return frame_color; |
846 } | 861 } |
847 | 862 |
848 void ThemeServiceGtk::LoadDefaultValues() { | 863 void ThemeServiceGtk::LoadDefaultValues() { |
849 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); | 864 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); |
850 thumb_active_color_ = SkColorSetRGB(244, 244, 244); | 865 thumb_active_color_ = SkColorSetRGB(244, 244, 244); |
851 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); | 866 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); |
852 track_color_ = SkColorSetRGB(211, 211, 211); | 867 track_color_ = SkColorSetRGB(211, 211, 211); |
853 | 868 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 // We use two colors: the main color (passed in) and a lightened version of | 1001 // 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 | 1002 // that color (which is supposed to match the light gradient at the top of |
988 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). | 1003 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). |
989 ColorMap::const_iterator it = colors_.find(color_id); | 1004 ColorMap::const_iterator it = colors_.find(color_id); |
990 DCHECK(it != colors_.end()); | 1005 DCHECK(it != colors_.end()); |
991 SkColor base = it->second; | 1006 SkColor base = it->second; |
992 | 1007 |
993 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); | 1008 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); |
994 | 1009 |
995 int gradient_size; | 1010 int gradient_size; |
996 const GdkColor* gradient_top_color = NULL; | 1011 GdkColor* gradient_top_color = NULL; |
997 gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 1012 gtk_widget_style_get(GTK_WIDGET(fake_frame_), |
998 "frame-gradient-size", &gradient_size, | 1013 "frame-gradient-size", &gradient_size, |
999 gradient_name, &gradient_top_color, | 1014 gradient_name, &gradient_top_color, |
1000 NULL); | 1015 NULL); |
1001 if (gradient_size) { | 1016 if (gradient_size) { |
1002 SkColor lighter = gradient_top_color ? | 1017 SkColor lighter = gradient_top_color ? |
1003 gfx::GdkColorToSkColor(*gradient_top_color) : | 1018 gfx::GdkColorToSkColor(*gradient_top_color) : |
1004 color_utils::HSLShift(base, kGtkFrameShift); | 1019 color_utils::HSLShift(base, kGtkFrameShift); |
| 1020 if (gradient_top_color) |
| 1021 gdk_color_free(gradient_top_color); |
1005 SkShader* shader = gfx::CreateGradientShader( | 1022 SkShader* shader = gfx::CreateGradientShader( |
1006 0, gradient_size, lighter, base); | 1023 0, gradient_size, lighter, base); |
1007 SkPaint paint; | 1024 SkPaint paint; |
1008 paint.setStyle(SkPaint::kFill_Style); | 1025 paint.setStyle(SkPaint::kFill_Style); |
1009 paint.setAntiAlias(true); | 1026 paint.setAntiAlias(true); |
1010 paint.setShader(shader); | 1027 paint.setShader(shader); |
1011 shader->unref(); | 1028 shader->unref(); |
1012 | 1029 |
1013 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); | 1030 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); |
1014 } | 1031 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 cairo_new_path(cr); | 1143 cairo_new_path(cr); |
1127 cairo_set_line_width(cr, 1.0); | 1144 cairo_set_line_width(cr, 1.0); |
1128 cairo_move_to(cr, start_x, allocation.y); | 1145 cairo_move_to(cr, start_x, allocation.y); |
1129 cairo_line_to(cr, start_x, allocation.y + allocation.height); | 1146 cairo_line_to(cr, start_x, allocation.y + allocation.height); |
1130 cairo_stroke(cr); | 1147 cairo_stroke(cr); |
1131 cairo_destroy(cr); | 1148 cairo_destroy(cr); |
1132 cairo_pattern_destroy(pattern); | 1149 cairo_pattern_destroy(pattern); |
1133 | 1150 |
1134 return TRUE; | 1151 return TRUE; |
1135 } | 1152 } |
OLD | NEW |