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> |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 CairoCachedSurface* GtkThemeService::GetSurfaceNamed( |
567 int id, | 567 int id, |
568 GtkWidget* widget_on_display) { | 568 GtkWidget* widget_on_display) { |
569 return GetSurfaceNamedImpl(id, | 569 return GetSurfaceNamedImpl( |
570 &per_display_surfaces_, | 570 id, |
571 GetPixbufNamed(id), | 571 &per_display_surfaces_, |
572 widget_on_display); | 572 &GtkThemeService::GetPixbufNamed, |
| 573 widget_on_display); |
573 } | 574 } |
574 | 575 |
575 CairoCachedSurface* GtkThemeService::GetRTLEnabledSurfaceNamed( | 576 CairoCachedSurface* GtkThemeService::GetRTLEnabledSurfaceNamed( |
576 int id, | 577 int id, |
577 GtkWidget* widget_on_display) { | 578 GtkWidget* widget_on_display) { |
578 // 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 |
579 // same reason that ThemeService::GetPixbufImpl() does: so that if one | 580 // same reason that ThemeService::GetPixbufImpl() does: so that if one |
580 // 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 |
581 // GetSurfaceNamed() with the same ID, they'll correctly get different | 582 // GetSurfaceNamed() with the same ID, they'll correctly get different |
582 // surfaces in RTL mode. | 583 // surfaces in RTL mode. |
583 return GetSurfaceNamedImpl(-id, | 584 return GetSurfaceNamedImpl( |
584 &per_display_surfaces_, | 585 -id, |
585 GetRTLEnabledPixbufNamed(id), | 586 &per_display_surfaces_, |
586 widget_on_display); | 587 &GtkThemeService::GetRTLEnabledPixbufNamedWrapper, |
| 588 widget_on_display); |
587 } | 589 } |
588 | 590 |
589 CairoCachedSurface* GtkThemeService::GetUnthemedSurfaceNamed( | 591 CairoCachedSurface* GtkThemeService::GetUnthemedSurfaceNamed( |
590 int id, | 592 int id, |
591 GtkWidget* widget_on_display) { | 593 GtkWidget* widget_on_display) { |
592 return GetSurfaceNamedImpl(id, | 594 return GetSurfaceNamedImpl(id, |
593 &per_display_unthemed_surfaces_, | 595 &per_display_unthemed_surfaces_, |
594 ResourceBundle::GetSharedInstance().GetNativeImageNamed(id), | 596 &GtkThemeService::GetUnthemedNativePixbuf, |
595 widget_on_display); | 597 widget_on_display); |
596 } | 598 } |
597 | 599 |
| 600 CairoCachedSurface* GtkThemeService::GetCairoIcon( |
| 601 int id, |
| 602 GtkWidget* widget_on_display) { |
| 603 return GetSurfaceNamedImpl(id, |
| 604 &per_display_icon_surfaces_, |
| 605 &GtkThemeService::GetPixbufForIconId, |
| 606 widget_on_display); |
| 607 } |
| 608 |
598 // static | 609 // static |
599 GdkPixbuf* GtkThemeService::GetFolderIcon(bool native) { | 610 GdkPixbuf* GtkThemeService::GetFolderIcon(bool native) { |
600 if (native) { | 611 if (native) { |
601 if (!icon_widget_) | 612 if (!icon_widget_) |
602 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 613 icon_widget_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
603 // We never release our ref, so we will leak this on program shutdown. | 614 // We never release our ref, so we will leak this on program shutdown. |
604 if (!default_folder_icon_) { | 615 if (!default_folder_icon_) { |
605 default_folder_icon_ = | 616 default_folder_icon_ = |
606 gtk_widget_render_icon(icon_widget_, GTK_STOCK_DIRECTORY, | 617 gtk_widget_render_icon(icon_widget_, GTK_STOCK_DIRECTORY, |
607 GTK_ICON_SIZE_MENU, NULL); | 618 GTK_ICON_SIZE_MENU, NULL); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 Browser* browser = BrowserList::GetLastActive(); | 708 Browser* browser = BrowserList::GetLastActive(); |
698 if (browser && browser->window()) { | 709 if (browser && browser->window()) { |
699 gtk_util::SetDefaultWindowIcon(browser->window()->GetNativeHandle()); | 710 gtk_util::SetDefaultWindowIcon(browser->window()->GetNativeHandle()); |
700 } | 711 } |
701 } | 712 } |
702 | 713 |
703 void GtkThemeService::FreePlatformCaches() { | 714 void GtkThemeService::FreePlatformCaches() { |
704 ThemeService::FreePlatformCaches(); | 715 ThemeService::FreePlatformCaches(); |
705 FreePerDisplaySurfaces(&per_display_surfaces_); | 716 FreePerDisplaySurfaces(&per_display_surfaces_); |
706 FreePerDisplaySurfaces(&per_display_unthemed_surfaces_); | 717 FreePerDisplaySurfaces(&per_display_unthemed_surfaces_); |
| 718 FreePerDisplaySurfaces(&per_display_icon_surfaces_); |
707 STLDeleteValues(>k_images_); | 719 STLDeleteValues(>k_images_); |
708 } | 720 } |
709 | 721 |
710 void GtkThemeService::OnStyleSet(GtkWidget* widget, | 722 void GtkThemeService::OnStyleSet(GtkWidget* widget, |
711 GtkStyle* previous_style) { | 723 GtkStyle* previous_style) { |
712 GdkPixbuf* default_folder_icon = default_folder_icon_; | 724 GdkPixbuf* default_folder_icon = default_folder_icon_; |
713 GdkPixbuf* default_bookmark_icon = default_bookmark_icon_; | 725 GdkPixbuf* default_bookmark_icon = default_bookmark_icon_; |
714 default_folder_icon_ = NULL; | 726 default_folder_icon_ = NULL; |
715 default_bookmark_icon_ = NULL; | 727 default_bookmark_icon_ = NULL; |
716 | 728 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 // since the icons tinted this way will only be displayed against | 1129 // since the icons tinted this way will only be displayed against |
1118 // base[GTK_STATE_SELECTED]. | 1130 // base[GTK_STATE_SELECTED]. |
1119 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); | 1131 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); |
1120 const GdkColor color = style->text[GTK_STATE_SELECTED]; | 1132 const GdkColor color = style->text[GTK_STATE_SELECTED]; |
1121 color_utils::SkColorToHSL(GdkToSkColor(&color), tint); | 1133 color_utils::SkColorToHSL(GdkToSkColor(&color), tint); |
1122 } | 1134 } |
1123 | 1135 |
1124 CairoCachedSurface* GtkThemeService::GetSurfaceNamedImpl( | 1136 CairoCachedSurface* GtkThemeService::GetSurfaceNamedImpl( |
1125 int id, | 1137 int id, |
1126 PerDisplaySurfaceMap* display_surface_map, | 1138 PerDisplaySurfaceMap* display_surface_map, |
1127 GdkPixbuf* pixbuf, | 1139 PixbufProvidingMethod provider, |
1128 GtkWidget* widget_on_display) { | 1140 GtkWidget* widget_on_display) { |
1129 GdkDisplay* display = gtk_widget_get_display(widget_on_display); | 1141 GdkDisplay* display = gtk_widget_get_display(widget_on_display); |
1130 CairoCachedSurfaceMap& surface_map = (*display_surface_map)[display]; | 1142 CairoCachedSurfaceMap& surface_map = (*display_surface_map)[display]; |
1131 | 1143 |
1132 // Check to see if we already have the pixbuf in the cache. | 1144 // Check to see if we already have the pixbuf in the cache. |
1133 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); | 1145 CairoCachedSurfaceMap::const_iterator found = surface_map.find(id); |
1134 if (found != surface_map.end()) | 1146 if (found != surface_map.end()) |
1135 return found->second; | 1147 return found->second; |
1136 | 1148 |
1137 CairoCachedSurface* surface = new CairoCachedSurface; | 1149 CairoCachedSurface* surface = new CairoCachedSurface; |
1138 surface->UsePixbuf(pixbuf); | 1150 surface->UsePixbuf((this->*provider)(id)); |
1139 | 1151 |
1140 surface_map[id] = surface; | 1152 surface_map[id] = surface; |
1141 | 1153 |
1142 return surface; | 1154 return surface; |
1143 } | 1155 } |
1144 | 1156 |
| 1157 // PixbufProvidingMethod that undoes the negative sign on |id|. |
| 1158 GdkPixbuf* GtkThemeService::GetRTLEnabledPixbufNamedWrapper(int id) const { |
| 1159 return GetRTLEnabledPixbufNamed(-id); |
| 1160 } |
| 1161 |
| 1162 // PixbufProvidingMethod that just calls ResourceBundle. We want to minimize |
| 1163 // the calls to this method because it aquires an AutoLock and we don't want |
| 1164 // this to happen all the time. |
| 1165 GdkPixbuf* GtkThemeService::GetUnthemedNativePixbuf(int id) const { |
| 1166 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); |
| 1167 } |
| 1168 |
| 1169 // PixbufProvidingMethod that maps a GtkThemeService::CairoDefaultIcon to a |
| 1170 // GdkPixbuf. |
| 1171 GdkPixbuf* GtkThemeService::GetPixbufForIconId(int id) const { |
| 1172 switch (id) { |
| 1173 case GtkThemeService::NATIVE_FAVICON: |
| 1174 return GtkThemeService::GetDefaultFavicon(true); |
| 1175 case GtkThemeService::CHROME_FAVICON: |
| 1176 return GtkThemeService::GetDefaultFavicon(false); |
| 1177 case GtkThemeService::NATIVE_FOLDER: |
| 1178 return GtkThemeService::GetFolderIcon(true); |
| 1179 case GtkThemeService::CHROME_FOLDER: |
| 1180 return GtkThemeService::GetFolderIcon(false); |
| 1181 default: |
| 1182 NOTREACHED(); |
| 1183 return NULL; |
| 1184 } |
| 1185 } |
| 1186 |
1145 void GtkThemeService::OnDestroyChromeButton(GtkWidget* button) { | 1187 void GtkThemeService::OnDestroyChromeButton(GtkWidget* button) { |
1146 std::vector<GtkWidget*>::iterator it = | 1188 std::vector<GtkWidget*>::iterator it = |
1147 find(chrome_buttons_.begin(), chrome_buttons_.end(), button); | 1189 find(chrome_buttons_.begin(), chrome_buttons_.end(), button); |
1148 if (it != chrome_buttons_.end()) | 1190 if (it != chrome_buttons_.end()) |
1149 chrome_buttons_.erase(it); | 1191 chrome_buttons_.erase(it); |
1150 } | 1192 } |
1151 | 1193 |
1152 void GtkThemeService::OnDestroyChromeLinkButton(GtkWidget* button) { | 1194 void GtkThemeService::OnDestroyChromeLinkButton(GtkWidget* button) { |
1153 std::vector<GtkWidget*>::iterator it = | 1195 std::vector<GtkWidget*>::iterator it = |
1154 find(link_buttons_.begin(), link_buttons_.end(), button); | 1196 find(link_buttons_.begin(), link_buttons_.end(), button); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 cairo_set_line_width(cr, 1.0); | 1240 cairo_set_line_width(cr, 1.0); |
1199 cairo_move_to(cr, start_x, widget->allocation.y); | 1241 cairo_move_to(cr, start_x, widget->allocation.y); |
1200 cairo_line_to(cr, start_x, | 1242 cairo_line_to(cr, start_x, |
1201 widget->allocation.y + widget->allocation.height); | 1243 widget->allocation.y + widget->allocation.height); |
1202 cairo_stroke(cr); | 1244 cairo_stroke(cr); |
1203 cairo_destroy(cr); | 1245 cairo_destroy(cr); |
1204 cairo_pattern_destroy(pattern); | 1246 cairo_pattern_destroy(pattern); |
1205 | 1247 |
1206 return TRUE; | 1248 return TRUE; |
1207 } | 1249 } |
OLD | NEW |