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; | |
James Hawkins
2011/06/23 18:08:26
nit: This would be more readable if you add a blan
| |
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 still exists since it is possible that the tab | |
57 // corresponding to this context menu has been closed. | |
58 if (!tab_) | |
59 return; | |
60 tab_->delegate()->ExecuteCommandForTab( | |
61 static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_); | |
62 } | |
63 | |
64 GtkWidget* TabStripMenuController::GetImageForCommandId(int command_id) const { | |
65 int browser_cmd_id; | |
66 if (!TabStripModel::ContextMenuCommandToBrowserCommand(command_id, | |
67 &browser_cmd_id)) | |
68 return NULL; | |
69 return MenuGtk::Delegate::GetDefaultImageForCommandId(browser_cmd_id); | |
70 } | |
OLD | NEW |