Chromium Code Reviews| 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..505e032954cbe18a67795002d34f58227e9a9ce7 100644 |
| --- a/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
| +++ b/chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc |
| @@ -145,6 +145,25 @@ void ClipboardSelectionCleared(GtkClipboard* clipboard, |
| &insert); |
| } |
| } |
|
Evan Stade
2012/09/05 21:07:17
blank line and function docs
dominich
2012/09/05 21:21:39
Done.
|
| +guint GetPopupMenuIndexForStockLabel(const char* label, GtkMenu* menu) { |
| + string16 stock_label(UTF8ToUTF16(label)); |
|
Evan Stade
2012/09/05 21:07:17
why do you convert to utf16 before comparison?
dominich
2012/09/05 21:21:39
It's what the original code was doing. It seemed s
Evan Stade
2012/09/05 22:11:50
well then let's change it.
dominich
2012/09/05 23:35:34
Done.
|
| + 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 |
| @@ -1257,39 +1276,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 +1601,15 @@ void OmniboxViewGtk::HandleCopyClipboard(GtkWidget* sender) { |
| HandleCopyOrCutClipboard(true); |
| } |
| +void OmniboxViewGtk::HandleCopyURLClipboard(GtkWidget* sender) { |
| + const string16& text = toolbar_model()->GetText(false); |
|
Evan Stade
2012/09/05 21:07:17
nit: I'd declare these in the order they're used.
dominich
2012/09/05 21:21:39
Done.
|
| + const GURL& url = toolbar_model()->GetURL(); |
| + |
| + BookmarkNodeData data; |
| + data.ReadFromTuple(url, text); |
| + data.WriteToClipboard(NULL); |
|
Evan Stade
2012/09/05 21:07:17
why don't you pass the profile?
dominich
2012/09/05 21:21:39
the HandleCopyOrCutClipboard method below passes N
Evan Stade
2012/09/05 22:11:50
why does that one pass NULL?
dominich
2012/09/05 23:35:34
we don't want to write the profile path to the boo
Evan Stade
2012/09/06 01:35:03
can you add documentation to BookmarkNodeData::Wri
|
| +} |
| + |
| void OmniboxViewGtk::HandleCutClipboard(GtkWidget* sender) { |
| HandleCopyOrCutClipboard(false); |
| } |