Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | |
| 20 #include "ui/base/gtk/focus_store_gtk.h" | |
| 21 #include "ui/base/gtk/gtk_floating_container.h" | |
| 22 | |
| 23 using WebKit::WebContextMenuData; | |
| 24 | |
| 25 namespace content { | |
| 26 | |
| 27 ShellWebContentsViewDelegate::ShellWebContentsViewDelegate( | |
| 28 WebContents* web_contents) | |
| 29 : web_contents_(web_contents), | |
| 30 floating_(gtk_floating_container_new()) { | |
| 31 } | |
| 32 | |
| 33 ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() { | |
| 34 floating_.Destroy(); | |
| 35 } | |
| 36 | |
| 37 void ShellWebContentsViewDelegate::ShowContextMenu( | |
| 38 const ContextMenuParams& params) { | |
| 39 GtkWidget* menu = gtk_menu_new(); | |
| 40 | |
| 41 params_ = params; | |
| 42 bool has_link = !params_.unfiltered_link_url.is_empty(); | |
| 43 bool has_selection = !params_.selection_text.empty(); | |
| 44 | |
| 45 if (params_.media_type == WebContextMenuData::MediaTypeNone && | |
| 46 !has_link && | |
| 47 !has_selection && | |
| 48 !params_.is_editable) { | |
| 49 GtkWidget* back_menu = gtk_menu_item_new_with_label("Back"); | |
| 50 gtk_menu_append(GTK_MENU(menu), back_menu); | |
| 51 g_signal_connect(back_menu, "activate", | |
|
jochen (gone - plz use gerrit)
2012/08/31 20:58:58
each parameter should go on its own line
Shouqun Liu
2012/08/31 21:34:20
Done.
| |
| 52 G_CALLBACK(OnBackMenuActivatedThunk), this); | |
| 53 gtk_widget_set_sensitive(back_menu, | |
| 54 web_contents_->GetController().CanGoBack()); | |
| 55 | |
| 56 GtkWidget* forward_menu = gtk_menu_item_new_with_label("Forward"); | |
| 57 gtk_menu_append(GTK_MENU(menu), forward_menu); | |
| 58 g_signal_connect(forward_menu, "activate", | |
|
jochen (gone - plz use gerrit)
2012/08/31 20:58:58
same here and below
| |
| 59 G_CALLBACK(OnForwardMenuActivatedThunk), this); | |
| 60 gtk_widget_set_sensitive(forward_menu, | |
| 61 web_contents_->GetController().CanGoForward()); | |
| 62 | |
| 63 GtkWidget* reload_menu = gtk_menu_item_new_with_label("Reload"); | |
| 64 gtk_menu_append(GTK_MENU(menu), reload_menu); | |
| 65 g_signal_connect(reload_menu, "activate", | |
| 66 G_CALLBACK(OnReloadMenuActivatedThunk), this); | |
| 67 | |
| 68 GtkWidget* navigate_separator = gtk_separator_menu_item_new(); | |
| 69 gtk_menu_append(GTK_MENU(menu), navigate_separator); | |
| 70 } | |
| 71 | |
| 72 if (has_link) { | |
| 73 GtkWidget* open_menu = gtk_menu_item_new_with_label("Open in New Window"); | |
| 74 gtk_menu_append(GTK_MENU(menu), open_menu); | |
| 75 g_signal_connect(open_menu, "activate", | |
| 76 G_CALLBACK(OnOpenURLMenuActivatedThunk), this); | |
| 77 | |
| 78 GtkWidget* link_separator = gtk_separator_menu_item_new(); | |
| 79 gtk_menu_append(GTK_MENU(menu), link_separator); | |
| 80 } | |
| 81 | |
| 82 if (params_.is_editable) { | |
| 83 GtkWidget* cut_menu = gtk_menu_item_new_with_label("Cut"); | |
| 84 gtk_menu_append(GTK_MENU(menu), cut_menu); | |
| 85 g_signal_connect(cut_menu, "activate", | |
| 86 G_CALLBACK(OnCutMenuActivatedThunk), this); | |
| 87 gtk_widget_set_sensitive( | |
| 88 cut_menu, | |
| 89 params_.edit_flags & WebContextMenuData::CanCut); | |
| 90 | |
| 91 GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy"); | |
| 92 gtk_menu_append(GTK_MENU(menu), copy_menu); | |
| 93 g_signal_connect(copy_menu, "activate", | |
| 94 G_CALLBACK(OnCopyMenuActivatedThunk), this); | |
| 95 gtk_widget_set_sensitive( | |
| 96 copy_menu, | |
| 97 params_.edit_flags & WebContextMenuData::CanCopy); | |
| 98 | |
| 99 GtkWidget* paste_menu = gtk_menu_item_new_with_label("Paste"); | |
| 100 gtk_menu_append(GTK_MENU(menu), paste_menu); | |
| 101 g_signal_connect(paste_menu, "activate", | |
| 102 G_CALLBACK(OnPasteMenuActivatedThunk), this); | |
| 103 gtk_widget_set_sensitive( | |
| 104 paste_menu, | |
| 105 params_.edit_flags & WebContextMenuData::CanPaste); | |
| 106 | |
| 107 GtkWidget* delete_menu = gtk_menu_item_new_with_label("Delete"); | |
| 108 gtk_menu_append(GTK_MENU(menu), delete_menu); | |
| 109 g_signal_connect(delete_menu, "activate", | |
| 110 G_CALLBACK(OnDeleteMenuActivatedThunk), this); | |
| 111 gtk_widget_set_sensitive( | |
| 112 delete_menu, | |
| 113 params_.edit_flags & WebContextMenuData::CanDelete); | |
| 114 | |
| 115 GtkWidget* edit_separator = gtk_separator_menu_item_new(); | |
| 116 gtk_menu_append(GTK_MENU(menu), edit_separator); | |
| 117 | |
|
jochen (gone - plz use gerrit)
2012/08/31 20:58:58
no empty line
| |
| 118 } else if (has_selection) { | |
| 119 GtkWidget* copy_menu = gtk_menu_item_new_with_label("Copy"); | |
| 120 gtk_menu_append(GTK_MENU(menu), copy_menu); | |
| 121 g_signal_connect(copy_menu, "activate", | |
| 122 G_CALLBACK(OnCopyMenuActivatedThunk), this); | |
| 123 | |
| 124 GtkWidget* copy_separator = gtk_separator_menu_item_new(); | |
| 125 gtk_menu_append(GTK_MENU(menu), copy_separator); | |
| 126 } | |
| 127 | |
| 128 GtkWidget* inspect_menu = gtk_menu_item_new_with_label("Inspect..."); | |
| 129 gtk_menu_append(GTK_MENU(menu), inspect_menu); | |
| 130 g_signal_connect(inspect_menu, "activate", | |
| 131 G_CALLBACK(OnInspectMenuActivatedThunk), this); | |
| 132 | |
| 133 gtk_widget_show_all(menu); | |
| 134 | |
| 135 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, GDK_CURRENT_TIME); | |
| 136 } | |
| 137 | |
| 138 WebDragDestDelegate* ShellWebContentsViewDelegate::GetDragDestDelegate() { | |
| 139 return NULL; | |
| 140 } | |
| 141 | |
| 142 void ShellWebContentsViewDelegate::Initialize(GtkWidget* expanded_container, | |
| 143 ui::FocusStoreGtk* focus_store) { | |
| 144 expanded_container_ = expanded_container; | |
| 145 | |
| 146 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_container_); | |
| 147 gtk_widget_show(floating_.get()); | |
| 148 } | |
| 149 | |
| 150 gfx::NativeView ShellWebContentsViewDelegate::GetNativeView() const { | |
| 151 return floating_.get(); | |
| 152 } | |
| 153 | |
| 154 void ShellWebContentsViewDelegate::Focus() { | |
| 155 GtkWidget* widget = web_contents_->GetView()->GetContentNativeView(); | |
| 156 if (widget) | |
| 157 gtk_widget_grab_focus(widget); | |
| 158 } | |
| 159 | |
| 160 gboolean ShellWebContentsViewDelegate::OnNativeViewFocusEvent( | |
| 161 GtkWidget* widget, | |
| 162 GtkDirectionType type, | |
| 163 gboolean* return_value) { | |
| 164 return false; | |
| 165 } | |
| 166 | |
| 167 void ShellWebContentsViewDelegate::OnBackMenuActivated(GtkWidget* widget) { | |
| 168 web_contents_->GetController().GoToOffset(-1); | |
| 169 web_contents_->Focus(); | |
| 170 } | |
| 171 | |
| 172 void ShellWebContentsViewDelegate::OnForwardMenuActivated(GtkWidget* widget) { | |
| 173 web_contents_->GetController().GoToOffset(1); | |
| 174 web_contents_->Focus(); | |
| 175 } | |
| 176 | |
| 177 void ShellWebContentsViewDelegate::OnReloadMenuActivated(GtkWidget* widget) { | |
| 178 web_contents_->GetController().Reload(false); | |
| 179 web_contents_->Focus(); | |
| 180 } | |
| 181 | |
| 182 void ShellWebContentsViewDelegate::OnOpenURLMenuActivated(GtkWidget* widget) { | |
| 183 ShellBrowserContext* browser_context = | |
| 184 static_cast<ShellContentBrowserClient*>( | |
| 185 GetContentClient()->browser())->browser_context(); | |
| 186 Shell::CreateNewWindow(browser_context, | |
| 187 params_.link_url, | |
| 188 NULL, | |
| 189 MSG_ROUTING_NONE, | |
| 190 NULL); | |
| 191 } | |
| 192 | |
| 193 void ShellWebContentsViewDelegate::OnCutMenuActivated(GtkWidget* widget) { | |
| 194 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
| 195 rvh->Cut(); | |
| 196 } | |
| 197 | |
| 198 void ShellWebContentsViewDelegate::OnCopyMenuActivated(GtkWidget* widget) { | |
| 199 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
| 200 rvh->Copy(); | |
| 201 } | |
| 202 | |
| 203 void ShellWebContentsViewDelegate::OnPasteMenuActivated(GtkWidget* widget) { | |
| 204 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
| 205 rvh->Paste(); | |
| 206 } | |
| 207 | |
| 208 void ShellWebContentsViewDelegate::OnDeleteMenuActivated(GtkWidget* widget) { | |
| 209 RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | |
| 210 rvh->Delete(); | |
| 211 } | |
| 212 | |
| 213 void ShellWebContentsViewDelegate::OnInspectMenuActivated(GtkWidget* widget) { | |
| 214 ShellContentBrowserClient* browser_client = | |
| 215 static_cast<ShellContentBrowserClient*>( | |
| 216 GetContentClient()->browser()); | |
| 217 ShellDevToolsDelegate* delegate = | |
| 218 browser_client->shell_browser_main_parts()->devtools_delegate(); | |
| 219 GURL url = delegate->devtools_http_handler()->GetFrontendURL( | |
| 220 web_contents_->GetRenderViewHost()); | |
| 221 Shell::CreateNewWindow( | |
| 222 web_contents_->GetBrowserContext(), | |
| 223 url, NULL, MSG_ROUTING_NONE, NULL); | |
|
jochen (gone - plz use gerrit)
2012/08/31 20:58:58
either each parameter on it's own line or all para
| |
| 224 } | |
| 225 | |
| 226 } // namespace content | |
| OLD | NEW |