diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-02 18:47:33 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-02 18:47:33 +0000 |
commit | 491c9820c4aa31b3e4c99f9136564925117f7598 (patch) | |
tree | 3b051d16804f510bdfd907c24e5b5d25cb789b4e /chrome/browser/gtk | |
parent | 074f7eee76d59f4c263b06e1f0bd6da8d17968af (diff) | |
download | chromium_src-491c9820c4aa31b3e4c99f9136564925117f7598.zip chromium_src-491c9820c4aa31b3e4c99f9136564925117f7598.tar.gz chromium_src-491c9820c4aa31b3e4c99f9136564925117f7598.tar.bz2 |
Add a context menu to the tab strip. It appears when you click in the
tab strip background.
Review URL: http://codereview.chromium.org/119020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 69 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 21 |
2 files changed, 89 insertions, 1 deletions
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 2d80179..bdb526d 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -467,6 +467,8 @@ void TabStripGtk::Init(int width, Profile* profile) { G_CALLBACK(OnExpose), this); g_signal_connect(G_OBJECT(tabstrip_.get()), "size-allocate", G_CALLBACK(OnSizeAllocate), this); + g_signal_connect(G_OBJECT(tabstrip_.get()), "button-press-event", + G_CALLBACK(OnButtonPress), this); newtab_button_.reset(MakeNewTabButton()); @@ -1089,6 +1091,15 @@ void TabStripGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation, } // static +gboolean TabStripGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event, + TabStripGtk* tabstrip) { + if (3 == event->button) + tabstrip->ShowContextMenu(); + + return TRUE; +} + +// static void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) { tabstrip->model_->delegate()->AddBlankTab(true); } @@ -1115,3 +1126,61 @@ CustomDrawButton* TabStripGtk::MakeNewTabButton() { return button; } + +void TabStripGtk::ShowContextMenu() { + if (!context_menu_.get()) { + context_menu_.reset(new MenuGtk(this, false)); + context_menu_->AppendMenuItemWithLabel( + TabStripModel::CommandNewTab, + l10n_util::GetStringUTF8(IDS_TAB_CXMENU_NEWTAB)); + context_menu_->AppendMenuItemWithLabel( + TabStripModel::CommandRestoreTab, + l10n_util::GetStringUTF8(IDS_RESTORE_TAB)); + + context_menu_->AppendSeparator(); + + context_menu_->AppendMenuItemWithLabel( + TabStripModel::CommandTaskManager, + l10n_util::GetStringUTF8(IDS_TASK_MANAGER)); + } + + context_menu_->PopupAsContext(gtk_get_current_event_time()); +} + +bool TabStripGtk::IsCommandEnabled(int command_id) const { + switch (command_id) { + case TabStripModel::CommandNewTab: + return true; + + case TabStripModel::CommandRestoreTab: + return model_->delegate()->CanRestoreTab(); + + case TabStripModel::CommandTaskManager: + // TODO(tc): This needs to be implemented in the TabStripModelDelegate. + return false; + + default: + NOTREACHED(); + } + return false; +} + +void TabStripGtk::ExecuteCommand(int command_id) { + switch (command_id) { + case TabStripModel::CommandNewTab: + model_->delegate()->AddBlankTab(true); + break; + + case TabStripModel::CommandRestoreTab: + model_->delegate()->RestoreTab(); + break; + + case TabStripModel::CommandTaskManager: + // TODO(tc): This needs to be implemented in the TabStripModelDelegate. + NOTIMPLEMENTED(); + break; + + default: + NOTREACHED(); + } +} diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index 0516c5a..cf0fff3 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/gfx/rect.h" +#include "chrome/browser/gtk/menu_gtk.h" #include "chrome/browser/gtk/tabs/tab_gtk.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/common/owned_widget_gtk.h" @@ -18,7 +19,8 @@ class CustomDrawButton; class DraggedTabControllerGtk; class TabStripGtk : public TabStripModelObserver, - public TabGtk::TabDelegate { + public TabGtk::TabDelegate, + public MenuGtk::Delegate { public: class TabAnimation; @@ -123,6 +125,10 @@ class TabStripGtk : public TabStripModelObserver, static void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation, TabStripGtk* tabstrip); + // Event handler for context menu popups. + static gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event, + TabStripGtk* tabstrip); + // Handles the clicked signal from the new tab button. static void OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip); @@ -179,6 +185,16 @@ class TabStripGtk : public TabStripModelObserver, // during animations, so we can't use current_unselected_width_. void LayoutNewTabButton(double last_tab_right, double unselected_width); + // -- Context Menu ----------------------------------------------------------- + + // On Windows, right clicking in the tab strip background brings up the + // system menu. There's no such thing on linux, so we just show the menu + // items we add to the menu. + void ShowContextMenu(); + // MenuGtk::Delegate implementation: + virtual bool IsCommandEnabled(int command_id) const; + virtual void ExecuteCommand(int command_id); + // -- Animations ------------------------------------------------------------- // A generic Layout method for various classes of TabStrip animations, @@ -247,6 +263,9 @@ class TabStripGtk : public TabStripModelObserver, // the drag session. scoped_ptr<DraggedTabControllerGtk> drag_controller_; + // The context menu. + scoped_ptr<MenuGtk> context_menu_; + DISALLOW_COPY_AND_ASSIGN(TabStripGtk); }; |