OLD | NEW |
1 | 1 |
2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 6 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/environment.h" | 13 #include "base/environment.h" |
14 #include "base/nix/xdg_util.h" | 14 #include "base/nix/xdg_util.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/themes/theme_service_factory.h" | 18 #include "chrome/browser/themes/theme_service_factory.h" |
19 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" | |
22 #include "chrome/browser/ui/gtk/chrome_gtk_frame.h" | 21 #include "chrome/browser/ui/gtk/chrome_gtk_frame.h" |
23 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 22 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
24 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 23 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
25 #include "chrome/browser/ui/gtk/gtk_util.h" | 24 #include "chrome/browser/ui/gtk/gtk_util.h" |
26 #include "chrome/browser/ui/gtk/hover_controller_gtk.h" | 25 #include "chrome/browser/ui/gtk/hover_controller_gtk.h" |
27 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "content/browser/user_metrics.h" | 28 #include "content/browser/user_metrics.h" |
30 #include "content/public/browser/notification_details.h" | 29 #include "content/public/browser/notification_details.h" |
31 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
33 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
34 #include "grit/theme_resources_standard.h" | 33 #include "grit/theme_resources_standard.h" |
35 #include "grit/ui_resources.h" | 34 #include "grit/ui_resources.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 35 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "third_party/skia/include/core/SkCanvas.h" | 36 #include "third_party/skia/include/core/SkCanvas.h" |
38 #include "third_party/skia/include/core/SkColor.h" | 37 #include "third_party/skia/include/core/SkColor.h" |
39 #include "third_party/skia/include/core/SkShader.h" | 38 #include "third_party/skia/include/core/SkShader.h" |
40 #include "ui/base/gtk/gtk_hig_constants.h" | 39 #include "ui/base/gtk/gtk_hig_constants.h" |
41 #include "ui/base/gtk/gtk_signal_registrar.h" | 40 #include "ui/base/gtk/gtk_signal_registrar.h" |
42 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
43 #include "ui/gfx/canvas_skia.h" | 42 #include "ui/gfx/canvas_skia.h" |
44 #include "ui/gfx/color_utils.h" | 43 #include "ui/gfx/color_utils.h" |
45 #include "ui/gfx/gtk_util.h" | 44 #include "ui/gfx/gtk_util.h" |
| 45 #include "ui/gfx/image/cairo_cached_surface.h" |
46 #include "ui/gfx/image/image.h" | 46 #include "ui/gfx/image/image.h" |
47 #include "ui/gfx/skbitmap_operations.h" | 47 #include "ui/gfx/skbitmap_operations.h" |
48 #include "ui/gfx/skia_util.h" | 48 #include "ui/gfx/skia_util.h" |
49 #include "ui/gfx/skia_utils_gtk.h" | 49 #include "ui/gfx/skia_utils_gtk.h" |
50 | 50 |
51 namespace { | 51 namespace { |
52 | 52 |
53 // The size of the rendered toolbar image. | 53 // The size of the rendered toolbar image. |
54 const int kToolbarImageWidth = 64; | 54 const int kToolbarImageWidth = 64; |
55 const int kToolbarImageHeight = 128; | 55 const int kToolbarImageHeight = 128; |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 if (theme_thumb_active) | 556 if (theme_thumb_active) |
557 *thumb_active_color = *theme_thumb_active; | 557 *thumb_active_color = *theme_thumb_active; |
558 | 558 |
559 if (theme_thumb_inactive) | 559 if (theme_thumb_inactive) |
560 *thumb_inactive_color = *theme_thumb_inactive; | 560 *thumb_inactive_color = *theme_thumb_inactive; |
561 | 561 |
562 if (theme_trough_color) | 562 if (theme_trough_color) |
563 *track_color = *theme_trough_color; | 563 *track_color = *theme_trough_color; |
564 } | 564 } |
565 | 565 |
566 CairoCachedSurface* GtkThemeService::GetSurfaceNamed( | 566 gfx::CairoCachedSurface* GtkThemeService::GetSurfaceNamed( |
567 int id, | 567 int id, |
568 GtkWidget* widget_on_display) { | 568 GtkWidget* widget_on_display) { |
569 return GetSurfaceNamedImpl( | 569 return GetSurfaceNamedImpl( |
570 id, | 570 id, |
571 &per_display_surfaces_, | 571 &per_display_surfaces_, |
572 &GtkThemeService::GetPixbufNamed, | 572 &GtkThemeService::GetPixbufNamed, |
573 widget_on_display); | 573 widget_on_display); |
574 } | 574 } |
575 | 575 |
576 CairoCachedSurface* GtkThemeService::GetRTLEnabledSurfaceNamed( | 576 gfx::CairoCachedSurface* GtkThemeService::GetRTLEnabledSurfaceNamed( |
577 int id, | 577 int id, |
578 GtkWidget* widget_on_display) { | 578 GtkWidget* widget_on_display) { |
579 // We flip the sign of |id| when passing it to GetSurfaceNamedImpl() for the | 579 // We flip the sign of |id| when passing it to GetSurfaceNamedImpl() for the |
580 // same reason that ThemeService::GetPixbufImpl() does: so that if one | 580 // same reason that ThemeService::GetPixbufImpl() does: so that if one |
581 // location calls this function with a resource ID, and another place calls | 581 // location calls this function with a resource ID, and another place calls |
582 // GetSurfaceNamed() with the same ID, they'll correctly get different | 582 // GetSurfaceNamed() with the same ID, they'll correctly get different |
583 // surfaces in RTL mode. | 583 // surfaces in RTL mode. |
584 return GetSurfaceNamedImpl( | 584 return GetSurfaceNamedImpl( |
585 -id, | 585 -id, |
586 &per_display_surfaces_, | 586 &per_display_surfaces_, |
587 &GtkThemeService::GetRTLEnabledPixbufNamedWrapper, | 587 &GtkThemeService::GetRTLEnabledPixbufNamedWrapper, |
588 widget_on_display); | 588 widget_on_display); |
589 } | 589 } |
590 | 590 |
591 CairoCachedSurface* GtkThemeService::GetUnthemedSurfaceNamed( | 591 gfx::CairoCachedSurface* GtkThemeService::GetUnthemedSurfaceNamed( |
592 int id, | 592 int id, |
593 GtkWidget* widget_on_display) { | 593 GtkWidget* widget_on_display) { |
594 return GetSurfaceNamedImpl(id, | 594 return GetSurfaceNamedImpl(id, |
595 &per_display_unthemed_surfaces_, | 595 &per_display_unthemed_surfaces_, |
596 &GtkThemeService::GetUnthemedNativePixbuf, | 596 &GtkThemeService::GetUnthemedNativePixbuf, |
597 widget_on_display); | 597 widget_on_display); |
598 } | 598 } |
599 | 599 |
600 CairoCachedSurface* GtkThemeService::GetCairoIcon( | 600 gfx::CairoCachedSurface* GtkThemeService::GetCairoIcon( |
601 int id, | 601 int id, |
602 GtkWidget* widget_on_display) { | 602 GtkWidget* widget_on_display) { |
603 return GetSurfaceNamedImpl(id, | 603 return GetSurfaceNamedImpl(id, |
604 &per_display_icon_surfaces_, | 604 &per_display_icon_surfaces_, |
605 &GtkThemeService::GetPixbufForIconId, | 605 &GtkThemeService::GetPixbufForIconId, |
606 widget_on_display); | 606 widget_on_display); |
607 } | 607 } |
608 | 608 |
609 // static | 609 // static |
610 GdkPixbuf* GtkThemeService::GetFolderIcon(bool native) { | 610 GdkPixbuf* GtkThemeService::GetFolderIcon(bool native) { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 void GtkThemeService::GetSelectedEntryForegroundHSL( | 1124 void GtkThemeService::GetSelectedEntryForegroundHSL( |
1125 color_utils::HSL* tint) const { | 1125 color_utils::HSL* tint) const { |
1126 // The simplest of all the tints. We just use the selected text in the entry | 1126 // The simplest of all the tints. We just use the selected text in the entry |
1127 // since the icons tinted this way will only be displayed against | 1127 // since the icons tinted this way will only be displayed against |
1128 // base[GTK_STATE_SELECTED]. | 1128 // base[GTK_STATE_SELECTED]. |
1129 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); | 1129 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); |
1130 const GdkColor color = style->text[GTK_STATE_SELECTED]; | 1130 const GdkColor color = style->text[GTK_STATE_SELECTED]; |
1131 color_utils::SkColorToHSL(GdkToSkColor(&color), tint); | 1131 color_utils::SkColorToHSL(GdkToSkColor(&color), tint); |
1132 } | 1132 } |
1133 | 1133 |
1134 CairoCachedSurface* GtkThemeService::GetSurfaceNamedImpl( | 1134 gfx::CairoCachedSurface* GtkThemeService::GetSurfaceNamedImpl( |
1135 int id, | 1135 int id, |
1136 PerDisplaySurfaceMap* display_surface_map, | 1136 PerDisplaySurfaceMap* display_surface_map, |
1137 PixbufProvidingMethod provider, | 1137 PixbufProvidingMethod provider, |
1138 GtkWidget* widget_on_display) { | 1138 GtkWidget* widget_on_display) { |
1139 GdkDisplay* display = gtk_widget_get_display(widget_on_display); | 1139 GdkDisplay* display = gtk_widget_get_display(widget_on_display); |
1140 CairoCachedSurfaceMap& surface_map = (*display_surface_map)[display]; | 1140 CairoCachedSurfaceMap& surface_map = (*display_surface_map)[display]; |
1141 | 1141 |
1142 // Check to see if we already have the pixbuf in the cache. | 1142 // Check to see if we already have the pixbuf in the cache. |
1143 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); | 1143 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); |
1144 if (found != surface_map.end()) | 1144 if (found != surface_map.end()) |
1145 return found->second; | 1145 return found->second; |
1146 | 1146 |
1147 CairoCachedSurface* surface = new CairoCachedSurface; | 1147 gfx::CairoCachedSurface* surface = new gfx::CairoCachedSurface; |
1148 surface->UsePixbuf((this->*provider)(id)); | 1148 surface->UsePixbuf((this->*provider)(id)); |
1149 | 1149 |
1150 surface_map[id] = surface; | 1150 surface_map[id] = surface; |
1151 | 1151 |
1152 return surface; | 1152 return surface; |
1153 } | 1153 } |
1154 | 1154 |
1155 // PixbufProvidingMethod that undoes the negative sign on |id|. | 1155 // PixbufProvidingMethod that undoes the negative sign on |id|. |
1156 GdkPixbuf* GtkThemeService::GetRTLEnabledPixbufNamedWrapper(int id) const { | 1156 GdkPixbuf* GtkThemeService::GetRTLEnabledPixbufNamedWrapper(int id) const { |
1157 return GetRTLEnabledPixbufNamed(-id); | 1157 return GetRTLEnabledPixbufNamed(-id); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 cairo_set_line_width(cr, 1.0); | 1238 cairo_set_line_width(cr, 1.0); |
1239 cairo_move_to(cr, start_x, widget->allocation.y); | 1239 cairo_move_to(cr, start_x, widget->allocation.y); |
1240 cairo_line_to(cr, start_x, | 1240 cairo_line_to(cr, start_x, |
1241 widget->allocation.y + widget->allocation.height); | 1241 widget->allocation.y + widget->allocation.height); |
1242 cairo_stroke(cr); | 1242 cairo_stroke(cr); |
1243 cairo_destroy(cr); | 1243 cairo_destroy(cr); |
1244 cairo_pattern_destroy(pattern); | 1244 cairo_pattern_destroy(pattern); |
1245 | 1245 |
1246 return TRUE; | 1246 return TRUE; |
1247 } | 1247 } |
OLD | NEW |