1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h"
7 #include "chrome/browser/ui/gtk/accelerators_gtk.h"
8 #include "chrome/browser/ui/gtk/menu_gtk.h"
9 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 TabStripMenuController::TabStripMenuController(TabGtk
* tab
,
16 model_(this, model
, index
) {
17 menu_
.reset(new MenuGtk(this, &model_
));
20 TabStripMenuController::~TabStripMenuController() {}
22 void TabStripMenuController::RunMenu(const gfx::Point
& point
,
24 menu_
->PopupAsContext(point
, event_time
);
27 void TabStripMenuController::Cancel() {
32 bool TabStripMenuController::IsCommandIdChecked(int command_id
) const {
36 bool TabStripMenuController::IsCommandIdEnabled(int command_id
) const {
37 return tab_
&& tab_
->delegate()->IsCommandEnabledForTab(
38 static_cast<TabStripModel::ContextMenuCommand
>(command_id
),
42 bool TabStripMenuController::GetAcceleratorForCommandId(
44 ui::Accelerator
* out_accelerator
) {
46 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id
,
49 const ui::Accelerator
* accelerator
=
50 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(
54 *out_accelerator
= *accelerator
;
58 void TabStripMenuController::ExecuteCommand(int command_id
, int event_flags
) {
59 // Checking if the tab still exists since it is possible that the tab
60 // corresponding to this context menu has been closed.
63 tab_
->delegate()->ExecuteCommandForTab(
64 static_cast<TabStripModel::ContextMenuCommand
>(command_id
), tab_
);
67 GtkWidget
* TabStripMenuController::GetImageForCommandId(int command_id
) const {
69 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id
,
72 return MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id
);