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/tabs/tab_menu_model.h" | 5 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 10 #include "chrome/browser/ui/tabs/tab_utils.h" |
10 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
11 | 12 |
12 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate, | 13 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate, |
13 TabStripModel* tab_strip, | 14 TabStripModel* tab_strip, |
14 int index) | 15 int index) |
15 : ui::SimpleMenuModel(delegate) { | 16 : ui::SimpleMenuModel(delegate) { |
16 Build(tab_strip, index); | 17 Build(tab_strip, index); |
17 } | 18 } |
18 | 19 |
19 void TabMenuModel::Build(TabStripModel* tab_strip, int index) { | 20 void TabMenuModel::Build(TabStripModel* tab_strip, int index) { |
20 bool affects_multiple_tabs = | 21 bool affects_multiple_tabs = |
21 (tab_strip->IsTabSelected(index) && | 22 (tab_strip->IsTabSelected(index) && |
22 tab_strip->selection_model().selected_indices().size() > 1); | 23 tab_strip->selection_model().selected_indices().size() > 1); |
23 AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB); | 24 AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB); |
24 AddSeparator(ui::NORMAL_SEPARATOR); | 25 AddSeparator(ui::NORMAL_SEPARATOR); |
25 AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD); | 26 AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD); |
26 AddItemWithStringId(TabStripModel::CommandDuplicate, | 27 AddItemWithStringId(TabStripModel::CommandDuplicate, |
27 IDS_TAB_CXMENU_DUPLICATE); | 28 IDS_TAB_CXMENU_DUPLICATE); |
28 bool will_pin = tab_strip->WillContextMenuPin(index); | 29 bool will_pin = tab_strip->WillContextMenuPin(index); |
29 if (affects_multiple_tabs) { | 30 if (affects_multiple_tabs) { |
30 AddItemWithStringId( | 31 AddItemWithStringId( |
31 TabStripModel::CommandTogglePinned, | 32 TabStripModel::CommandTogglePinned, |
32 will_pin ? IDS_TAB_CXMENU_PIN_TABS : IDS_TAB_CXMENU_UNPIN_TABS); | 33 will_pin ? IDS_TAB_CXMENU_PIN_TABS : IDS_TAB_CXMENU_UNPIN_TABS); |
33 } else { | 34 } else { |
34 AddItemWithStringId( | 35 AddItemWithStringId( |
35 TabStripModel::CommandTogglePinned, | 36 TabStripModel::CommandTogglePinned, |
36 will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB); | 37 will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB); |
37 } | 38 } |
| 39 if (chrome::IsTabAudioMutingFeatureEnabled()) { |
| 40 if (affects_multiple_tabs) { |
| 41 const bool will_mute = !chrome::AreAllTabsMuted( |
| 42 *tab_strip, tab_strip->selection_model().selected_indices()); |
| 43 AddItemWithStringId( |
| 44 TabStripModel::CommandToggleTabAudioMuted, |
| 45 will_mute ? IDS_TAB_CXMENU_AUDIO_MUTE_TABS : |
| 46 IDS_TAB_CXMENU_AUDIO_UNMUTE_TABS); |
| 47 } else { |
| 48 const bool will_mute = |
| 49 !chrome::IsTabAudioMuted(tab_strip->GetWebContentsAt(index)); |
| 50 AddItemWithStringId( |
| 51 TabStripModel::CommandToggleTabAudioMuted, |
| 52 will_mute ? IDS_TAB_CXMENU_AUDIO_MUTE_TAB : |
| 53 IDS_TAB_CXMENU_AUDIO_UNMUTE_TAB); |
| 54 } |
| 55 } |
38 AddSeparator(ui::NORMAL_SEPARATOR); | 56 AddSeparator(ui::NORMAL_SEPARATOR); |
39 if (affects_multiple_tabs) { | 57 if (affects_multiple_tabs) { |
40 AddItemWithStringId(TabStripModel::CommandCloseTab, | 58 AddItemWithStringId(TabStripModel::CommandCloseTab, |
41 IDS_TAB_CXMENU_CLOSETABS); | 59 IDS_TAB_CXMENU_CLOSETABS); |
42 } else { | 60 } else { |
43 AddItemWithStringId(TabStripModel::CommandCloseTab, | 61 AddItemWithStringId(TabStripModel::CommandCloseTab, |
44 IDS_TAB_CXMENU_CLOSETAB); | 62 IDS_TAB_CXMENU_CLOSETAB); |
45 } | 63 } |
46 AddItemWithStringId(TabStripModel::CommandCloseOtherTabs, | 64 AddItemWithStringId(TabStripModel::CommandCloseOtherTabs, |
47 IDS_TAB_CXMENU_CLOSEOTHERTABS); | 65 IDS_TAB_CXMENU_CLOSEOTHERTABS); |
48 AddItemWithStringId(TabStripModel::CommandCloseTabsToRight, | 66 AddItemWithStringId(TabStripModel::CommandCloseTabsToRight, |
49 IDS_TAB_CXMENU_CLOSETABSTORIGHT); | 67 IDS_TAB_CXMENU_CLOSETABSTORIGHT); |
50 AddSeparator(ui::NORMAL_SEPARATOR); | 68 AddSeparator(ui::NORMAL_SEPARATOR); |
51 const bool is_window = tab_strip->delegate()->GetRestoreTabType() == | 69 const bool is_window = tab_strip->delegate()->GetRestoreTabType() == |
52 TabStripModelDelegate::RESTORE_WINDOW; | 70 TabStripModelDelegate::RESTORE_WINDOW; |
53 AddItemWithStringId(TabStripModel::CommandRestoreTab, | 71 AddItemWithStringId(TabStripModel::CommandRestoreTab, |
54 is_window ? IDS_RESTORE_WINDOW : IDS_RESTORE_TAB); | 72 is_window ? IDS_RESTORE_WINDOW : IDS_RESTORE_TAB); |
55 AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs, | 73 AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs, |
56 IDS_TAB_CXMENU_BOOKMARK_ALL_TABS); | 74 IDS_TAB_CXMENU_BOOKMARK_ALL_TABS); |
57 } | 75 } |
OLD | NEW |