Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc

Issue 8786003: GTK: Move tab_renderer_gtk.cc off of GetSurfaceNamed() and onto GetImageNamed(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase now that dependent patch is committed Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tabs/tab_renderer_gtk.h" 5 #include "chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 14 matching lines...) Expand all
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "grit/theme_resources_standard.h" 26 #include "grit/theme_resources_standard.h"
27 #include "grit/ui_resources.h" 27 #include "grit/ui_resources.h"
28 #include "ui/base/animation/slide_animation.h" 28 #include "ui/base/animation/slide_animation.h"
29 #include "ui/base/animation/throb_animation.h" 29 #include "ui/base/animation/throb_animation.h"
30 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/gfx/canvas_skia_paint.h" 32 #include "ui/gfx/canvas_skia_paint.h"
33 #include "ui/gfx/favicon_size.h" 33 #include "ui/gfx/favicon_size.h"
34 #include "ui/gfx/gtk_util.h" 34 #include "ui/gfx/gtk_util.h"
35 #include "ui/gfx/image/image.h"
35 #include "ui/gfx/image/cairo_cached_surface.h" 36 #include "ui/gfx/image/cairo_cached_surface.h"
36 #include "ui/gfx/pango_util.h" 37 #include "ui/gfx/pango_util.h"
37 #include "ui/gfx/platform_font_pango.h" 38 #include "ui/gfx/platform_font_pango.h"
38 #include "ui/gfx/skbitmap_operations.h" 39 #include "ui/gfx/skbitmap_operations.h"
39 #include "skia/ext/image_operations.h" 40 #include "skia/ext/image_operations.h"
40 41
41 #if !GTK_CHECK_VERSION(2, 22, 0) 42 #if !GTK_CHECK_VERSION(2, 22, 0)
42 #define gtk_button_get_event_window(button) button->event_window 43 #define gtk_button_get_event_window(button) button->event_window
43 #endif // Gtk+ >= 2.22 44 #endif // Gtk+ >= 2.22
44 45
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 theme_id = IDR_THEME_TOOLBAR; 477 theme_id = IDR_THEME_TOOLBAR;
477 } else { 478 } else {
478 theme_id = data_.incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : 479 theme_id = data_.incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO :
479 IDR_THEME_TAB_BACKGROUND; 480 IDR_THEME_TAB_BACKGROUND;
480 481
481 if (!theme_service_->HasCustomImage(theme_id)) 482 if (!theme_service_->HasCustomImage(theme_id))
482 offset_y = background_offset_y_; 483 offset_y = background_offset_y_;
483 } 484 }
484 485
485 // Paint the background behind the favicon. 486 // Paint the background behind the favicon.
486 gfx::CairoCachedSurface* tab_bg = 487 const gfx::Image* tab_bg = theme_service_->GetImageNamed(theme_id);
487 theme_service_->GetSurfaceNamed(theme_id, widget); 488 tab_bg->ToCairo()->SetSource(cr, widget, -x(), -offset_y);
488 tab_bg->SetSource(cr, widget, -x(), -offset_y);
489 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 489 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
490 cairo_rectangle(cr, 490 cairo_rectangle(cr,
491 favicon_bounds_.x(), favicon_bounds_.y(), 491 favicon_bounds_.x(), favicon_bounds_.y(),
492 favicon_bounds_.width(), favicon_bounds_.height()); 492 favicon_bounds_.width(), favicon_bounds_.height());
493 cairo_fill(cr); 493 cairo_fill(cr);
494 494
495 if (!IsActive()) { 495 if (!IsActive()) {
496 double throb_value = GetThrobValue(); 496 double throb_value = GetThrobValue();
497 if (throb_value > 0) { 497 if (throb_value > 0) {
498 cairo_push_group(cr); 498 cairo_push_group(cr);
499 gfx::CairoCachedSurface* active_bg = theme_service_->GetSurfaceNamed( 499 const gfx::Image* active_bg =
500 IDR_THEME_TOOLBAR, widget); 500 theme_service_->GetImageNamed(IDR_THEME_TOOLBAR);
501 active_bg->SetSource(cr, widget, -x(), 0); 501 active_bg->ToCairo()->SetSource(cr, widget, -x(), 0);
502 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 502 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
503 503
504 cairo_rectangle(cr, 504 cairo_rectangle(cr,
505 favicon_bounds_.x(), favicon_bounds_.y(), 505 favicon_bounds_.x(), favicon_bounds_.y(),
506 favicon_bounds_.width(), favicon_bounds_.height()); 506 favicon_bounds_.width(), favicon_bounds_.height());
507 cairo_fill(cr); 507 cairo_fill(cr);
508 508
509 cairo_pop_group_to_source(cr); 509 cairo_pop_group_to_source(cr);
510 cairo_paint_with_alpha(cr, throb_value); 510 cairo_paint_with_alpha(cr, throb_value);
511 } 511 }
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 } 854 }
855 855
856 void TabRendererGtk::PaintIcon(GtkWidget* widget, cairo_t* cr) { 856 void TabRendererGtk::PaintIcon(GtkWidget* widget, cairo_t* cr) {
857 if (loading_animation_.animation_state() != ANIMATION_NONE) { 857 if (loading_animation_.animation_state() != ANIMATION_NONE) {
858 PaintLoadingAnimation(widget, cr); 858 PaintLoadingAnimation(widget, cr);
859 return; 859 return;
860 } 860 }
861 861
862 gfx::CairoCachedSurface* to_display = NULL; 862 gfx::CairoCachedSurface* to_display = NULL;
863 if (should_display_crashed_favicon_) { 863 if (should_display_crashed_favicon_) {
864 to_display = theme_service_->GetSurfaceNamed(IDR_SAD_FAVICON, widget); 864 to_display = theme_service_->GetImageNamed(IDR_SAD_FAVICON)->ToCairo();
865 } else if (!data_.favicon.isNull()) { 865 } else if (!data_.favicon.isNull()) {
866 if (data_.is_default_favicon && theme_service_->UsingNativeTheme()) { 866 if (data_.is_default_favicon && theme_service_->UsingNativeTheme()) {
867 to_display = theme_service_->GetCairoIcon( 867 to_display = theme_service_->GetCairoIcon(
868 GtkThemeService::NATIVE_FAVICON, widget); 868 GtkThemeService::NATIVE_FAVICON, widget);
869 } else if (data_.cairo_favicon.valid()) { 869 } else if (data_.cairo_favicon.valid()) {
870 to_display = &data_.cairo_favicon; 870 to_display = &data_.cairo_favicon;
871 } 871 }
872 } 872 }
873 873
874 if (to_display) { 874 if (to_display) {
(...skipping 17 matching lines...) Expand all
892 PaintActiveTabBackground(widget, cr); 892 PaintActiveTabBackground(widget, cr);
893 cairo_pop_group_to_source(cr); 893 cairo_pop_group_to_source(cr);
894 cairo_paint_with_alpha(cr, throb_value); 894 cairo_paint_with_alpha(cr, throb_value);
895 } 895 }
896 } 896 }
897 } 897 }
898 898
899 void TabRendererGtk::DrawTabBackground( 899 void TabRendererGtk::DrawTabBackground(
900 cairo_t* cr, 900 cairo_t* cr,
901 GtkWidget* widget, 901 GtkWidget* widget,
902 gfx::CairoCachedSurface* tab_bg, 902 const gfx::Image* tab_bg,
903 int offset_x, 903 int offset_x,
904 int offset_y) { 904 int offset_y) {
905 tab_bg->SetSource(cr, widget, -offset_x, -offset_y); 905 tab_bg->ToCairo()->SetSource(cr, widget, -offset_x, -offset_y);
906 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 906 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
907 907
908 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
909
908 // Draw left edge 910 // Draw left edge
909 gfx::CairoCachedSurface* tab_l_mask = 911 gfx::Image& tab_l_mask = rb.GetNativeImageNamed(IDR_TAB_ALPHA_LEFT);
910 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_LEFT, widget); 912 tab_l_mask.ToCairo()->MaskSource(cr, widget, 0, 0);
911 tab_l_mask->MaskSource(cr, widget, 0, 0);
912 913
913 // Draw center 914 // Draw center
914 cairo_rectangle(cr, 915 cairo_rectangle(cr,
915 tab_active_l_width_, kDropShadowOffset, 916 tab_active_l_width_, kDropShadowOffset,
916 width() - (2 * tab_active_l_width_), 917 width() - (2 * tab_active_l_width_),
917 tab_inactive_l_height_); 918 tab_inactive_l_height_);
918 cairo_fill(cr); 919 cairo_fill(cr);
919 920
920 // Draw right edge 921 // Draw right edge
921 gfx::CairoCachedSurface* tab_r_mask = 922 gfx::Image& tab_r_mask = rb.GetNativeImageNamed(IDR_TAB_ALPHA_RIGHT);
922 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_RIGHT, widget); 923 tab_r_mask.ToCairo()->MaskSource(cr, widget,
923 tab_r_mask->MaskSource(cr, widget, width() - tab_active_l_width_, 0); 924 width() - tab_active_l_width_, 0);
924 } 925 }
925 926
926 void TabRendererGtk::DrawTabShadow( 927 void TabRendererGtk::DrawTabShadow(
927 cairo_t* cr, 928 cairo_t* cr,
928 GtkWidget* widget, 929 GtkWidget* widget,
929 int left_idr, 930 int left_idr,
930 int center_idr, 931 int center_idr,
931 int right_idr) { 932 int right_idr) {
933 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
934 gfx::Image& active_image_l = rb.GetNativeImageNamed(left_idr);
935 gfx::Image& active_image_c = rb.GetNativeImageNamed(center_idr);
936 gfx::Image& active_image_r = rb.GetNativeImageNamed(right_idr);
937
932 // Draw left drop shadow 938 // Draw left drop shadow
933 gfx::CairoCachedSurface* active_image_l = 939 active_image_l.ToCairo()->SetSource(cr, widget, 0, 0);
934 theme_service_->GetSurfaceNamed(left_idr, widget);
935 active_image_l->SetSource(cr, widget, 0, 0);
936 cairo_paint(cr); 940 cairo_paint(cr);
937 941
938 // Draw the center shadow 942 // Draw the center shadow
939 gfx::CairoCachedSurface* active_image_c = 943 active_image_c.ToCairo()->SetSource(cr, widget, 0, 0);
940 theme_service_->GetSurfaceNamed(center_idr, widget);
941 active_image_c->SetSource(cr, widget, 0, 0);
942 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 944 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
943 cairo_rectangle(cr, tab_active_l_width_, 0, 945 cairo_rectangle(cr, tab_active_l_width_, 0,
944 width() - (2 * tab_active_l_width_), 946 width() - (2 * tab_active_l_width_),
945 height()); 947 height());
946 cairo_fill(cr); 948 cairo_fill(cr);
947 949
948 // Draw right drop shadow 950 // Draw right drop shadow
949 gfx::CairoCachedSurface* active_image_r = 951 active_image_r.ToCairo()->SetSource(
950 theme_service_->GetSurfaceNamed(right_idr, widget); 952 cr, widget, width() - active_image_r.ToCairo()->Width(), 0);
951 active_image_r->SetSource(cr, widget, width() - active_image_r->Width(), 0);
952 cairo_paint(cr); 953 cairo_paint(cr);
953 } 954 }
954 955
955 void TabRendererGtk::PaintInactiveTabBackground(GtkWidget* widget, 956 void TabRendererGtk::PaintInactiveTabBackground(GtkWidget* widget,
956 cairo_t* cr) { 957 cairo_t* cr) {
957 int theme_id = data_.incognito ? 958 int theme_id = data_.incognito ?
958 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; 959 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND;
959 960
960 gfx::CairoCachedSurface* tab_bg = 961 const gfx::Image* tab_bg = theme_service_->GetImageNamed(theme_id);
961 theme_service_->GetSurfaceNamed(theme_id, widget);
962 962
963 // If the theme is providing a custom background image, then its top edge 963 // If the theme is providing a custom background image, then its top edge
964 // should be at the top of the tab. Otherwise, we assume that the background 964 // should be at the top of the tab. Otherwise, we assume that the background
965 // image is a composited foreground + frame image. 965 // image is a composited foreground + frame image.
966 int offset_y = theme_service_->HasCustomImage(theme_id) ? 966 int offset_y = theme_service_->HasCustomImage(theme_id) ?
967 0 : background_offset_y_; 967 0 : background_offset_y_;
968 968
969 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, offset_y); 969 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, offset_y);
970 970
971 DrawTabShadow(cr, widget, IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER, 971 DrawTabShadow(cr, widget, IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER,
972 IDR_TAB_INACTIVE_RIGHT); 972 IDR_TAB_INACTIVE_RIGHT);
973 } 973 }
974 974
975 void TabRendererGtk::PaintActiveTabBackground(GtkWidget* widget, 975 void TabRendererGtk::PaintActiveTabBackground(GtkWidget* widget,
976 cairo_t* cr) { 976 cairo_t* cr) {
977 gfx::CairoCachedSurface* tab_bg = 977 const gfx::Image* tab_bg = theme_service_->GetImageNamed(IDR_THEME_TOOLBAR);
978 theme_service_->GetSurfaceNamed(IDR_THEME_TOOLBAR, widget);
979 978
980 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, 0); 979 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, 0);
981 DrawTabShadow(cr, widget, IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER, 980 DrawTabShadow(cr, widget, IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER,
982 IDR_TAB_ACTIVE_RIGHT); 981 IDR_TAB_ACTIVE_RIGHT);
983 } 982 }
984 983
985 void TabRendererGtk::PaintLoadingAnimation(GtkWidget* widget, 984 void TabRendererGtk::PaintLoadingAnimation(GtkWidget* widget,
986 cairo_t* cr) { 985 cairo_t* cr) {
987 int id = loading_animation_.animation_state() == ANIMATION_WAITING ? 986 int id = loading_animation_.animation_state() == ANIMATION_WAITING ?
988 IDR_THROBBER_WAITING : IDR_THROBBER; 987 IDR_THROBBER_WAITING : IDR_THROBBER;
989 gfx::CairoCachedSurface* throbber = 988 const gfx::Image* throbber = theme_service_->GetImageNamed(id);
990 theme_service_->GetSurfaceNamed(id, widget);
991 989
992 const int image_size = throbber->Height(); 990 const int image_size = throbber->ToCairo()->Height();
993 const int image_offset = loading_animation_.animation_frame() * image_size; 991 const int image_offset = loading_animation_.animation_frame() * image_size;
994 DCHECK(image_size == favicon_bounds_.height()); 992 DCHECK(image_size == favicon_bounds_.height());
995 DCHECK(image_size == favicon_bounds_.width()); 993 DCHECK(image_size == favicon_bounds_.width());
996 994
997 throbber->SetSource(cr, widget, favicon_bounds_.x() - image_offset, 995 throbber->ToCairo()->SetSource(cr, widget, favicon_bounds_.x() - image_offset,
998 favicon_bounds_.y()); 996 favicon_bounds_.y());
999 cairo_rectangle(cr, favicon_bounds_.x(), favicon_bounds_.y(), 997 cairo_rectangle(cr, favicon_bounds_.x(), favicon_bounds_.y(),
1000 image_size, image_size); 998 image_size, image_size);
1001 cairo_fill(cr); 999 cairo_fill(cr);
1002 } 1000 }
1003 1001
1004 int TabRendererGtk::IconCapacity() const { 1002 int TabRendererGtk::IconCapacity() const {
1005 if (height() < GetMinimumUnselectedSize().height()) 1003 if (height() < GetMinimumUnselectedSize().height())
1006 return 0; 1004 return 0;
1007 return (width() - kLeftPadding - kRightPadding) / gfx::kFaviconSize; 1005 return (width() - kLeftPadding - kRightPadding) / gfx::kFaviconSize;
1008 } 1006 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 return FALSE; 1101 return FALSE;
1104 } 1102 }
1105 1103
1106 // static 1104 // static
1107 void TabRendererGtk::InitResources() { 1105 void TabRendererGtk::InitResources() {
1108 if (initialized_) 1106 if (initialized_)
1109 return; 1107 return;
1110 1108
1111 // Grab the pixel sizes of our masking images. 1109 // Grab the pixel sizes of our masking images.
1112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1110 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1113 SkBitmap* tab_active_l = rb.GetBitmapNamed(IDR_TAB_ACTIVE_LEFT); 1111 GdkPixbuf* tab_active_l = rb.GetNativeImageNamed(IDR_TAB_ACTIVE_LEFT);
Elliot Glaysher 2011/12/05 22:52:16 This makes sure that the image representation of t
1114 tab_active_l_width_ = tab_active_l->width(); 1112 tab_active_l_width_ = gdk_pixbuf_get_width(tab_active_l);
1115 tab_active_l_height_ = tab_active_l->height(); 1113 tab_active_l_height_ = gdk_pixbuf_get_height(tab_active_l);
1116 1114
1117 SkBitmap* tab_inactive_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); 1115 GdkPixbuf* tab_inactive_l = rb.GetNativeImageNamed(IDR_TAB_INACTIVE_LEFT);
1118 tab_inactive_l_height_ = tab_inactive_l->height(); 1116 tab_inactive_l_height_ = gdk_pixbuf_get_height(tab_inactive_l);
1119 1117
1120 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); 1118 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width();
1121 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); 1119 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height();
1122 1120
1123 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); 1121 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
1124 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); 1122 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize);
1125 title_font_height_ = title_font_->GetHeight(); 1123 title_font_height_ = title_font_->GetHeight();
1126 1124
1127 initialized_ = true; 1125 initialized_ = true;
1128 } 1126 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698