OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/tabs/tab_renderer_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 should_display_crashed_favicon_(false), | 245 should_display_crashed_favicon_(false), |
246 loading_animation_(theme_provider), | 246 loading_animation_(theme_provider), |
247 background_offset_x_(0), | 247 background_offset_x_(0), |
248 background_offset_y_(kInactiveTabBackgroundOffsetY), | 248 background_offset_y_(kInactiveTabBackgroundOffsetY), |
249 close_button_color_(0) { | 249 close_button_color_(0) { |
250 InitResources(); | 250 InitResources(); |
251 | 251 |
252 tab_.Own(gtk_fixed_new()); | 252 tab_.Own(gtk_fixed_new()); |
253 gtk_widget_set_app_paintable(tab_.get(), TRUE); | 253 gtk_widget_set_app_paintable(tab_.get(), TRUE); |
254 g_signal_connect(tab_.get(), "expose-event", | 254 g_signal_connect(tab_.get(), "expose-event", |
255 G_CALLBACK(OnExposeEvent), this); | 255 G_CALLBACK(OnExposeEventThunk), this); |
256 g_signal_connect(tab_.get(), "size-allocate", | 256 g_signal_connect(tab_.get(), "size-allocate", |
257 G_CALLBACK(OnSizeAllocate), this); | 257 G_CALLBACK(OnSizeAllocateThunk), this); |
258 close_button_.reset(MakeCloseButton()); | 258 close_button_.reset(MakeCloseButton()); |
259 gtk_widget_show(tab_.get()); | 259 gtk_widget_show(tab_.get()); |
260 | 260 |
261 hover_animation_.reset(new SlideAnimation(this)); | 261 hover_animation_.reset(new SlideAnimation(this)); |
262 hover_animation_->SetSlideDuration(kHoverDurationMs); | 262 hover_animation_->SetSlideDuration(kHoverDurationMs); |
263 | 263 |
264 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 264 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
265 NotificationService::AllSources()); | 265 NotificationService::AllSources()); |
266 } | 266 } |
267 | 267 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 } | 965 } |
966 | 966 |
967 CustomDrawButton* TabRendererGtk::MakeCloseButton() { | 967 CustomDrawButton* TabRendererGtk::MakeCloseButton() { |
968 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, | 968 CustomDrawButton* button = new CustomDrawButton(IDR_TAB_CLOSE, |
969 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); | 969 IDR_TAB_CLOSE_P, IDR_TAB_CLOSE_H, IDR_TAB_CLOSE); |
970 | 970 |
971 gtk_widget_set_tooltip_text(button->widget(), | 971 gtk_widget_set_tooltip_text(button->widget(), |
972 l10n_util::GetStringUTF8(IDS_TOOLTIP_CLOSE_TAB).c_str()); | 972 l10n_util::GetStringUTF8(IDS_TOOLTIP_CLOSE_TAB).c_str()); |
973 | 973 |
974 g_signal_connect(button->widget(), "clicked", | 974 g_signal_connect(button->widget(), "clicked", |
975 G_CALLBACK(OnCloseButtonClicked), this); | 975 G_CALLBACK(OnCloseButtonClickedThunk), this); |
976 g_signal_connect(button->widget(), "button-release-event", | 976 g_signal_connect(button->widget(), "button-release-event", |
977 G_CALLBACK(OnCloseButtonMouseRelease), this); | 977 G_CALLBACK(OnCloseButtonMouseReleaseThunk), this); |
978 g_signal_connect(button->widget(), "enter-notify-event", | 978 g_signal_connect(button->widget(), "enter-notify-event", |
979 G_CALLBACK(OnEnterNotifyEvent), this); | 979 G_CALLBACK(OnEnterNotifyEventThunk), this); |
980 g_signal_connect(button->widget(), "leave-notify-event", | 980 g_signal_connect(button->widget(), "leave-notify-event", |
981 G_CALLBACK(OnLeaveNotifyEvent), this); | 981 G_CALLBACK(OnLeaveNotifyEventThunk), this); |
982 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 982 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
983 gtk_fixed_put(GTK_FIXED(tab_.get()), button->widget(), 0, 0); | 983 gtk_fixed_put(GTK_FIXED(tab_.get()), button->widget(), 0, 0); |
984 | 984 |
985 return button; | 985 return button; |
986 } | 986 } |
987 | 987 |
988 double TabRendererGtk::GetThrobValue() { | 988 double TabRendererGtk::GetThrobValue() { |
989 if (mini_title_animation_.get() && mini_title_animation_->is_animating()) { | 989 if (mini_title_animation_.get() && mini_title_animation_->is_animating()) { |
990 return mini_title_animation_->GetCurrentValue() * | 990 return mini_title_animation_->GetCurrentValue() * |
991 kMiniTitleChangeThrobOpacity; | 991 kMiniTitleChangeThrobOpacity; |
992 } | 992 } |
993 return hover_animation_.get() ? | 993 return hover_animation_.get() ? |
994 kHoverOpacity * hover_animation_->GetCurrentValue() : 0; | 994 kHoverOpacity * hover_animation_->GetCurrentValue() : 0; |
995 } | 995 } |
996 | 996 |
997 void TabRendererGtk::CloseButtonClicked() { | 997 void TabRendererGtk::CloseButtonClicked() { |
998 // Nothing to do. | 998 // Nothing to do. |
999 } | 999 } |
1000 | 1000 |
1001 // static | 1001 void TabRendererGtk::OnCloseButtonClicked(GtkWidget* widget) { |
1002 void TabRendererGtk::OnCloseButtonClicked(GtkWidget* widget, | 1002 CloseButtonClicked(); |
1003 TabRendererGtk* tab) { | |
1004 tab->CloseButtonClicked(); | |
1005 } | 1003 } |
1006 | 1004 |
1007 // static | |
1008 gboolean TabRendererGtk::OnCloseButtonMouseRelease(GtkWidget* widget, | 1005 gboolean TabRendererGtk::OnCloseButtonMouseRelease(GtkWidget* widget, |
1009 GdkEventButton* event, | 1006 GdkEventButton* event) { |
1010 TabRendererGtk* tab) { | |
1011 if (event->button == 2) { | 1007 if (event->button == 2) { |
1012 tab->CloseButtonClicked(); | 1008 CloseButtonClicked(); |
1013 return TRUE; | 1009 return TRUE; |
1014 } | 1010 } |
1015 | 1011 |
1016 return FALSE; | 1012 return FALSE; |
1017 } | 1013 } |
1018 | 1014 |
1019 // static | 1015 gboolean TabRendererGtk::OnExposeEvent(GtkWidget* widget, |
1020 gboolean TabRendererGtk::OnExposeEvent(GtkWidget* widget, GdkEventExpose* event, | 1016 GdkEventExpose* event) { |
1021 TabRendererGtk* tab) { | 1017 PaintTab(event); |
1022 tab->PaintTab(event); | 1018 gtk_container_propagate_expose(GTK_CONTAINER(tab_.get()), |
1023 gtk_container_propagate_expose(GTK_CONTAINER(tab->tab_.get()), | 1019 close_button_->widget(), event); |
1024 tab->close_button_->widget(), event); | |
1025 return TRUE; | 1020 return TRUE; |
1026 } | 1021 } |
1027 | 1022 |
1028 // static | |
1029 void TabRendererGtk::OnSizeAllocate(GtkWidget* widget, | 1023 void TabRendererGtk::OnSizeAllocate(GtkWidget* widget, |
1030 GtkAllocation* allocation, | 1024 GtkAllocation* allocation) { |
1031 TabRendererGtk* tab) { | |
1032 gfx::Rect bounds = gfx::Rect(allocation->x, allocation->y, | 1025 gfx::Rect bounds = gfx::Rect(allocation->x, allocation->y, |
1033 allocation->width, allocation->height); | 1026 allocation->width, allocation->height); |
1034 | 1027 |
1035 // Nothing to do if the bounds are the same. If we don't catch this, we'll | 1028 // Nothing to do if the bounds are the same. If we don't catch this, we'll |
1036 // get an infinite loop of size-allocate signals. | 1029 // get an infinite loop of size-allocate signals. |
1037 if (tab->bounds_ == bounds) | 1030 if (bounds_ == bounds) |
1038 return; | 1031 return; |
1039 | 1032 |
1040 tab->bounds_ = bounds; | 1033 bounds_ = bounds; |
1041 tab->Layout(); | 1034 Layout(); |
1042 } | 1035 } |
1043 | 1036 |
1044 // static | |
1045 gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, | 1037 gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, |
1046 GdkEventCrossing* event, | 1038 GdkEventCrossing* event) { |
1047 TabRendererGtk* tab) { | 1039 hover_animation_->SetTweenType(Tween::EASE_OUT); |
1048 tab->hover_animation_->SetTweenType(Tween::EASE_OUT); | 1040 hover_animation_->Show(); |
1049 tab->hover_animation_->Show(); | |
1050 return FALSE; | 1041 return FALSE; |
1051 } | 1042 } |
1052 | 1043 |
1053 // static | |
1054 gboolean TabRendererGtk::OnLeaveNotifyEvent(GtkWidget* widget, | 1044 gboolean TabRendererGtk::OnLeaveNotifyEvent(GtkWidget* widget, |
1055 GdkEventCrossing* event, | 1045 GdkEventCrossing* event) { |
1056 TabRendererGtk* tab) { | 1046 hover_animation_->SetTweenType(Tween::EASE_IN); |
1057 tab->hover_animation_->SetTweenType(Tween::EASE_IN); | 1047 hover_animation_->Hide(); |
1058 tab->hover_animation_->Hide(); | |
1059 return FALSE; | 1048 return FALSE; |
1060 } | 1049 } |
1061 | 1050 |
1062 // static | 1051 // static |
1063 void TabRendererGtk::InitResources() { | 1052 void TabRendererGtk::InitResources() { |
1064 if (initialized_) | 1053 if (initialized_) |
1065 return; | 1054 return; |
1066 | 1055 |
1067 LoadTabImages(); | 1056 LoadTabImages(); |
1068 | 1057 |
1069 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1058 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1070 // Force the font size to 9pt, which matches Windows' default font size | 1059 // Force the font size to 9pt, which matches Windows' default font size |
1071 // (taken from the system). | 1060 // (taken from the system). |
1072 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 1061 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
1073 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 9)); | 1062 title_font_ = new gfx::Font(gfx::Font::CreateFont(base_font.FontName(), 9)); |
1074 title_font_height_ = title_font_->height(); | 1063 title_font_height_ = title_font_->height(); |
1075 | 1064 |
1076 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); | 1065 crashed_fav_icon = rb.GetBitmapNamed(IDR_SAD_FAVICON); |
1077 | 1066 |
1078 initialized_ = true; | 1067 initialized_ = true; |
1079 } | 1068 } |
OLD | NEW |