OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_strip_gtk.h" | 5 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
10 #include "app/slide_animation.h" | 10 #include "app/slide_animation.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 tabstrip_.Own(gtk_fixed_new()); | 461 tabstrip_.Own(gtk_fixed_new()); |
462 gtk_fixed_set_has_window(GTK_FIXED(tabstrip_.get()), TRUE); | 462 gtk_fixed_set_has_window(GTK_FIXED(tabstrip_.get()), TRUE); |
463 gtk_widget_set_size_request(tabstrip_.get(), width, | 463 gtk_widget_set_size_request(tabstrip_.get(), width, |
464 TabGtk::GetMinimumUnselectedSize().height()); | 464 TabGtk::GetMinimumUnselectedSize().height()); |
465 gtk_widget_set_app_paintable(tabstrip_.get(), TRUE); | 465 gtk_widget_set_app_paintable(tabstrip_.get(), TRUE); |
466 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", | 466 g_signal_connect(G_OBJECT(tabstrip_.get()), "expose-event", |
467 G_CALLBACK(OnExpose), this); | 467 G_CALLBACK(OnExpose), this); |
468 g_signal_connect(G_OBJECT(tabstrip_.get()), "size-allocate", | 468 g_signal_connect(G_OBJECT(tabstrip_.get()), "size-allocate", |
469 G_CALLBACK(OnSizeAllocate), this); | 469 G_CALLBACK(OnSizeAllocate), this); |
| 470 g_signal_connect(G_OBJECT(tabstrip_.get()), "button-press-event", |
| 471 G_CALLBACK(OnButtonPress), this); |
470 | 472 |
471 newtab_button_.reset(MakeNewTabButton()); | 473 newtab_button_.reset(MakeNewTabButton()); |
472 | 474 |
473 gtk_widget_show_all(tabstrip_.get()); | 475 gtk_widget_show_all(tabstrip_.get()); |
474 | 476 |
475 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); | 477 bounds_ = GetInitialWidgetBounds(tabstrip_.get()); |
476 } | 478 } |
477 | 479 |
478 void TabStripGtk::AddTabStripToBox(GtkWidget* box) { | 480 void TabStripGtk::AddTabStripToBox(GtkWidget* box) { |
479 gtk_box_pack_start(GTK_BOX(box), tabstrip_.get(), FALSE, FALSE, 0); | 481 gtk_box_pack_start(GTK_BOX(box), tabstrip_.get(), FALSE, FALSE, 0); |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 // TODO(jhawkins): Windows resizes the layout tabs continuously during | 1084 // TODO(jhawkins): Windows resizes the layout tabs continuously during |
1083 // a resize. I need to investigate which signal to watch in order to | 1085 // a resize. I need to investigate which signal to watch in order to |
1084 // reproduce this behavior. | 1086 // reproduce this behavior. |
1085 if (tabstrip->GetTabCount() == 1) | 1087 if (tabstrip->GetTabCount() == 1) |
1086 tabstrip->Layout(); | 1088 tabstrip->Layout(); |
1087 else | 1089 else |
1088 tabstrip->ResizeLayoutTabs(); | 1090 tabstrip->ResizeLayoutTabs(); |
1089 } | 1091 } |
1090 | 1092 |
1091 // static | 1093 // static |
| 1094 gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event, |
| 1095 TabStripGtk* tabstrip) { |
| 1096 if (3 == event->button) |
| 1097 tabstrip->ShowContextMenu(); |
| 1098 |
| 1099 return TRUE; |
| 1100 } |
| 1101 |
| 1102 // static |
1092 void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) { | 1103 void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) { |
1093 tabstrip->model_->delegate()->AddBlankTab(true); | 1104 tabstrip->model_->delegate()->AddBlankTab(true); |
1094 } | 1105 } |
1095 | 1106 |
1096 void TabStripGtk::PaintBackground(GdkEventExpose* event) { | 1107 void TabStripGtk::PaintBackground(GdkEventExpose* event) { |
1097 gfx::CanvasPaint canvas(event); | 1108 gfx::CanvasPaint canvas(event); |
1098 canvas.TileImageInt(*background_, 0, 0, bounds_.width(), bounds_.height()); | 1109 canvas.TileImageInt(*background_, 0, 0, bounds_.width(), bounds_.height()); |
1099 } | 1110 } |
1100 | 1111 |
1101 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { | 1112 void TabStripGtk::SetTabBounds(TabGtk* tab, const gfx::Rect& bounds) { |
1102 tab->SetBounds(bounds); | 1113 tab->SetBounds(bounds); |
1103 gtk_fixed_move(GTK_FIXED(tabstrip_.get()), tab->widget(), | 1114 gtk_fixed_move(GTK_FIXED(tabstrip_.get()), tab->widget(), |
1104 bounds.x(), bounds.y()); | 1115 bounds.x(), bounds.y()); |
1105 } | 1116 } |
1106 | 1117 |
1107 CustomDrawButton* TabStripGtk::MakeNewTabButton() { | 1118 CustomDrawButton* TabStripGtk::MakeNewTabButton() { |
1108 CustomDrawButton* button = new CustomDrawButton(IDR_NEWTAB_BUTTON, | 1119 CustomDrawButton* button = new CustomDrawButton(IDR_NEWTAB_BUTTON, |
1109 IDR_NEWTAB_BUTTON_P, IDR_NEWTAB_BUTTON_H, 0); | 1120 IDR_NEWTAB_BUTTON_P, IDR_NEWTAB_BUTTON_H, 0); |
1110 | 1121 |
1111 g_signal_connect(G_OBJECT(button->widget()), "clicked", | 1122 g_signal_connect(G_OBJECT(button->widget()), "clicked", |
1112 G_CALLBACK(OnNewTabClicked), this); | 1123 G_CALLBACK(OnNewTabClicked), this); |
1113 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 1124 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
1114 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); | 1125 gtk_fixed_put(GTK_FIXED(tabstrip_.get()), button->widget(), 0, 0); |
1115 | 1126 |
1116 return button; | 1127 return button; |
1117 } | 1128 } |
| 1129 |
| 1130 void TabStripGtk::ShowContextMenu() { |
| 1131 if (!context_menu_.get()) { |
| 1132 context_menu_.reset(new MenuGtk(this, false)); |
| 1133 context_menu_->AppendMenuItemWithLabel( |
| 1134 TabStripModel::CommandNewTab, |
| 1135 l10n_util::GetStringUTF8(IDS_TAB_CXMENU_NEWTAB)); |
| 1136 context_menu_->AppendMenuItemWithLabel( |
| 1137 TabStripModel::CommandRestoreTab, |
| 1138 l10n_util::GetStringUTF8(IDS_RESTORE_TAB)); |
| 1139 |
| 1140 context_menu_->AppendSeparator(); |
| 1141 |
| 1142 context_menu_->AppendMenuItemWithLabel( |
| 1143 TabStripModel::CommandTaskManager, |
| 1144 l10n_util::GetStringUTF8(IDS_TASK_MANAGER)); |
| 1145 } |
| 1146 |
| 1147 context_menu_->PopupAsContext(gtk_get_current_event_time()); |
| 1148 } |
| 1149 |
| 1150 bool TabStripGtk::IsCommandEnabled(int command_id) const { |
| 1151 switch (command_id) { |
| 1152 case TabStripModel::CommandNewTab: |
| 1153 return true; |
| 1154 |
| 1155 case TabStripModel::CommandRestoreTab: |
| 1156 return model_->delegate()->CanRestoreTab(); |
| 1157 |
| 1158 case TabStripModel::CommandTaskManager: |
| 1159 // TODO(tc): This needs to be implemented in the TabStripModelDelegate. |
| 1160 return false; |
| 1161 |
| 1162 default: |
| 1163 NOTREACHED(); |
| 1164 } |
| 1165 return false; |
| 1166 } |
| 1167 |
| 1168 void TabStripGtk::ExecuteCommand(int command_id) { |
| 1169 switch (command_id) { |
| 1170 case TabStripModel::CommandNewTab: |
| 1171 model_->delegate()->AddBlankTab(true); |
| 1172 break; |
| 1173 |
| 1174 case TabStripModel::CommandRestoreTab: |
| 1175 model_->delegate()->RestoreTab(); |
| 1176 break; |
| 1177 |
| 1178 case TabStripModel::CommandTaskManager: |
| 1179 // TODO(tc): This needs to be implemented in the TabStripModelDelegate. |
| 1180 NOTIMPLEMENTED(); |
| 1181 break; |
| 1182 |
| 1183 default: |
| 1184 NOTREACHED(); |
| 1185 } |
| 1186 } |
OLD | NEW |