• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/tabs/tab_menu_model.h"
6 
7 #include "base/command_line.h"
8 #include "chrome/browser/tabs/tab_strip_model.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "grit/generated_resources.h"
11 
TabMenuModel(ui::SimpleMenuModel::Delegate * delegate,bool is_pinned)12 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate,
13                            bool is_pinned)
14     : ui::SimpleMenuModel(delegate) {
15   Build(is_pinned);
16 }
17 
TabMenuModel(ui::SimpleMenuModel::Delegate * delegate,TabStripModel * tab_strip,int index)18 TabMenuModel::TabMenuModel(ui::SimpleMenuModel::Delegate* delegate,
19                            TabStripModel* tab_strip,
20                            int index)
21     : ui::SimpleMenuModel(delegate) {
22   Build(tab_strip, index);
23 }
24 
25 // static
AreVerticalTabsEnabled()26 bool TabMenuModel::AreVerticalTabsEnabled() {
27 #if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
28   return CommandLine::ForCurrentProcess()->HasSwitch(
29       switches::kEnableVerticalTabs);
30 #else
31   return false;
32 #endif
33 }
34 
Build(bool is_pinned)35 void TabMenuModel::Build(bool is_pinned) {
36   AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB);
37   AddSeparator();
38   AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD);
39   AddItemWithStringId(TabStripModel::CommandDuplicate,
40                       IDS_TAB_CXMENU_DUPLICATE);
41   AddItemWithStringId(
42       TabStripModel::CommandTogglePinned,
43       is_pinned ? IDS_TAB_CXMENU_UNPIN_TAB : IDS_TAB_CXMENU_PIN_TAB);
44   AddSeparator();
45   AddItemWithStringId(TabStripModel::CommandCloseTab,
46                       IDS_TAB_CXMENU_CLOSETAB);
47   AddItemWithStringId(TabStripModel::CommandCloseOtherTabs,
48                       IDS_TAB_CXMENU_CLOSEOTHERTABS);
49   AddItemWithStringId(TabStripModel::CommandCloseTabsToRight,
50                       IDS_TAB_CXMENU_CLOSETABSTORIGHT);
51   AddSeparator();
52   AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB);
53   AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs,
54                       IDS_TAB_CXMENU_BOOKMARK_ALL_TABS);
55   if (AreVerticalTabsEnabled()) {
56     AddSeparator();
57     AddCheckItemWithStringId(TabStripModel::CommandUseVerticalTabs,
58                              IDS_TAB_CXMENU_USE_VERTICAL_TABS);
59   }
60 }
61 
Build(TabStripModel * tab_strip,int index)62 void TabMenuModel::Build(TabStripModel* tab_strip, int index) {
63   bool effects_multiple_tabs =
64       (tab_strip->IsTabSelected(index) &&
65        tab_strip->selection_model().selected_indices().size() > 1);
66   AddItemWithStringId(TabStripModel::CommandNewTab, IDS_TAB_CXMENU_NEWTAB);
67   AddSeparator();
68   AddItemWithStringId(TabStripModel::CommandReload, IDS_TAB_CXMENU_RELOAD);
69   AddItemWithStringId(TabStripModel::CommandDuplicate,
70                       IDS_TAB_CXMENU_DUPLICATE);
71   bool will_pin = tab_strip->WillContextMenuPin(index);
72   if (effects_multiple_tabs) {
73     AddItemWithStringId(
74         TabStripModel::CommandTogglePinned,
75         will_pin ? IDS_TAB_CXMENU_PIN_TABS : IDS_TAB_CXMENU_UNPIN_TABS);
76   } else {
77     AddItemWithStringId(
78         TabStripModel::CommandTogglePinned,
79         will_pin ? IDS_TAB_CXMENU_PIN_TAB : IDS_TAB_CXMENU_UNPIN_TAB);
80   }
81   AddSeparator();
82   if (effects_multiple_tabs) {
83     AddItemWithStringId(TabStripModel::CommandCloseTab,
84                         IDS_TAB_CXMENU_CLOSETABS);
85   } else {
86     AddItemWithStringId(TabStripModel::CommandCloseTab,
87                         IDS_TAB_CXMENU_CLOSETAB);
88   }
89   AddItemWithStringId(TabStripModel::CommandCloseOtherTabs,
90                       IDS_TAB_CXMENU_CLOSEOTHERTABS);
91   AddItemWithStringId(TabStripModel::CommandCloseTabsToRight,
92                       IDS_TAB_CXMENU_CLOSETABSTORIGHT);
93   AddSeparator();
94   AddItemWithStringId(TabStripModel::CommandRestoreTab, IDS_RESTORE_TAB);
95   AddItemWithStringId(TabStripModel::CommandBookmarkAllTabs,
96                       IDS_TAB_CXMENU_BOOKMARK_ALL_TABS);
97   if (AreVerticalTabsEnabled()) {
98     AddSeparator();
99     AddCheckItemWithStringId(TabStripModel::CommandUseVerticalTabs,
100                              IDS_TAB_CXMENU_USE_VERTICAL_TABS);
101   }
102   if (CommandLine::ForCurrentProcess()->HasSwitch(
103           switches::kEnableTabGroupsContextMenu)) {
104     AddSeparator();
105     AddItemWithStringId(TabStripModel::CommandSelectByDomain,
106                         IDS_TAB_CXMENU_SELECT_BY_DOMAIN);
107     AddItemWithStringId(TabStripModel::CommandSelectByOpener,
108                         IDS_TAB_CXMENU_SELECT_BY_OPENER);
109   }
110 }
111