OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" | 5 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h" |
6 | 6 |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/command_updater.h" | 8 #include "chrome/browser/command_updater.h" |
9 #include "chrome/browser/sessions/tab_restore_service.h" | 9 #include "chrome/browser/sessions/tab_restore_service.h" |
10 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 10 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" |
11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 | 14 |
14 SystemMenuModelDelegate::SystemMenuModelDelegate( | 15 SystemMenuModelDelegate::SystemMenuModelDelegate( |
15 ui::AcceleratorProvider* provider, | 16 ui::AcceleratorProvider* provider, |
16 Browser* browser) | 17 Browser* browser) |
17 : provider_(provider), | 18 : provider_(provider), |
18 browser_(browser) { | 19 browser_(browser) { |
19 } | 20 } |
20 | 21 |
21 SystemMenuModelDelegate::~SystemMenuModelDelegate() { | 22 SystemMenuModelDelegate::~SystemMenuModelDelegate() { |
22 } | 23 } |
23 | 24 |
24 bool SystemMenuModelDelegate::IsCommandIdChecked(int command_id) const { | 25 bool SystemMenuModelDelegate::IsCommandIdChecked(int command_id) const { |
25 // TODO(beng): encoding menu. | 26 // TODO(beng): encoding menu. |
26 // No items in our system menu are check-able. | 27 // No items in our system menu are check-able. |
27 return false; | 28 return false; |
28 } | 29 } |
29 | 30 |
30 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const { | 31 bool SystemMenuModelDelegate::IsCommandIdEnabled(int command_id) const { |
31 return browser_->command_updater()->IsCommandEnabled(command_id); | 32 return chrome::IsCommandEnabled(browser_, command_id); |
32 } | 33 } |
33 | 34 |
34 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, | 35 bool SystemMenuModelDelegate::GetAcceleratorForCommandId(int command_id, |
35 ui::Accelerator* accelerator) { | 36 ui::Accelerator* accelerator) { |
36 return provider_->GetAcceleratorForCommandId(command_id, accelerator); | 37 return provider_->GetAcceleratorForCommandId(command_id, accelerator); |
37 } | 38 } |
38 | 39 |
39 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { | 40 bool SystemMenuModelDelegate::IsItemForCommandIdDynamic(int command_id) const { |
40 return command_id == IDC_RESTORE_TAB; | 41 return command_id == IDC_RESTORE_TAB; |
41 } | 42 } |
42 | 43 |
43 string16 SystemMenuModelDelegate::GetLabelForCommandId(int command_id) const { | 44 string16 SystemMenuModelDelegate::GetLabelForCommandId(int command_id) const { |
44 DCHECK_EQ(command_id, IDC_RESTORE_TAB); | 45 DCHECK_EQ(command_id, IDC_RESTORE_TAB); |
45 | 46 |
46 int string_id = IDS_RESTORE_TAB; | 47 int string_id = IDS_RESTORE_TAB; |
47 if (IsCommandIdEnabled(command_id)) { | 48 if (IsCommandIdEnabled(command_id)) { |
48 TabRestoreService* trs = | 49 TabRestoreService* trs = |
49 TabRestoreServiceFactory::GetForProfile(browser_->profile()); | 50 TabRestoreServiceFactory::GetForProfile(browser_->profile()); |
50 if (trs && trs->entries().front()->type == TabRestoreService::WINDOW) | 51 if (trs && trs->entries().front()->type == TabRestoreService::WINDOW) |
51 string_id = IDS_RESTORE_WINDOW; | 52 string_id = IDS_RESTORE_WINDOW; |
52 } | 53 } |
53 return l10n_util::GetStringUTF16(string_id); | 54 return l10n_util::GetStringUTF16(string_id); |
54 } | 55 } |
55 | 56 |
56 void SystemMenuModelDelegate::ExecuteCommand(int command_id) { | 57 void SystemMenuModelDelegate::ExecuteCommand(int command_id) { |
57 browser_->ExecuteCommandIfEnabled(command_id); | 58 chrome::ExecuteCommand(browser_, command_id); |
58 } | 59 } |
OLD | NEW |