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

Side by Side Diff: content/shell/shell_web_contents_view_delegate_gtk.cc

Issue 10913035: Add context popup menu support for content shell[GTK]. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix the Mac build Created 8 years, 3 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/shell_web_contents_view_delegate_creator.h ('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 (c) 2012 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/shell_web_contents_view_delegate.h"
6
7 #include "content/public/browser/devtools_http_handler.h"
8 #include "content/public/browser/render_process_host.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h"
13 #include "content/public/common/context_menu_params.h"
14 #include "content/shell/shell.h"
15 #include "content/shell/shell_browser_context.h"
16 #include "content/shell/shell_browser_main_parts.h"
17 #include "content/shell/shell_content_browser_client.h"
18 #include "content/shell/shell_devtools_delegate.h"
19 #include "content/shell/shell_web_contents_view_delegate_creator.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
21 #include "ui/base/gtk/focus_store_gtk.h"
22 #include "ui/base/gtk/gtk_floating_container.h"
23
24 using WebKit::WebContextMenuData;
25
26 namespace content {
27
28 WebContentsViewDelegate* CreateShellWebContentsViewDelegate(
29 WebContents* web_contents) {
30 return new ShellWebContentsViewDelegate(web_contents);
31 }
32
33 ShellWebContentsViewDelegate::ShellWebContentsViewDelegate(
34 WebContents* web_contents)
35 : web_contents_(web_contents),
36 floating_(gtk_floating_container_new()) {
37 }
38
39 ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() {
40 floating_.Destroy();
41 }
42
43 void ShellWebContentsViewDelegate::ShowContextMenu(
44 const ContextMenuParams& params) {
45 GtkWidget* menu = gtk_menu_new();
46
47 params_ = params;
48 bool has_link = !params_.unfiltered_link_url.is_empty();
49 bool has_selection = !params_.selection_text.empty();
50
51 if (params_.media_type == WebContextMenuData::MediaTypeNone &&
52 !has_link &&
53 !has_selection &&
54 !params_.is_editable) {
55 GtkWidget* back_menu = gtk_menu_item_new_with_label("Back");
56 gtk_menu_append(GTK_MENU(menu), back_menu);
57 g_signal_connect(back_menu,
58 "activate",
59 G_CALLBACK(OnBackMenuActivatedThunk),
60 this);
61 gtk_widget_set_sensitive(back_menu,
62 web_contents_->GetController().CanGoBack());
63
64 GtkWidget* forward_menu = gtk_menu_item_new_with_label("Forward");
65 gtk_menu_append(GTK_MENU(menu), forward_menu);
66 g_signal_connect(forward_menu,
67 "activate",
68 G_CALLBACK(OnForwardMenuActivatedThunk),
69 this);
70 gtk_widget_set_sensitive(forward_menu,
71 web_contents_->GetController().CanGoForward());
72
73 GtkWidget* reload_menu = gtk_menu_item_new_with_label("Reload");
74 gtk_menu_append(GTK_MENU(menu), reload_menu);
75 g_signal_connect(reload_menu,
76 "activate",
77 G_CALLBACK(OnReloadMenuActivatedThunk),
78 this);
79
80 GtkWidget* navigate_separator = gtk_separator_menu_item_new();
81 gtk_menu_append(GTK_MENU(menu), navigate_separator);
82 }
83
84 if (has_link) {
85 GtkWidget* open_menu = gtk_menu_item_new_with_label("Open in New Window");
86 gtk_menu_append(GTK_MENU(menu), open_menu);
87 g_signal_connect(open_menu,
88 "activate",
89 G_CALLBACK(OnOpenURLMenuActivatedThunk),
90 this);
91
92 GtkWidget* link_separator = gtk_separator_menu_item_new();
93 gtk_menu_append(GTK_MENU(menu), link_separator);
94 }
95
96 if (params_.is_editable) {
97 GtkWidget* cut_menu = gtk_menu_item_new_with_label("Cut");
98 gtk_menu_append(GTK_MENU(menu), cut_menu);
99 g_signal_connect(cut_menu,
100 "activate",
101 G_CALLBACK(OnCutMenuActivatedThunk),
102 this);
103 gtk_widget_set_sensitive(
104 cut_menu,
105 params_.edit_flags & WebContextMenuData::CanCut);
106
107 GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy");
108 gtk_menu_append(GTK_MENU(menu), copy_menu);
109 g_signal_connect(copy_menu,
110 "activate",
111 G_CALLBACK(OnCopyMenuActivatedThunk),
112 this);
113 gtk_widget_set_sensitive(
114 copy_menu,
115 params_.edit_flags & WebContextMenuData::CanCopy);
116
117 GtkWidget* paste_menu = gtk_menu_item_new_with_label("Paste");
118 gtk_menu_append(GTK_MENU(menu), paste_menu);
119 g_signal_connect(paste_menu,
120 "activate",
121 G_CALLBACK(OnPasteMenuActivatedThunk),
122 this);
123 gtk_widget_set_sensitive(
124 paste_menu,
125 params_.edit_flags & WebContextMenuData::CanPaste);
126
127 GtkWidget* delete_menu = gtk_menu_item_new_with_label("Delete");
128 gtk_menu_append(GTK_MENU(menu), delete_menu);
129 g_signal_connect(delete_menu,
130 "activate",
131 G_CALLBACK(OnDeleteMenuActivatedThunk),
132 this);
133 gtk_widget_set_sensitive(
134 delete_menu,
135 params_.edit_flags & WebContextMenuData::CanDelete);
136
137 GtkWidget* edit_separator = gtk_separator_menu_item_new();
138 gtk_menu_append(GTK_MENU(menu), edit_separator);
139 } else if (has_selection) {
140 GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy");
141 gtk_menu_append(GTK_MENU(menu), copy_menu);
142 g_signal_connect(copy_menu,
143 "activate",
144 G_CALLBACK(OnCopyMenuActivatedThunk),
145 this);
146
147 GtkWidget* copy_separator = gtk_separator_menu_item_new();
148 gtk_menu_append(GTK_MENU(menu), copy_separator);
149 }
150
151 GtkWidget* inspect_menu = gtk_menu_item_new_with_label("Inspect...");
152 gtk_menu_append(GTK_MENU(menu), inspect_menu);
153 g_signal_connect(inspect_menu,
154 "activate",
155 G_CALLBACK(OnInspectMenuActivatedThunk),
156 this);
157
158 gtk_widget_show_all(menu);
159
160 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, GDK_CURRENT_TIME);
161 }
162
163 WebDragDestDelegate* ShellWebContentsViewDelegate::GetDragDestDelegate() {
164 return NULL;
165 }
166
167 void ShellWebContentsViewDelegate::Initialize(GtkWidget* expanded_container,
168 ui::FocusStoreGtk* focus_store) {
169 expanded_container_ = expanded_container;
170
171 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_container_);
172 gtk_widget_show(floating_.get());
173 }
174
175 gfx::NativeView ShellWebContentsViewDelegate::GetNativeView() const {
176 return floating_.get();
177 }
178
179 void ShellWebContentsViewDelegate::Focus() {
180 GtkWidget* widget = web_contents_->GetView()->GetContentNativeView();
181 if (widget)
182 gtk_widget_grab_focus(widget);
183 }
184
185 gboolean ShellWebContentsViewDelegate::OnNativeViewFocusEvent(
186 GtkWidget* widget,
187 GtkDirectionType type,
188 gboolean* return_value) {
189 return false;
190 }
191
192 void ShellWebContentsViewDelegate::OnBackMenuActivated(GtkWidget* widget) {
193 web_contents_->GetController().GoToOffset(-1);
194 web_contents_->Focus();
195 }
196
197 void ShellWebContentsViewDelegate::OnForwardMenuActivated(GtkWidget* widget) {
198 web_contents_->GetController().GoToOffset(1);
199 web_contents_->Focus();
200 }
201
202 void ShellWebContentsViewDelegate::OnReloadMenuActivated(GtkWidget* widget) {
203 web_contents_->GetController().Reload(false);
204 web_contents_->Focus();
205 }
206
207 void ShellWebContentsViewDelegate::OnOpenURLMenuActivated(GtkWidget* widget) {
208 ShellBrowserContext* browser_context =
209 static_cast<ShellContentBrowserClient*>(
210 GetContentClient()->browser())->browser_context();
211 Shell::CreateNewWindow(browser_context,
212 params_.link_url,
213 NULL,
214 MSG_ROUTING_NONE,
215 NULL);
216 }
217
218 void ShellWebContentsViewDelegate::OnCutMenuActivated(GtkWidget* widget) {
219 web_contents_->GetRenderViewHost()->Cut();
220 }
221
222 void ShellWebContentsViewDelegate::OnCopyMenuActivated(GtkWidget* widget) {
223 web_contents_->GetRenderViewHost()->Copy();
224 }
225
226 void ShellWebContentsViewDelegate::OnPasteMenuActivated(GtkWidget* widget) {
227 web_contents_->GetRenderViewHost()->Paste();
228 }
229
230 void ShellWebContentsViewDelegate::OnDeleteMenuActivated(GtkWidget* widget) {
231 web_contents_->GetRenderViewHost()->Delete();
232 }
233
234 void ShellWebContentsViewDelegate::OnInspectMenuActivated(GtkWidget* widget) {
235 ShellContentBrowserClient* browser_client =
236 static_cast<ShellContentBrowserClient*>(
237 GetContentClient()->browser());
238 ShellDevToolsDelegate* delegate =
239 browser_client->shell_browser_main_parts()->devtools_delegate();
240 GURL url = delegate->devtools_http_handler()->GetFrontendURL(
241 web_contents_->GetRenderViewHost());
242 Shell::CreateNewWindow(web_contents_->GetBrowserContext(),
243 url,
244 NULL,
245 MSG_ROUTING_NONE,
246 NULL);
247 }
248
249 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell_web_contents_view_delegate_creator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698