Chromium Code Reviews| Index: chrome/browser/ui/gtk/tabs/tab_gtk.cc |
| diff --git a/chrome/browser/ui/gtk/tabs/tab_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_gtk.cc |
| index d5cdd31a593c45546320cedbed407218c3d7c2ef..d6c5b16b4d4fc715c280c708157d99b4d846e247 100644 |
| --- a/chrome/browser/ui/gtk/tabs/tab_gtk.cc |
| +++ b/chrome/browser/ui/gtk/tabs/tab_gtk.cc |
| @@ -11,6 +11,7 @@ |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
| #include "chrome/browser/ui/gtk/menu_gtk.h" |
| +#include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" |
| #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| #include "grit/generated_resources.h" |
| #include "grit/theme_resources.h" |
| @@ -31,79 +32,6 @@ int GetTitleWidth(gfx::Font* font, string16 title) { |
| } // namespace |
| -class TabGtk::ContextMenuController : public ui::SimpleMenuModel::Delegate, |
| - public MenuGtk::Delegate { |
| - public: |
| - explicit ContextMenuController(TabGtk* tab) |
| - : tab_(tab), |
| - model_(this, tab->delegate()->IsTabPinned(tab)) { |
| - menu_.reset(new MenuGtk(this, &model_)); |
| - } |
| - |
| - virtual ~ContextMenuController() {} |
| - |
| - void RunMenu(const gfx::Point& point, guint32 event_time) { |
| - menu_->PopupAsContext(point, event_time); |
| - } |
| - |
| - void Cancel() { |
| - tab_ = NULL; |
| - menu_->Cancel(); |
| - } |
| - |
| - private: |
| - // Overridden from ui::SimpleMenuModel::Delegate: |
| - virtual bool IsCommandIdChecked(int command_id) const { |
| - return false; |
| - } |
| - virtual bool IsCommandIdEnabled(int command_id) const { |
| - return tab_ && tab_->delegate()->IsCommandEnabledForTab( |
| - static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| - tab_); |
| - } |
| - virtual bool GetAcceleratorForCommandId( |
| - int command_id, |
| - ui::Accelerator* accelerator) { |
| - int browser_command; |
| - if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| - &browser_command)) |
| - return false; |
| - const ui::AcceleratorGtk* accelerator_gtk = |
| - AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( |
| - browser_command); |
| - if (accelerator_gtk) |
| - *accelerator = *accelerator_gtk; |
| - return !!accelerator_gtk; |
| - } |
| - |
| - virtual void ExecuteCommand(int command_id) { |
| - if (!tab_) |
| - return; |
| - tab_->delegate()->ExecuteCommandForTab( |
| - static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_); |
| - } |
| - |
| - GtkWidget* GetImageForCommandId(int command_id) const { |
| - int browser_cmd_id; |
| - return TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| - &browser_cmd_id) ? |
| - MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id) : |
| - NULL; |
| - } |
| - |
| - // The context menu. |
| - scoped_ptr<MenuGtk> menu_; |
| - |
| - // The Tab the context menu was brought up for. Set to NULL when the menu |
| - // is canceled. |
| - TabGtk* tab_; |
| - |
| - // The model. |
| - TabMenuModel model_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ContextMenuController); |
| -}; |
| - |
| class TabGtk::TabGtkObserverHelper { |
| public: |
| explicit TabGtkObserverHelper(TabGtk* tab) |
| @@ -176,11 +104,16 @@ gboolean TabGtk::OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { |
| // Store whether or not we were selected just now... we only want to be |
| // able to drag foreground tabs, so we don't start dragging the tab if |
| // it was in the background. |
| - bool just_selected = !IsSelected(); |
| - if (just_selected) { |
| - delegate_->SelectTab(this); |
| + if (!IsActive() && (event->state & |
|
James Hawkins
2011/05/12 00:53:54
&& !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_
dpapad
2011/05/12 16:37:08
Done.
|
| + (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) == 0) { |
| + delegate_->ActivateTab(this); |
| + } else if (!IsActive() && (event->state & GDK_CONTROL_MASK) == |
|
James Hawkins
2011/05/12 00:53:54
It's merely enough to check `event->state & GDK_CO
dpapad
2011/05/12 16:37:08
Done.
|
| + GDK_CONTROL_MASK) { |
| + delegate_->ToggleTabSelection(this); |
| + } else if (!IsActive() && (event->state & GDK_SHIFT_MASK) == |
| + GDK_SHIFT_MASK) { |
| + delegate_->ExtendTabSelection(this); |
| } |
| - |
| // Hook into the message loop to handle dragging. |
| observer_.reset(new TabGtkObserverHelper(this)); |
| @@ -190,7 +123,7 @@ gboolean TabGtk::OnButtonPressEvent(GtkWidget* widget, GdkEventButton* event) { |
| // Only show the context menu if the left mouse button isn't down (i.e., |
| // the user might want to drag instead). |
| if (!last_mouse_down_) { |
| - menu_controller_.reset(new ContextMenuController(this)); |
| + menu_controller_.reset(delegate()->GetContextMenuControllerForTab(this)); |
| menu_controller_->RunMenu(gfx::Point(event->x_root, event->y_root), |
| event->time); |
| } |
| @@ -293,6 +226,10 @@ void TabGtk::DidProcessEvent(GdkEvent* event) { |
| /////////////////////////////////////////////////////////////////////////////// |
| // TabGtk, TabRendererGtk overrides: |
| +bool TabGtk::IsActive() const { |
| + return delegate_->IsTabActive(this); |
| +} |
| + |
| bool TabGtk::IsSelected() const { |
| return delegate_->IsTabSelected(this); |
| } |