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

Side by Side Diff: content/shell/browser/shell_web_contents_view_delegate_win.cc

Issue 2132983002: Move content shell context menu to ShellWebContentsViewDelegate in Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cast_shell_linux compile error Created 4 years, 5 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
« no previous file with comments | « content/shell/browser/shell_web_contents_view_delegate_views.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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 "content/shell/browser/shell_web_contents_view_delegate.h"
6
7 #include "base/command_line.h"
8 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/common/context_menu_params.h"
14 #include "content/shell/browser/shell.h"
15 #include "content/shell/browser/shell_browser_context.h"
16 #include "content/shell/browser/shell_browser_main_parts.h"
17 #include "content/shell/browser/shell_content_browser_client.h"
18 #include "content/shell/browser/shell_devtools_frontend.h"
19 #include "content/shell/browser/shell_web_contents_view_delegate_creator.h"
20 #include "content/shell/common/shell_switches.h"
21 #include "third_party/WebKit/public/web/WebContextMenuData.h"
22
23 using blink::WebContextMenuData;
24
25 namespace {
26
27 enum {
28 ShellContextMenuItemCutId = 10001,
29 ShellContextMenuItemCopyId,
30 ShellContextMenuItemPasteId,
31 ShellContextMenuItemDeleteId,
32 ShellContextMenuItemOpenLinkId,
33 ShellContextMenuItemBackId,
34 ShellContextMenuItemForwardId,
35 ShellContextMenuItemReloadId,
36 ShellContextMenuItemInspectId
37 };
38
39 void MakeContextMenuItem(HMENU menu,
40 int menu_index,
41 LPCTSTR text,
42 UINT id,
43 bool enabled) {
44 MENUITEMINFO mii = {0};
45 mii.cbSize = sizeof(mii);
46 mii.fMask = MIIM_FTYPE | MIIM_ID | MIIM_DATA | MIIM_STRING | MIIM_STATE;
47 mii.fState = enabled ? MFS_ENABLED : (MF_DISABLED | MFS_GRAYED);
48 mii.fType = MFT_STRING;
49 mii.wID = id;
50 mii.dwTypeData = const_cast<LPTSTR>(text);
51
52 InsertMenuItem(menu, menu_index, TRUE, &mii);
53 }
54
55 } // namespace
56
57 namespace content {
58
59 WebContentsViewDelegate* CreateShellWebContentsViewDelegate(
60 WebContents* web_contents) {
61 return new ShellWebContentsViewDelegate(web_contents);
62 }
63
64 ShellWebContentsViewDelegate::ShellWebContentsViewDelegate(
65 WebContents* web_contents)
66 : web_contents_(web_contents) {
67 }
68
69 ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() {
70 }
71
72 void ShellWebContentsViewDelegate::ShowContextMenu(
73 RenderFrameHost* render_frame_host,
74 const ContextMenuParams& params) {
75 if (switches::IsRunLayoutTestSwitchPresent())
76 return;
77
78 params_ = params;
79 bool has_link = !params_.unfiltered_link_url.is_empty();
80 bool has_selection = !params_.selection_text.empty();
81
82 HMENU menu = CreateMenu();
83 HMENU sub_menu = CreatePopupMenu();
84 AppendMenu(menu, MF_STRING | MF_POPUP, reinterpret_cast<UINT_PTR>(sub_menu),
85 L"");
86
87 int index = 0;
88 if (params_.media_type == WebContextMenuData::MediaTypeNone &&
89 !has_link &&
90 !has_selection &&
91 !params_.is_editable) {
92 MakeContextMenuItem(sub_menu,
93 index++,
94 L"Back",
95 ShellContextMenuItemBackId,
96 web_contents_->GetController().CanGoBack());
97
98 MakeContextMenuItem(sub_menu,
99 index++,
100 L"Forward",
101 ShellContextMenuItemForwardId,
102 web_contents_->GetController().CanGoForward());
103
104 MakeContextMenuItem(sub_menu,
105 index++,
106 L"Reload",
107 ShellContextMenuItemReloadId,
108 true);
109
110 AppendMenu(sub_menu, MF_SEPARATOR, 0, NULL);
111 index++;
112 }
113
114 if (has_link) {
115 MakeContextMenuItem(sub_menu,
116 index++,
117 L"Open in New Window",
118 ShellContextMenuItemOpenLinkId,
119 true);
120 AppendMenu(sub_menu, MF_SEPARATOR, 0, NULL);
121 index++;
122 }
123
124 if (params_.is_editable) {
125 bool cut_enabled = ((params_.edit_flags & WebContextMenuData::CanCut) != 0);
126 MakeContextMenuItem(sub_menu,
127 index++,
128 L"Cut",
129 ShellContextMenuItemCutId,
130 cut_enabled);
131
132 bool copy_enabled =
133 ((params_.edit_flags & WebContextMenuData::CanCopy) != 0);
134 MakeContextMenuItem(sub_menu,
135 index++,
136 L"Copy",
137 ShellContextMenuItemCopyId,
138 copy_enabled);
139
140 bool paste_enabled =
141 ((params_.edit_flags & WebContextMenuData::CanPaste) != 0);
142 MakeContextMenuItem(sub_menu,
143 index++,
144 L"Paste",
145 ShellContextMenuItemPasteId,
146 paste_enabled);
147 bool delete_enabled =
148 ((params_.edit_flags & WebContextMenuData::CanDelete) != 0);
149 MakeContextMenuItem(sub_menu,
150 index++,
151 L"Delete",
152 ShellContextMenuItemDeleteId,
153 delete_enabled);
154
155 AppendMenu(sub_menu, MF_SEPARATOR, 0, NULL);
156 index++;
157 } else if (has_selection) {
158 MakeContextMenuItem(sub_menu,
159 index++,
160 L"Copy",
161 ShellContextMenuItemCopyId,
162 true);
163
164 AppendMenu(sub_menu, MF_SEPARATOR, 0, NULL);
165 index++;
166 }
167
168 MakeContextMenuItem(sub_menu,
169 index++,
170 L"Inspect...",
171 ShellContextMenuItemInspectId,
172 true);
173 NOTIMPLEMENTED();
174 DestroyMenu(menu);
175 }
176
177 void ShellWebContentsViewDelegate::MenuItemSelected(int selection) {
178 switch (selection) {
179 case ShellContextMenuItemCutId:
180 web_contents_->Cut();
181 break;
182 case ShellContextMenuItemCopyId:
183 web_contents_->Copy();
184 break;
185 case ShellContextMenuItemPasteId:
186 web_contents_->Paste();
187 break;
188 case ShellContextMenuItemDeleteId:
189 web_contents_->Delete();
190 break;
191 case ShellContextMenuItemOpenLinkId: {
192 ShellBrowserContext* browser_context =
193 ShellContentBrowserClient::Get()->browser_context();
194 Shell::CreateNewWindow(browser_context,
195 params_.link_url,
196 NULL,
197 gfx::Size());
198 break;
199 }
200 case ShellContextMenuItemBackId:
201 web_contents_->GetController().GoToOffset(-1);
202 web_contents_->Focus();
203 break;
204 case ShellContextMenuItemForwardId:
205 web_contents_->GetController().GoToOffset(1);
206 web_contents_->Focus();
207 break;
208 case ShellContextMenuItemReloadId:
209 web_contents_->GetController().Reload(false);
210 web_contents_->Focus();
211 break;
212 case ShellContextMenuItemInspectId: {
213 ShellDevToolsFrontend::Show(web_contents_);
214 break;
215 }
216 }
217 }
218
219 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/browser/shell_web_contents_view_delegate_views.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698