Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/ui/views/frame/system_menu_model_builder.cc

Issue 11819008: Refactors building the system menu model into a common place (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk and fix windows build Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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/views/frame/system_menu_model_builder.h"
6
7 #include "base/command_line.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/host_desktop.h"
12 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/accelerators/accelerator.h"
16 #include "ui/base/models/simple_menu_model.h"
17
18 #if defined(OS_WIN)
19 #include "chrome/browser/ui/views/frame/system_menu_model.h"
20 #endif
21
22 SystemMenuModelBuilder::SystemMenuModelBuilder(
23 ui::AcceleratorProvider* provider,
24 Browser* browser)
25 : menu_delegate_(provider, browser) {
26 }
27
28 SystemMenuModelBuilder::~SystemMenuModelBuilder() {
29 }
30
31 void SystemMenuModelBuilder::Init() {
32 bool needs_trailing_separator = false;
33 ui::SimpleMenuModel* model = CreateMenuModel(&needs_trailing_separator);
34 menu_model_.reset(model);
35 BuildMenu(model);
36 if (needs_trailing_separator)
37 model->AddSeparator(ui::NORMAL_SEPARATOR);
38 }
39
40 ui::SimpleMenuModel* SystemMenuModelBuilder::CreateMenuModel(
41 bool* needs_trailing_separator) {
42 #if defined(OS_WIN)
43 if (browser()->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_NATIVE) {
44 *needs_trailing_separator = true;
45 return new SystemMenuModel(&menu_delegate_);
46 }
47 #endif
48 *needs_trailing_separator = false;
49 return new ui::SimpleMenuModel(&menu_delegate_);
50 }
51
52 void SystemMenuModelBuilder::BuildMenu(ui::SimpleMenuModel* model) {
53 // We add the menu items in reverse order so that insertion_index never needs
54 // to change.
55 if (browser()->is_type_tabbed())
56 BuildSystemMenuForBrowserWindow(model);
57 else
58 BuildSystemMenuForAppOrPopupWindow(model);
59 AddFrameToggleItems(model);
60 }
61
62 void SystemMenuModelBuilder::BuildSystemMenuForBrowserWindow(
63 ui::SimpleMenuModel* model) {
64 model->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
65 model->AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB);
66 if (chrome::CanOpenTaskManager()) {
67 model->AddSeparator(ui::NORMAL_SEPARATOR);
68 model->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
69 }
70 // If it's a regular browser window with tabs, we don't add any more items,
71 // since it already has menus (Page, Chrome).
72 }
73
74 void SystemMenuModelBuilder::BuildSystemMenuForAppOrPopupWindow(
75 ui::SimpleMenuModel* model) {
76 model->AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK);
77 model->AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD);
78 model->AddItemWithStringId(IDC_RELOAD, IDS_APP_MENU_RELOAD);
79 model->AddSeparator(ui::NORMAL_SEPARATOR);
80 if (browser()->is_app())
81 model->AddItemWithStringId(IDC_NEW_TAB, IDS_APP_MENU_NEW_WEB_PAGE);
82 else
83 model->AddItemWithStringId(IDC_SHOW_AS_TAB, IDS_SHOW_AS_TAB);
84 model->AddSeparator(ui::NORMAL_SEPARATOR);
85 model->AddItemWithStringId(IDC_CUT, IDS_CUT);
86 model->AddItemWithStringId(IDC_COPY, IDS_COPY);
87 model->AddItemWithStringId(IDC_PASTE, IDS_PASTE);
88 model->AddSeparator(ui::NORMAL_SEPARATOR);
89 model->AddItemWithStringId(IDC_FIND, IDS_FIND);
90 model->AddItemWithStringId(IDC_PRINT, IDS_PRINT);
91 zoom_menu_contents_.reset(new ZoomMenuModel(&menu_delegate_));
92 model->AddSubMenuWithStringId(IDC_ZOOM_MENU, IDS_ZOOM_MENU,
93 zoom_menu_contents_.get());
94 encoding_menu_contents_.reset(new EncodingMenuModel(browser()));
95 model->AddSubMenuWithStringId(IDC_ENCODING_MENU,
96 IDS_ENCODING_MENU,
97 encoding_menu_contents_.get());
98 if (browser()->is_app() && chrome::CanOpenTaskManager()) {
99 model->AddSeparator(ui::NORMAL_SEPARATOR);
100 model->AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
101 }
102 }
103
104 void SystemMenuModelBuilder::AddFrameToggleItems(ui::SimpleMenuModel* model) {
105 if (CommandLine::ForCurrentProcess()->HasSwitch(
106 switches::kDebugEnableFrameToggle)) {
107 model->AddSeparator(ui::NORMAL_SEPARATOR);
108 model->AddItem(IDC_DEBUG_FRAME_TOGGLE, ASCIIToUTF16("Toggle Frame Type"));
109 }
110 }
111
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/system_menu_model_builder.h ('k') | chrome/browser/ui/views/frame/system_menu_model_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698