Chromium Code Reviews| Index: chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.cc |
| diff --git a/chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.cc b/chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..440388f0128e20ee3af0cbc7a081c092c30b0478 |
| --- /dev/null |
| +++ b/chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" |
| + |
| +#include "chrome/browser/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/gtk/accelerators_gtk.h" |
| +#include "chrome/browser/ui/gtk/menu_gtk.h" |
| +#include "chrome/browser/ui/gtk/tabs/tab_gtk.h" |
| + |
| +TabStripMenuController::TabStripMenuController(TabGtk* tab, |
| + TabStripModel* model, |
| + int index) |
| + : tab_(tab), |
| + model_(this, model, index) { |
| + menu_.reset(new MenuGtk(this, &model_)); |
| +} |
| + |
| +void TabStripMenuController::RunMenu(const gfx::Point& point, |
| + guint32 event_time) { |
| + menu_->PopupAsContext(point, event_time); |
| +} |
| + |
| +void TabStripMenuController::Cancel() { |
| + tab_ = NULL; |
| + menu_->Cancel(); |
| +} |
| + |
| +bool TabStripMenuController::IsCommandIdChecked(int command_id) const { |
| + return false; |
| +} |
| + |
| +bool TabStripMenuController::IsCommandIdEnabled(int command_id) const { |
| + return tab_ && tab_->delegate()->IsCommandEnabledForTab( |
| + static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| + tab_); |
| +} |
| + |
| +bool TabStripMenuController::GetAcceleratorForCommandId( |
| + int command_id, |
| + ui::Accelerator* accelerator) { |
| + int browser_command; |
| + if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| + &browser_command)) |
| + return false; |
|
James Hawkins
2011/06/23 18:08:26
nit: This would be more readable if you add a blan
|
| + const ui::AcceleratorGtk* accelerator_gtk = |
| + AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( |
| + browser_command); |
| + if (accelerator_gtk) |
| + *accelerator = *accelerator_gtk; |
| + return !!accelerator_gtk; |
| +} |
| + |
| +void TabStripMenuController::ExecuteCommand(int command_id) { |
| + // Checking if the tab still exists since it is possible that the tab |
| + // corresponding to this context menu has been closed. |
| + if (!tab_) |
| + return; |
| + tab_->delegate()->ExecuteCommandForTab( |
| + static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_); |
| +} |
| + |
| +GtkWidget* TabStripMenuController::GetImageForCommandId(int command_id) const { |
| + int browser_cmd_id; |
| + if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| + &browser_cmd_id)) |
| + return NULL; |
| + return MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id); |
| +} |