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..eb282681aae4ed64e855053c9179a4a7d38e7166 100644 |
--- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
+++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
@@ -31,6 +31,7 @@ |
#include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
#include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
+#include "chrome/browser/ui/search/search.h" |
#include "chrome/browser/ui/toolbar/toolbar_model.h" |
#include "chrome/common/chrome_notification_types.h" |
#include "content/public/browser/notification_source.h" |
@@ -146,6 +147,26 @@ void ClipboardSelectionCleared(GtkClipboard* clipboard, |
} |
} |
+// Returns the |menu| item whose label matches |label|. |
+guint GetPopupMenuIndexForStockLabel(const char* label, GtkMenu* menu) { |
+ 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) { |
+ std::string menu_item_label = |
+ gtk_menu_item_get_label(GTK_MENU_ITEM(item->data)); |
+ if (menu_item_label == label) |
+ break; |
+ } |
+ } |
+ } |
+ g_list_free(list); |
+ return index; |
+} |
+ |
} // namespace |
OmniboxViewGtk::OmniboxViewGtk(OmniboxEditController* controller, |
@@ -1257,39 +1278,45 @@ 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 (chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())) { |
+ 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, |
+ toolbar_model()->WouldReplaceSearchURLWithSearchTerms() && |
+ !model()->user_input_in_progress()); |
+ 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 |
Peter Kasting
2012/09/11 21:52:59
Nit: uses -> use
dominich
2012/09/12 15:23:09
Done.
|
+ // the stock labels (i.e. gtk-paste and gtk-copy). |
Peter Kasting
2012/09/11 21:52:59
Nit: This comment seems a bit out of place given t
dominich
2012/09/12 15:23:09
Done.
|
+ |
+ // 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 +1604,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; |
Peter Kasting
2012/09/11 21:52:59
Nit: Would be nice to factor out this chunk from h
dominich
2012/09/12 15:23:09
No - it's an activate signal on the menu item rath
|
+ data.ReadFromTuple(url, text); |
+ data.WriteToClipboard(NULL); |
+} |
+ |
void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { |
HandleCopyOrCutClipboard(false); |
} |