Chromium Code Reviews| 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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 (link_color && link_color != &kDefaultLinkColor) | |
|
Elliot Glaysher
2012/03/27 21:43:00
Better to set a bool if &kDefaultLinkColor set abo
| |
| 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 if (theme_frame) | |
| 826 gdk_color_free(theme_frame); | |
| 822 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color); | 827 SetThemeTintFromGtk(ThemeService::TINT_BACKGROUND_TAB, &frame_color); |
| 823 | 828 |
| 824 BuildAndSetFrameColor( | 829 BuildAndSetFrameColor( |
| 825 &frame_style->bg[GTK_STATE_INSENSITIVE], | 830 &frame_style->bg[GTK_STATE_INSENSITIVE], |
| 826 theme_inactive_frame, | 831 theme_inactive_frame, |
| 827 kDefaultFrameShift, | 832 kDefaultFrameShift, |
| 828 ThemeService::COLOR_FRAME_INACTIVE, | 833 ThemeService::COLOR_FRAME_INACTIVE, |
| 829 ThemeService::TINT_FRAME_INACTIVE); | 834 ThemeService::TINT_FRAME_INACTIVE); |
| 835 if (theme_inactive_frame) | |
| 836 gdk_color_free(theme_inactive_frame); | |
| 830 | 837 |
| 831 BuildAndSetFrameColor( | 838 BuildAndSetFrameColor( |
| 832 &frame_color, | 839 &frame_color, |
| 833 theme_incognito_frame, | 840 theme_incognito_frame, |
| 834 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO), | 841 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO), |
| 835 ThemeService::COLOR_FRAME_INCOGNITO, | 842 ThemeService::COLOR_FRAME_INCOGNITO, |
| 836 ThemeService::TINT_FRAME_INCOGNITO); | 843 ThemeService::TINT_FRAME_INCOGNITO); |
| 844 if (theme_incognito_frame) | |
| 845 gdk_color_free(theme_incognito_frame); | |
| 837 | 846 |
| 838 BuildAndSetFrameColor( | 847 BuildAndSetFrameColor( |
| 839 &frame_color, | 848 &frame_color, |
| 840 theme_incognito_inactive_frame, | 849 theme_incognito_inactive_frame, |
| 841 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), | 850 GetDefaultTint(ThemeService::TINT_FRAME_INCOGNITO_INACTIVE), |
| 842 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, | 851 ThemeService::COLOR_FRAME_INCOGNITO_INACTIVE, |
| 843 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); | 852 ThemeService::TINT_FRAME_INCOGNITO_INACTIVE); |
| 853 if (theme_incognito_inactive_frame) | |
| 854 gdk_color_free(theme_incognito_inactive_frame); | |
| 844 | 855 |
| 845 return frame_color; | 856 return frame_color; |
| 846 } | 857 } |
| 847 | 858 |
| 848 void ThemeServiceGtk::LoadDefaultValues() { | 859 void ThemeServiceGtk::LoadDefaultValues() { |
| 849 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); | 860 focus_ring_color_ = SkColorSetARGB(255, 229, 151, 0); |
| 850 thumb_active_color_ = SkColorSetRGB(244, 244, 244); | 861 thumb_active_color_ = SkColorSetRGB(244, 244, 244); |
| 851 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); | 862 thumb_inactive_color_ = SkColorSetRGB(234, 234, 234); |
| 852 track_color_ = SkColorSetRGB(211, 211, 211); | 863 track_color_ = SkColorSetRGB(211, 211, 211); |
| 853 | 864 |
| (...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 | 997 // 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 | 998 // that color (which is supposed to match the light gradient at the top of |
| 988 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). | 999 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). |
| 989 ColorMap::const_iterator it = colors_.find(color_id); | 1000 ColorMap::const_iterator it = colors_.find(color_id); |
| 990 DCHECK(it != colors_.end()); | 1001 DCHECK(it != colors_.end()); |
| 991 SkColor base = it->second; | 1002 SkColor base = it->second; |
| 992 | 1003 |
| 993 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); | 1004 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); |
| 994 | 1005 |
| 995 int gradient_size; | 1006 int gradient_size; |
| 996 const GdkColor* gradient_top_color = NULL; | 1007 GdkColor* gradient_top_color = NULL; |
| 997 gtk_widget_style_get(GTK_WIDGET(fake_frame_), | 1008 gtk_widget_style_get(GTK_WIDGET(fake_frame_), |
| 998 "frame-gradient-size", &gradient_size, | 1009 "frame-gradient-size", &gradient_size, |
| 999 gradient_name, &gradient_top_color, | 1010 gradient_name, &gradient_top_color, |
| 1000 NULL); | 1011 NULL); |
| 1001 if (gradient_size) { | 1012 if (gradient_size) { |
| 1002 SkColor lighter = gradient_top_color ? | 1013 SkColor lighter = gradient_top_color ? |
| 1003 gfx::GdkColorToSkColor(*gradient_top_color) : | 1014 gfx::GdkColorToSkColor(*gradient_top_color) : |
| 1004 color_utils::HSLShift(base, kGtkFrameShift); | 1015 color_utils::HSLShift(base, kGtkFrameShift); |
| 1016 if (gradient_top_color) | |
| 1017 gdk_color_free(gradient_top_color); | |
| 1005 SkShader* shader = gfx::CreateGradientShader( | 1018 SkShader* shader = gfx::CreateGradientShader( |
| 1006 0, gradient_size, lighter, base); | 1019 0, gradient_size, lighter, base); |
| 1007 SkPaint paint; | 1020 SkPaint paint; |
| 1008 paint.setStyle(SkPaint::kFill_Style); | 1021 paint.setStyle(SkPaint::kFill_Style); |
| 1009 paint.setAntiAlias(true); | 1022 paint.setAntiAlias(true); |
| 1010 paint.setShader(shader); | 1023 paint.setShader(shader); |
| 1011 shader->unref(); | 1024 shader->unref(); |
| 1012 | 1025 |
| 1013 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); | 1026 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); |
| 1014 } | 1027 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 cairo_new_path(cr); | 1139 cairo_new_path(cr); |
| 1127 cairo_set_line_width(cr, 1.0); | 1140 cairo_set_line_width(cr, 1.0); |
| 1128 cairo_move_to(cr, start_x, allocation.y); | 1141 cairo_move_to(cr, start_x, allocation.y); |
| 1129 cairo_line_to(cr, start_x, allocation.y + allocation.height); | 1142 cairo_line_to(cr, start_x, allocation.y + allocation.height); |
| 1130 cairo_stroke(cr); | 1143 cairo_stroke(cr); |
| 1131 cairo_destroy(cr); | 1144 cairo_destroy(cr); |
| 1132 cairo_pattern_destroy(pattern); | 1145 cairo_pattern_destroy(pattern); |
| 1133 | 1146 |
| 1134 return TRUE; | 1147 return TRUE; |
| 1135 } | 1148 } |
| OLD | NEW |