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 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 return out_color; | 926 return out_color; |
927 } | 927 } |
928 | 928 |
929 void GtkThemeService::FreeIconSets() { | 929 void GtkThemeService::FreeIconSets() { |
930 if (fullscreen_icon_set_) { | 930 if (fullscreen_icon_set_) { |
931 gtk_icon_set_unref(fullscreen_icon_set_); | 931 gtk_icon_set_unref(fullscreen_icon_set_); |
932 fullscreen_icon_set_ = NULL; | 932 fullscreen_icon_set_ = NULL; |
933 } | 933 } |
934 } | 934 } |
935 | 935 |
936 SkBitmap* GtkThemeService::GenerateGtkThemeBitmap(int id) const { | 936 SkBitmap GtkThemeService::GenerateGtkThemeBitmap(int id) const { |
937 switch (id) { | 937 switch (id) { |
938 case IDR_THEME_TOOLBAR: { | 938 case IDR_THEME_TOOLBAR: { |
939 GtkStyle* style = gtk_rc_get_style(fake_window_); | 939 GtkStyle* style = gtk_rc_get_style(fake_window_); |
940 GdkColor* color = &style->bg[GTK_STATE_NORMAL]; | 940 GdkColor* color = &style->bg[GTK_STATE_NORMAL]; |
941 SkBitmap* bitmap = new SkBitmap; | 941 SkBitmap bitmap; |
942 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 942 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
943 kToolbarImageWidth, kToolbarImageHeight); | 943 kToolbarImageWidth, kToolbarImageHeight); |
944 bitmap->allocPixels(); | 944 bitmap.allocPixels(); |
945 bitmap->eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); | 945 bitmap.eraseRGB(color->red >> 8, color->green >> 8, color->blue >> 8); |
946 return bitmap; | 946 return bitmap; |
947 } | 947 } |
948 case IDR_THEME_TAB_BACKGROUND: | 948 case IDR_THEME_TAB_BACKGROUND: |
949 return GenerateTabImage(IDR_THEME_FRAME); | 949 return GenerateTabImage(IDR_THEME_FRAME); |
950 case IDR_THEME_TAB_BACKGROUND_INCOGNITO: | 950 case IDR_THEME_TAB_BACKGROUND_INCOGNITO: |
951 return GenerateTabImage(IDR_THEME_FRAME_INCOGNITO); | 951 return GenerateTabImage(IDR_THEME_FRAME_INCOGNITO); |
952 case IDR_THEME_FRAME: | 952 case IDR_THEME_FRAME: |
953 return GenerateFrameImage(ThemeService::COLOR_FRAME, | 953 return GenerateFrameImage(ThemeService::COLOR_FRAME, |
954 "frame-gradient-color"); | 954 "frame-gradient-color"); |
955 case IDR_THEME_FRAME_INACTIVE: | 955 case IDR_THEME_FRAME_INACTIVE: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 case IDR_OMNIBOX_STAR_DARK: | 988 case IDR_OMNIBOX_STAR_DARK: |
989 case IDR_OMNIBOX_TTS_DARK: { | 989 case IDR_OMNIBOX_TTS_DARK: { |
990 return GenerateTintedIcon(id, selected_entry_tint_); | 990 return GenerateTintedIcon(id, selected_entry_tint_); |
991 } | 991 } |
992 default: { | 992 default: { |
993 return GenerateTintedIcon(id, button_tint_); | 993 return GenerateTintedIcon(id, button_tint_); |
994 } | 994 } |
995 } | 995 } |
996 } | 996 } |
997 | 997 |
998 SkBitmap* GtkThemeService::GenerateFrameImage( | 998 SkBitmap GtkThemeService::GenerateFrameImage( |
999 int color_id, | 999 int color_id, |
1000 const char* gradient_name) const { | 1000 const char* gradient_name) const { |
1001 // 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 |
1002 // 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 |
1003 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). | 1003 // several GTK+ themes, such as Ambiance, Clearlooks or Bluebird). |
1004 ColorMap::const_iterator it = colors_.find(color_id); | 1004 ColorMap::const_iterator it = colors_.find(color_id); |
1005 DCHECK(it != colors_.end()); | 1005 DCHECK(it != colors_.end()); |
1006 SkColor base = it->second; | 1006 SkColor base = it->second; |
1007 | 1007 |
1008 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); | 1008 gfx::Canvas canvas(gfx::Size(kToolbarImageWidth, kToolbarImageHeight), true); |
(...skipping 16 matching lines...) Expand all Loading... |
1025 paint.setStyle(SkPaint::kFill_Style); | 1025 paint.setStyle(SkPaint::kFill_Style); |
1026 paint.setAntiAlias(true); | 1026 paint.setAntiAlias(true); |
1027 paint.setShader(shader); | 1027 paint.setShader(shader); |
1028 shader->unref(); | 1028 shader->unref(); |
1029 | 1029 |
1030 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); | 1030 canvas.DrawRect(gfx::Rect(0, 0, kToolbarImageWidth, gradient_size), paint); |
1031 } | 1031 } |
1032 | 1032 |
1033 canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth, | 1033 canvas.FillRect(gfx::Rect(0, gradient_size, kToolbarImageWidth, |
1034 kToolbarImageHeight - gradient_size), base); | 1034 kToolbarImageHeight - gradient_size), base); |
1035 return new SkBitmap(canvas.ExtractBitmap()); | 1035 return canvas.ExtractBitmap(); |
1036 } | 1036 } |
1037 | 1037 |
1038 SkBitmap* GtkThemeService::GenerateTabImage(int base_id) const { | 1038 SkBitmap GtkThemeService::GenerateTabImage(int base_id) const { |
1039 SkBitmap* base_image = GetBitmapNamed(base_id); | 1039 SkBitmap* base_image = GetBitmapNamed(base_id); |
1040 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( | 1040 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( |
1041 *base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB)); | 1041 *base_image, GetTint(ThemeService::TINT_BACKGROUND_TAB)); |
1042 return new SkBitmap(SkBitmapOperations::CreateTiledBitmap( | 1042 return SkBitmapOperations::CreateTiledBitmap( |
1043 bg_tint, 0, 0, bg_tint.width(), bg_tint.height())); | 1043 bg_tint, 0, 0, bg_tint.width(), bg_tint.height()); |
1044 } | 1044 } |
1045 | 1045 |
1046 SkBitmap* GtkThemeService::GenerateTintedIcon( | 1046 SkBitmap GtkThemeService::GenerateTintedIcon( |
1047 int base_id, | 1047 int base_id, |
1048 const color_utils::HSL& tint) const { | 1048 const color_utils::HSL& tint) const { |
1049 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1049 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1050 return new SkBitmap(SkBitmapOperations::CreateHSLShiftedBitmap( | 1050 return SkBitmapOperations::CreateHSLShiftedBitmap( |
1051 *rb.GetBitmapNamed(base_id), tint)); | 1051 *rb.GetBitmapNamed(base_id), tint); |
1052 } | 1052 } |
1053 | 1053 |
1054 void GtkThemeService::GetNormalButtonTintHSL( | 1054 void GtkThemeService::GetNormalButtonTintHSL( |
1055 color_utils::HSL* tint) const { | 1055 color_utils::HSL* tint) const { |
1056 GtkStyle* window_style = gtk_rc_get_style(fake_window_); | 1056 GtkStyle* window_style = gtk_rc_get_style(fake_window_); |
1057 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; | 1057 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; |
1058 const GdkColor base_color = window_style->base[GTK_STATE_NORMAL]; | 1058 const GdkColor base_color = window_style->base[GTK_STATE_NORMAL]; |
1059 | 1059 |
1060 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); | 1060 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
1061 const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL]; | 1061 const GdkColor text_color = label_style->fg[GTK_STATE_NORMAL]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 cairo_new_path(cr); | 1143 cairo_new_path(cr); |
1144 cairo_set_line_width(cr, 1.0); | 1144 cairo_set_line_width(cr, 1.0); |
1145 cairo_move_to(cr, start_x, allocation.y); | 1145 cairo_move_to(cr, start_x, allocation.y); |
1146 cairo_line_to(cr, start_x, allocation.y + allocation.height); | 1146 cairo_line_to(cr, start_x, allocation.y + allocation.height); |
1147 cairo_stroke(cr); | 1147 cairo_stroke(cr); |
1148 cairo_destroy(cr); | 1148 cairo_destroy(cr); |
1149 cairo_pattern_destroy(pattern); | 1149 cairo_pattern_destroy(pattern); |
1150 | 1150 |
1151 return TRUE; | 1151 return TRUE; |
1152 } | 1152 } |
OLD | NEW |