Chromium Code Reviews| 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 void TabStripMenuController::RunMenu(const gfx::Point& point, | |
| 21 guint32 event_time) { | |
| 22 menu_->PopupAsContext(point, event_time); | |
| 23 } | |
| 24 | |
| 25 void TabStripMenuController::Cancel() { | |
| 26 tab_ = NULL; | |
| 27 menu_->Cancel(); | |
| 28 } | |
| 29 | |
| 30 bool TabStripMenuController::IsCommandIdChecked(int command_id) const { | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 bool TabStripMenuController::IsCommandIdEnabled(int command_id) const { | |
| 35 return tab_ && tab_->delegate()->IsCommandEnabledForTab( | |
| 36 static_cast<TabStripModel::ContextMenuCommand>(command_id), | |
| 37 tab_); | |
| 38 } | |
| 39 | |
| 40 bool TabStripMenuController::GetAcceleratorForCommandId( | |
| 41 int command_id, | |
| 42 ui::Accelerator* accelerator) { | |
| 43 int browser_command; | |
| 44 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, | |
| 45 &browser_command)) | |
| 46 return false; | |
| 47 const ui::AcceleratorGtk* accelerator_gtk = | |
| 48 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand( | |
| 49 browser_command); | |
| 50 if (accelerator_gtk) | |
| 51 *accelerator = *accelerator_gtk; | |
| 52 return !!accelerator_gtk; | |
| 53 } | |
| 54 | |
| 55 void TabStripMenuController::ExecuteCommand(int command_id) { | |
| 56 // Checking if the tab corresponding to this menu has been closed. Normally | |
| 57 // this can not happen, but it might be possible if the tab is closed | |
| 58 // through javascript. | |
|
dpapad
2011/05/12 21:53:19
Done.
James Hawkins
2011/05/12 21:59:52
nit: Tabs can be closed various ways that don't re
dpapad
2011/05/12 22:31:38
Done.
| |
| 59 if (!tab_) | |
| 60 return; | |
| 61 tab_->delegate()->ExecuteCommandForTab( | |
| 62 static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_); | |
| 63 } | |
| 64 | |
| 65 GtkWidget* TabStripMenuController::GetImageForCommandId(int command_id) const { | |
| 66 int browser_cmd_id; | |
| 67 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, | |
| 68 &browser_cmd_id)) | |
| 69 return NULL; | |
| 70 return MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id); | |
| 71 } | |
| OLD | NEW |