Index: chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
index 9323e2cba37907ffe0cc4c4ac7e878597c997d4e..1b87f71bc27aa6ea334d73d27d2a1577c404dd18 100644 |
--- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
+++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
@@ -146,6 +146,27 @@ void ClipboardSelectionCleared(GtkClipboard* clipboard, |
} |
} |
+// Returns the |menu| item whose label matches |label|. |
+guint GetPopupMenuIndexForStockLabel(const char* label, GtkMenu* menu) { |
+ string16 stock_label(UTF8ToUTF16(label)); |
+ GList* list = gtk_container_get_children(GTK_CONTAINER(menu)); |
+ guint index = 1; |
+ for (GList* item = list; item != NULL; item = item->next, ++index) { |
+ if (GTK_IS_IMAGE_MENU_ITEM(item->data)) { |
+ gboolean is_stock = gtk_image_menu_item_get_use_stock( |
+ GTK_IMAGE_MENU_ITEM(item->data)); |
+ if (is_stock) { |
+ string16 menu_item_label = UTF8ToUTF16( |
+ gtk_menu_item_get_label(GTK_MENU_ITEM(item->data))); |
+ if (menu_item_label == stock_label) |
+ break; |
+ } |
+ } |
+ } |
+ g_list_free(list); |
+ return index; |
+} |
+ |
} // namespace |
OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, |
@@ -1257,39 +1278,44 @@ void OmniboxViewGtk::HandlePopulatePopup(GtkWidget* sender, GtkMenu* menu) { |
command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES)); |
gtk_widget_show(search_engine_menuitem); |
- // Detect the Paste menu item by searching for the one that |
- // uses the stock Paste label (i.e. gtk-paste). |
- string16 stock_paste_label(UTF8ToUTF16(GTK_STOCK_PASTE)); |
- GList* list = gtk_container_get_children(GTK_CONTAINER(menu)); |
- guint index = 1; |
- for (GList* item = list; item != NULL; item = item->next, ++index) { |
- if (GTK_IS_IMAGE_MENU_ITEM(item->data)) { |
- gboolean is_stock = gtk_image_menu_item_get_use_stock( |
- GTK_IMAGE_MENU_ITEM(item->data)); |
- if (is_stock) { |
- string16 menu_item_label |
- (UTF8ToUTF16(gtk_menu_item_get_label(GTK_MENU_ITEM(item->data)))); |
- if (menu_item_label == stock_paste_label) { |
- break; |
- } |
- } |
- } |
- } |
- g_list_free(list); |
- |
- // If we don't find the stock Paste menu item, |
- // the Paste and Go item will be appended at the end of the popup menu. |
GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); |
gchar* text = gtk_clipboard_wait_for_text(x_clipboard); |
sanitized_text_for_paste_and_go_ = text ? |
StripJavascriptSchemas(CollapseWhitespace(UTF8ToUTF16(text), true)) : |
string16(); |
g_free(text); |
+ |
+ // Copy URL menu item. |
+ if (toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && |
+ !model()->user_input_in_progress()) { |
+ GtkWidget* copy_url_menuitem = gtk_menu_item_new_with_mnemonic( |
+ ui::ConvertAcceleratorsFromWindowsStyle( |
+ l10n_util::GetStringUTF8(IDS_COPY_URL)).c_str()); |
+ // If we don't find the stock Copy menu item, the Copy URL item will be |
+ // appended at the end of the popup menu. |
+ gtk_menu_shell_insert(GTK_MENU_SHELL(menu), copy_url_menuitem, |
+ GetPopupMenuIndexForStockLabel(GTK_STOCK_COPY, menu)); |
+ g_signal_connect(copy_url_menuitem, "activate", |
+ G_CALLBACK(HandleCopyURLClipboardThunk), this); |
+ gtk_widget_set_sensitive(copy_url_menuitem, |
+ command_updater()->IsCommandEnabled(IDC_COPY_URL)); |
+ gtk_widget_show(copy_url_menuitem); |
+ } |
+ |
+ // Paste and Go menu item. |
GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic( |
ui::ConvertAcceleratorsFromWindowsStyle(l10n_util::GetStringUTF8( |
model()->IsPasteAndSearch(sanitized_text_for_paste_and_go_) ? |
IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str()); |
- gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, index); |
+ |
+ // Detect the Paste and Copy menu items by searching for the ones that uses |
+ // the stock labels (i.e. gtk-paste and gtk-copy). |
+ |
+ // If we don't find the stock Paste menu item, the Paste and Go item will be |
+ // appended at the end of the popup menu. |
+ gtk_menu_shell_insert(GTK_MENU_SHELL(menu), paste_go_menuitem, |
+ GetPopupMenuIndexForStockLabel(GTK_STOCK_PASTE, menu)); |
+ |
g_signal_connect(paste_go_menuitem, "activate", |
G_CALLBACK(HandlePasteAndGoThunk), this); |
gtk_widget_set_sensitive(paste_go_menuitem, |
@@ -1577,6 +1603,15 @@ void OmniboxViewGtk::HandleCopyClipboard(GtkWidget* sender) { |
HandleCopyOrCutClipboard(true); |
} |
+void OmniboxViewGtk::HandleCopyURLClipboard(GtkWidget* sender) { |
+ const GURL& url = toolbar_model()->GetURL(); |
+ const string16& text = toolbar_model()->GetText(false); |
+ |
+ BookmarkNodeData data; |
+ data.ReadFromTuple(url, text); |
+ data.WriteToClipboard(NULL); |
+} |
+ |
void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { |
HandleCopyOrCutClipboard(false); |
} |