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

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

Issue 8769017: GTK: Move CairoCachedSurface from being owned by GtkThemeService to gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase for commit 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') | chrome/chrome_browser.gypi » ('j') | 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"
11 #include "chrome/browser/defaults.h" 11 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/extensions/extension_tab_helper.h" 12 #include "chrome/browser/extensions/extension_tab_helper.h"
13 #include "chrome/browser/favicon/favicon_tab_helper.h" 13 #include "chrome/browser/favicon/favicon_tab_helper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" 16 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
17 #include "chrome/browser/ui/gtk/cairo_cached_surface.h"
18 #include "chrome/browser/ui/gtk/custom_button.h" 17 #include "chrome/browser/ui/gtk/custom_button.h"
19 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 18 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
20 #include "chrome/browser/ui/gtk/gtk_util.h" 19 #include "chrome/browser/ui/gtk/gtk_util.h"
21 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
23 #include "content/browser/tab_contents/tab_contents.h" 22 #include "content/browser/tab_contents/tab_contents.h"
24 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
25 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
26 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
27 #include "grit/theme_resources_standard.h" 26 #include "grit/theme_resources_standard.h"
28 #include "grit/ui_resources.h" 27 #include "grit/ui_resources.h"
29 #include "ui/base/animation/slide_animation.h" 28 #include "ui/base/animation/slide_animation.h"
30 #include "ui/base/animation/throb_animation.h" 29 #include "ui/base/animation/throb_animation.h"
31 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/canvas_skia_paint.h" 32 #include "ui/gfx/canvas_skia_paint.h"
34 #include "ui/gfx/favicon_size.h" 33 #include "ui/gfx/favicon_size.h"
35 #include "ui/gfx/gtk_util.h" 34 #include "ui/gfx/gtk_util.h"
35 #include "ui/gfx/image/cairo_cached_surface.h"
36 #include "ui/gfx/pango_util.h" 36 #include "ui/gfx/pango_util.h"
37 #include "ui/gfx/platform_font_pango.h" 37 #include "ui/gfx/platform_font_pango.h"
38 #include "ui/gfx/skbitmap_operations.h" 38 #include "ui/gfx/skbitmap_operations.h"
39 #include "skia/ext/image_operations.h" 39 #include "skia/ext/image_operations.h"
40 40
41 #if !GTK_CHECK_VERSION(2, 22, 0) 41 #if !GTK_CHECK_VERSION(2, 22, 0)
42 #define gtk_button_get_event_window(button) button->event_window 42 #define gtk_button_get_event_window(button) button->event_window
43 #endif // Gtk+ >= 2.22 43 #endif // Gtk+ >= 2.22
44 44
45 namespace { 45 namespace {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 theme_id = IDR_THEME_TOOLBAR; 476 theme_id = IDR_THEME_TOOLBAR;
477 } else { 477 } else {
478 theme_id = data_.incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : 478 theme_id = data_.incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO :
479 IDR_THEME_TAB_BACKGROUND; 479 IDR_THEME_TAB_BACKGROUND;
480 480
481 if (!theme_service_->HasCustomImage(theme_id)) 481 if (!theme_service_->HasCustomImage(theme_id))
482 offset_y = background_offset_y_; 482 offset_y = background_offset_y_;
483 } 483 }
484 484
485 // Paint the background behind the favicon. 485 // Paint the background behind the favicon.
486 CairoCachedSurface* tab_bg = 486 gfx::CairoCachedSurface* tab_bg =
487 theme_service_->GetSurfaceNamed(theme_id, widget); 487 theme_service_->GetSurfaceNamed(theme_id, widget);
488 tab_bg->SetSource(cr, -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 CairoCachedSurface* active_bg = theme_service_->GetSurfaceNamed( 499 gfx::CairoCachedSurface* active_bg = theme_service_->GetSurfaceNamed(
500 IDR_THEME_TOOLBAR, widget); 500 IDR_THEME_TOOLBAR, widget);
501 active_bg->SetSource(cr, -x(), 0); 501 active_bg->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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 base::i18n::IsRTL() ? gfx::Canvas::TEXT_ALIGN_RIGHT : 852 base::i18n::IsRTL() ? gfx::Canvas::TEXT_ALIGN_RIGHT :
853 gfx::Canvas::TEXT_ALIGN_LEFT); 853 gfx::Canvas::TEXT_ALIGN_LEFT);
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 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_->GetSurfaceNamed(IDR_SAD_FAVICON, widget);
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) {
875 to_display->SetSource(cr, 875 to_display->SetSource(cr,
876 widget,
876 favicon_bounds_.x(), 877 favicon_bounds_.x(),
877 favicon_bounds_.y() + favicon_hiding_offset_); 878 favicon_bounds_.y() + favicon_hiding_offset_);
878 cairo_paint(cr); 879 cairo_paint(cr);
879 } 880 }
880 } 881 }
881 882
882 void TabRendererGtk::PaintTabBackground(GtkWidget* widget, cairo_t* cr) { 883 void TabRendererGtk::PaintTabBackground(GtkWidget* widget, cairo_t* cr) {
883 if (IsActive()) { 884 if (IsActive()) {
884 PaintActiveTabBackground(widget, cr); 885 PaintActiveTabBackground(widget, cr);
885 } else { 886 } else {
886 PaintInactiveTabBackground(widget, cr); 887 PaintInactiveTabBackground(widget, cr);
887 888
888 double throb_value = GetThrobValue(); 889 double throb_value = GetThrobValue();
889 if (throb_value > 0) { 890 if (throb_value > 0) {
890 cairo_push_group(cr); 891 cairo_push_group(cr);
891 PaintActiveTabBackground(widget, cr); 892 PaintActiveTabBackground(widget, cr);
892 cairo_pop_group_to_source(cr); 893 cairo_pop_group_to_source(cr);
893 cairo_paint_with_alpha(cr, throb_value); 894 cairo_paint_with_alpha(cr, throb_value);
894 } 895 }
895 } 896 }
896 } 897 }
897 898
898 void TabRendererGtk::DrawTabBackground( 899 void TabRendererGtk::DrawTabBackground(
899 cairo_t* cr, 900 cairo_t* cr,
900 GtkWidget* widget, 901 GtkWidget* widget,
901 CairoCachedSurface* tab_bg, 902 gfx::CairoCachedSurface* tab_bg,
902 int offset_x, 903 int offset_x,
903 int offset_y) { 904 int offset_y) {
904 tab_bg->SetSource(cr, -offset_x, -offset_y); 905 tab_bg->SetSource(cr, widget, -offset_x, -offset_y);
905 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 906 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
906 907
907 // Draw left edge 908 // Draw left edge
908 CairoCachedSurface* tab_l_mask = 909 gfx::CairoCachedSurface* tab_l_mask =
909 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_LEFT, widget); 910 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_LEFT, widget);
910 tab_l_mask->MaskSource(cr, 0, 0); 911 tab_l_mask->MaskSource(cr, widget, 0, 0);
911 912
912 // Draw center 913 // Draw center
913 cairo_rectangle(cr, 914 cairo_rectangle(cr,
914 tab_active_l_width_, kDropShadowOffset, 915 tab_active_l_width_, kDropShadowOffset,
915 width() - (2 * tab_active_l_width_), 916 width() - (2 * tab_active_l_width_),
916 tab_inactive_l_height_); 917 tab_inactive_l_height_);
917 cairo_fill(cr); 918 cairo_fill(cr);
918 919
919 // Draw right edge 920 // Draw right edge
920 CairoCachedSurface* tab_r_mask = 921 gfx::CairoCachedSurface* tab_r_mask =
921 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_RIGHT, widget); 922 theme_service_->GetSurfaceNamed(IDR_TAB_ALPHA_RIGHT, widget);
922 tab_r_mask->MaskSource(cr, width() - tab_active_l_width_, 0); 923 tab_r_mask->MaskSource(cr, widget, width() - tab_active_l_width_, 0);
923 } 924 }
924 925
925 void TabRendererGtk::DrawTabShadow( 926 void TabRendererGtk::DrawTabShadow(
926 cairo_t* cr, 927 cairo_t* cr,
927 GtkWidget* widget, 928 GtkWidget* widget,
928 int left_idr, 929 int left_idr,
929 int center_idr, 930 int center_idr,
930 int right_idr) { 931 int right_idr) {
931 // Draw left drop shadow 932 // Draw left drop shadow
932 CairoCachedSurface* active_image_l = 933 gfx::CairoCachedSurface* active_image_l =
933 theme_service_->GetSurfaceNamed(left_idr, widget); 934 theme_service_->GetSurfaceNamed(left_idr, widget);
934 active_image_l->SetSource(cr, 0, 0); 935 active_image_l->SetSource(cr, widget, 0, 0);
935 cairo_paint(cr); 936 cairo_paint(cr);
936 937
937 // Draw the center shadow 938 // Draw the center shadow
938 CairoCachedSurface* active_image_c = 939 gfx::CairoCachedSurface* active_image_c =
939 theme_service_->GetSurfaceNamed(center_idr, widget); 940 theme_service_->GetSurfaceNamed(center_idr, widget);
940 active_image_c->SetSource(cr, 0, 0); 941 active_image_c->SetSource(cr, widget, 0, 0);
941 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 942 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
942 cairo_rectangle(cr, tab_active_l_width_, 0, 943 cairo_rectangle(cr, tab_active_l_width_, 0,
943 width() - (2 * tab_active_l_width_), 944 width() - (2 * tab_active_l_width_),
944 height()); 945 height());
945 cairo_fill(cr); 946 cairo_fill(cr);
946 947
947 // Draw right drop shadow 948 // Draw right drop shadow
948 CairoCachedSurface* active_image_r = 949 gfx::CairoCachedSurface* active_image_r =
949 theme_service_->GetSurfaceNamed(right_idr, widget); 950 theme_service_->GetSurfaceNamed(right_idr, widget);
950 active_image_r->SetSource(cr, width() - active_image_r->Width(), 0); 951 active_image_r->SetSource(cr, widget, width() - active_image_r->Width(), 0);
951 cairo_paint(cr); 952 cairo_paint(cr);
952 } 953 }
953 954
954 void TabRendererGtk::PaintInactiveTabBackground(GtkWidget* widget, 955 void TabRendererGtk::PaintInactiveTabBackground(GtkWidget* widget,
955 cairo_t* cr) { 956 cairo_t* cr) {
956 int theme_id = data_.incognito ? 957 int theme_id = data_.incognito ?
957 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; 958 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND;
958 959
959 CairoCachedSurface* tab_bg = 960 gfx::CairoCachedSurface* tab_bg =
960 theme_service_->GetSurfaceNamed(theme_id, widget); 961 theme_service_->GetSurfaceNamed(theme_id, widget);
961 962
962 // 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
963 // 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
964 // image is a composited foreground + frame image. 965 // image is a composited foreground + frame image.
965 int offset_y = theme_service_->HasCustomImage(theme_id) ? 966 int offset_y = theme_service_->HasCustomImage(theme_id) ?
966 0 : background_offset_y_; 967 0 : background_offset_y_;
967 968
968 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, offset_y); 969 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, offset_y);
969 970
970 DrawTabShadow(cr, widget, IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER, 971 DrawTabShadow(cr, widget, IDR_TAB_INACTIVE_LEFT, IDR_TAB_INACTIVE_CENTER,
971 IDR_TAB_INACTIVE_RIGHT); 972 IDR_TAB_INACTIVE_RIGHT);
972 } 973 }
973 974
974 void TabRendererGtk::PaintActiveTabBackground(GtkWidget* widget, 975 void TabRendererGtk::PaintActiveTabBackground(GtkWidget* widget,
975 cairo_t* cr) { 976 cairo_t* cr) {
976 CairoCachedSurface* tab_bg = 977 gfx::CairoCachedSurface* tab_bg =
977 theme_service_->GetSurfaceNamed(IDR_THEME_TOOLBAR, widget); 978 theme_service_->GetSurfaceNamed(IDR_THEME_TOOLBAR, widget);
978 979
979 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, 0); 980 DrawTabBackground(cr, widget, tab_bg, background_offset_x_, 0);
980 DrawTabShadow(cr, widget, IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER, 981 DrawTabShadow(cr, widget, IDR_TAB_ACTIVE_LEFT, IDR_TAB_ACTIVE_CENTER,
981 IDR_TAB_ACTIVE_RIGHT); 982 IDR_TAB_ACTIVE_RIGHT);
982 } 983 }
983 984
984 void TabRendererGtk::PaintLoadingAnimation(GtkWidget* widget, 985 void TabRendererGtk::PaintLoadingAnimation(GtkWidget* widget,
985 cairo_t* cr) { 986 cairo_t* cr) {
986 int id = loading_animation_.animation_state() == ANIMATION_WAITING ? 987 int id = loading_animation_.animation_state() == ANIMATION_WAITING ?
987 IDR_THROBBER_WAITING : IDR_THROBBER; 988 IDR_THROBBER_WAITING : IDR_THROBBER;
988 CairoCachedSurface* throbber = theme_service_->GetSurfaceNamed(id, widget); 989 gfx::CairoCachedSurface* throbber =
990 theme_service_->GetSurfaceNamed(id, widget);
989 991
990 const int image_size = throbber->Height(); 992 const int image_size = throbber->Height();
991 const int image_offset = loading_animation_.animation_frame() * image_size; 993 const int image_offset = loading_animation_.animation_frame() * image_size;
992 DCHECK(image_size == favicon_bounds_.height()); 994 DCHECK(image_size == favicon_bounds_.height());
993 DCHECK(image_size == favicon_bounds_.width()); 995 DCHECK(image_size == favicon_bounds_.width());
994 996
995 throbber->SetSource(cr, favicon_bounds_.x() - image_offset, 997 throbber->SetSource(cr, widget, favicon_bounds_.x() - image_offset,
996 favicon_bounds_.y()); 998 favicon_bounds_.y());
997 cairo_rectangle(cr, favicon_bounds_.x(), favicon_bounds_.y(), 999 cairo_rectangle(cr, favicon_bounds_.x(), favicon_bounds_.y(),
998 image_size, image_size); 1000 image_size, image_size);
999 cairo_fill(cr); 1001 cairo_fill(cr);
1000 } 1002 }
1001 1003
1002 int TabRendererGtk::IconCapacity() const { 1004 int TabRendererGtk::IconCapacity() const {
1003 if (height() < GetMinimumUnselectedSize().height()) 1005 if (height() < GetMinimumUnselectedSize().height())
1004 return 0; 1006 return 0;
1005 return (width() - kLeftPadding - kRightPadding) / gfx::kFaviconSize; 1007 return (width() - kLeftPadding - kRightPadding) / gfx::kFaviconSize;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 1119
1118 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width(); 1120 close_button_width_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->width();
1119 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height(); 1121 close_button_height_ = rb.GetBitmapNamed(IDR_TAB_CLOSE)->height();
1120 1122
1121 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); 1123 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
1122 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); 1124 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize);
1123 title_font_height_ = title_font_->GetHeight(); 1125 title_font_height_ = title_font_->GetHeight();
1124 1126
1125 initialized_ = true; 1127 initialized_ = true;
1126 } 1128 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698