OLD | NEW |
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 const SkScalar kTabCapWidth = 15; | 71 const SkScalar kTabCapWidth = 15; |
72 const SkScalar kTabTopCurveWidth = 4; | 72 const SkScalar kTabTopCurveWidth = 4; |
73 const SkScalar kTabBottomCurveWidth = 3; | 73 const SkScalar kTabBottomCurveWidth = 3; |
74 | 74 |
75 // The vertical and horizontal offset used to position the close button | 75 // The vertical and horizontal offset used to position the close button |
76 // in the tab. TODO(jhawkins): Ask pkasting what the Fuzz is about. | 76 // in the tab. TODO(jhawkins): Ask pkasting what the Fuzz is about. |
77 const int kCloseButtonVertFuzz = 0; | 77 const int kCloseButtonVertFuzz = 0; |
78 const int kCloseButtonHorzFuzz = 5; | 78 const int kCloseButtonHorzFuzz = 5; |
79 | 79 |
80 SkBitmap* crashed_fav_icon = NULL; | 80 SkBitmap* crashed_favicon = NULL; |
81 | 81 |
82 // Gets the bounds of |widget| relative to |parent|. | 82 // Gets the bounds of |widget| relative to |parent|. |
83 gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent, | 83 gfx::Rect GetWidgetBoundsRelativeToParent(GtkWidget* parent, |
84 GtkWidget* widget) { | 84 GtkWidget* widget) { |
85 gfx::Point parent_pos = gtk_util::GetWidgetScreenPosition(parent); | 85 gfx::Point parent_pos = gtk_util::GetWidgetScreenPosition(parent); |
86 gfx::Point widget_pos = gtk_util::GetWidgetScreenPosition(widget); | 86 gfx::Point widget_pos = gtk_util::GetWidgetScreenPosition(widget); |
87 return gfx::Rect(widget_pos.x() - parent_pos.x(), | 87 return gfx::Rect(widget_pos.x() - parent_pos.x(), |
88 widget_pos.y() - parent_pos.y(), | 88 widget_pos.y() - parent_pos.y(), |
89 widget->allocation.width, widget->allocation.height); | 89 widget->allocation.width, widget->allocation.height); |
90 } | 90 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); | 243 DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation); |
244 }; | 244 }; |
245 | 245 |
246 //////////////////////////////////////////////////////////////////////////////// | 246 //////////////////////////////////////////////////////////////////////////////// |
247 // TabRendererGtk, public: | 247 // TabRendererGtk, public: |
248 | 248 |
249 TabRendererGtk::TabRendererGtk(ui::ThemeProvider* theme_provider) | 249 TabRendererGtk::TabRendererGtk(ui::ThemeProvider* theme_provider) |
250 : showing_icon_(false), | 250 : showing_icon_(false), |
251 showing_close_button_(false), | 251 showing_close_button_(false), |
252 fav_icon_hiding_offset_(0), | 252 favicon_hiding_offset_(0), |
253 should_display_crashed_favicon_(false), | 253 should_display_crashed_favicon_(false), |
254 loading_animation_(theme_provider), | 254 loading_animation_(theme_provider), |
255 background_offset_x_(0), | 255 background_offset_x_(0), |
256 background_offset_y_(kInactiveTabBackgroundOffsetY), | 256 background_offset_y_(kInactiveTabBackgroundOffsetY), |
257 close_button_color_(0) { | 257 close_button_color_(0) { |
258 InitResources(); | 258 InitResources(); |
259 | 259 |
260 tab_.Own(gtk_fixed_new()); | 260 tab_.Own(gtk_fixed_new()); |
261 gtk_widget_set_app_paintable(tab_.get(), TRUE); | 261 gtk_widget_set_app_paintable(tab_.get(), TRUE); |
262 g_signal_connect(tab_.get(), "expose-event", | 262 g_signal_connect(tab_.get(), "expose-event", |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 if (!crash_animation_.get()) | 598 if (!crash_animation_.get()) |
599 return; | 599 return; |
600 crash_animation_->Stop(); | 600 crash_animation_->Stop(); |
601 } | 601 } |
602 | 602 |
603 bool TabRendererGtk::IsPerformingCrashAnimation() const { | 603 bool TabRendererGtk::IsPerformingCrashAnimation() const { |
604 return crash_animation_.get() && crash_animation_->is_animating(); | 604 return crash_animation_.get() && crash_animation_->is_animating(); |
605 } | 605 } |
606 | 606 |
607 void TabRendererGtk::SetFaviconHidingOffset(int offset) { | 607 void TabRendererGtk::SetFaviconHidingOffset(int offset) { |
608 fav_icon_hiding_offset_ = offset; | 608 favicon_hiding_offset_ = offset; |
609 SchedulePaint(); | 609 SchedulePaint(); |
610 } | 610 } |
611 | 611 |
612 void TabRendererGtk::DisplayCrashedFavIcon() { | 612 void TabRendererGtk::DisplayCrashedFavIcon() { |
613 should_display_crashed_favicon_ = true; | 613 should_display_crashed_favicon_ = true; |
614 } | 614 } |
615 | 615 |
616 void TabRendererGtk::ResetCrashedFavIcon() { | 616 void TabRendererGtk::ResetCrashedFavIcon() { |
617 should_display_crashed_favicon_ = false; | 617 should_display_crashed_favicon_ = false; |
618 } | 618 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 title_bounds_.width(), title_bounds_.height()); | 821 title_bounds_.width(), title_bounds_.height()); |
822 } | 822 } |
823 | 823 |
824 void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { | 824 void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { |
825 if (loading_animation_.animation_state() != ANIMATION_NONE) { | 825 if (loading_animation_.animation_state() != ANIMATION_NONE) { |
826 PaintLoadingAnimation(canvas); | 826 PaintLoadingAnimation(canvas); |
827 } else { | 827 } else { |
828 canvas->Save(); | 828 canvas->Save(); |
829 canvas->ClipRectInt(0, 0, width(), height() - kFavIconTitleSpacing); | 829 canvas->ClipRectInt(0, 0, width(), height() - kFavIconTitleSpacing); |
830 if (should_display_crashed_favicon_) { | 830 if (should_display_crashed_favicon_) { |
831 canvas->DrawBitmapInt(*crashed_fav_icon, 0, 0, | 831 canvas->DrawBitmapInt(*crashed_favicon, 0, 0, |
832 crashed_fav_icon->width(), | 832 crashed_favicon->width(), |
833 crashed_fav_icon->height(), | 833 crashed_favicon->height(), |
834 favicon_bounds_.x(), | 834 favicon_bounds_.x(), |
835 favicon_bounds_.y() + fav_icon_hiding_offset_, | 835 favicon_bounds_.y() + favicon_hiding_offset_, |
836 kFaviconSize, kFaviconSize, | 836 kFaviconSize, kFaviconSize, |
837 true); | 837 true); |
838 } else { | 838 } else { |
839 if (!data_.favicon.isNull()) { | 839 if (!data_.favicon.isNull()) { |
840 if (data_.is_default_favicon && theme_provider_->UseGtkTheme()) { | 840 if (data_.is_default_favicon && theme_provider_->UseGtkTheme()) { |
841 GdkPixbuf* favicon = GtkThemeProvider::GetDefaultFavicon(true); | 841 GdkPixbuf* favicon = GtkThemeProvider::GetDefaultFavicon(true); |
842 canvas->AsCanvasSkia()->DrawGdkPixbuf( | 842 canvas->AsCanvasSkia()->DrawGdkPixbuf( |
843 favicon, favicon_bounds_.x(), | 843 favicon, favicon_bounds_.x(), |
844 favicon_bounds_.y() + fav_icon_hiding_offset_); | 844 favicon_bounds_.y() + favicon_hiding_offset_); |
845 } else { | 845 } else { |
846 // If the favicon is an app icon, it is allowed to be drawn slightly | 846 // If the favicon is an app icon, it is allowed to be drawn slightly |
847 // larger than the standard favicon. | 847 // larger than the standard favicon. |
848 int favIconHeightOffset = data_.app ? -2 : 0; | 848 int favIconHeightOffset = data_.app ? -2 : 0; |
849 int favIconWidthDelta = data_.app ? | 849 int favIconWidthDelta = data_.app ? |
850 data_.favicon.width() - kFaviconSize : 0; | 850 data_.favicon.width() - kFaviconSize : 0; |
851 int favIconHeightDelta = data_.app ? | 851 int favIconHeightDelta = data_.app ? |
852 data_.favicon.height() - kFaviconSize : 0; | 852 data_.favicon.height() - kFaviconSize : 0; |
853 | 853 |
854 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch | 854 // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch |
855 // to using that class to render the favicon). | 855 // to using that class to render the favicon). |
856 canvas->DrawBitmapInt(data_.favicon, 0, 0, | 856 canvas->DrawBitmapInt(data_.favicon, 0, 0, |
857 data_.favicon.width(), | 857 data_.favicon.width(), |
858 data_.favicon.height(), | 858 data_.favicon.height(), |
859 favicon_bounds_.x() - favIconWidthDelta/2, | 859 favicon_bounds_.x() - favIconWidthDelta/2, |
860 favicon_bounds_.y() + favIconHeightOffset | 860 favicon_bounds_.y() + favIconHeightOffset |
861 - favIconHeightDelta/2 | 861 - favIconHeightDelta/2 |
862 + fav_icon_hiding_offset_, | 862 + favicon_hiding_offset_, |
863 kFaviconSize + favIconWidthDelta, | 863 kFaviconSize + favIconWidthDelta, |
864 kFaviconSize + favIconHeightDelta, | 864 kFaviconSize + favIconHeightDelta, |
865 true); | 865 true); |
866 } | 866 } |
867 } | 867 } |
868 } | 868 } |
869 canvas->Restore(); | 869 canvas->Restore(); |
870 } | 870 } |
871 } | 871 } |
872 | 872 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 if (initialized_) | 1076 if (initialized_) |
1077 return; | 1077 return; |
1078 | 1078 |
1079 LoadTabImages(); | 1079 LoadTabImages(); |
1080 | 1080 |
1081 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1081 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1082 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1082 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
1083 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); | 1083 title_font_ = new gfx::Font(base_font.GetFontName(), kFontPixelSize); |
1084 title_font_height_ = title_font_->GetHeight(); | 1084 title_font_height_ = title_font_->GetHeight(); |
1085 | 1085 |
1086 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1086 crashed_favicon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
1087 | 1087 |
1088 initialized_ = true; | 1088 initialized_ = true; |
1089 } | 1089 } |
OLD | NEW |