OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 #include "chrome/browser/ui/gtk/tabs/tab_strip_menu_controller.h" |
| 6 |
| 7 #include "chrome/browser/tabs/tab_strip_model.h" |
| 8 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
| 9 #include "chrome/browser/ui/gtk/menu_gtk.h" |
| 10 #include "chrome/browser/ui/gtk/tabs/tab_gtk.h" |
| 11 |
| 12 TabStripMenuController::TabStripMenuController(TabGtk* tab, |
| 13 TabStripModel* model, |
| 14 int index) |
| 15 : tab_(tab), |
| 16 model_(this, model, index) { |
| 17 menu_.reset(new MenuGtk(this, &model_)); |
| 18 } |
| 19 |
| 20 TabStripMenuController::~TabStripMenuController() {} |
| 21 |
| 22 void TabStripMenuController::RunMenu(const gfx::Point& point, |
| 23 guint32 event_time) { |
| 24 menu_->PopupAsContext(point, event_time); |
| 25 } |
| 26 |
| 27 void TabStripMenuController::Cancel() { |
| 28 tab_ = NULL; |
| 29 menu_->Cancel(); |
| 30 } |
| 31 |
| 32 bool TabStripMenuController::IsCommandIdChecked(int command_id) const { |
| 33 return false; |
| 34 } |
| 35 |
| 36 bool TabStripMenuController::IsCommandIdEnabled(int command_id) const { |
| 37 return tab_ && tab_->delegate()->IsCommandEnabledForTab( |
| 38 static_cast<TabStripModel::ContextMenuCommand>(command_id), |
| 39 tab_); |
| 40 } |
| 41 |
| 42 bool TabStripMenuController::GetAcceleratorForCommandId( |
| 43 int command_id, |
| 44 ui::Accelerator* accelerator) { |
| 45 int browser_command; |
| 46 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| 47 &browser_command)) |
| 48 return false; |
| 49 const ui::AcceleratorGtk* accelerator_gtk = |
| 50 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( |
| 51 browser_command); |
| 52 if (accelerator_gtk) |
| 53 *accelerator = *accelerator_gtk; |
| 54 return !!accelerator_gtk; |
| 55 } |
| 56 |
| 57 void TabStripMenuController::ExecuteCommand(int command_id) { |
| 58 // Checking if the tab still exists since it is possible that the tab |
| 59 // corresponding to this context menu has been closed. |
| 60 if (!tab_) |
| 61 return; |
| 62 tab_->delegate()->ExecuteCommandForTab( |
| 63 static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_); |
| 64 } |
| 65 |
| 66 GtkWidget* TabStripMenuController::GetImageForCommandId(int command_id) const { |
| 67 int browser_cmd_id; |
| 68 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, |
| 69 &browser_cmd_id)) |
| 70 return NULL; |
| 71 return MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id); |
| 72 } |
OLD | NEW |