summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authormhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 22:19:34 +0000
committermhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 22:19:34 +0000
commit431c446fbd7fe899a5792d611f5abb1a1f68ea3c (patch)
tree3745e723743206a8e525346fbc70c6f0885a6dfa /chrome/browser/autocomplete
parentc6c066721f0678fc694f96169514c8aa14e9ffe1 (diff)
downloadchromium_src-431c446fbd7fe899a5792d611f5abb1a1f68ea3c.zip
chromium_src-431c446fbd7fe899a5792d611f5abb1a1f68ea3c.tar.gz
chromium_src-431c446fbd7fe899a5792d611f5abb1a1f68ea3c.tar.bz2
Paste and Go was missing on the omnibar this CL will append a menu item to the current Autocomplete edit box and by using Gtk clipboard, it will paste and search it.
BUG=14800 (http://crbug.com/14800) TEST=Selected text from view and right clicked copied. Went to the omnibox and right clicked > Paste and Go. It navigated to the page successfully. Review URL: http://codereview.chromium.org/140050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18967 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc31
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h18
2 files changed, 45 insertions, 4 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 17e9a11..06647df 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -508,19 +508,42 @@ void AutocompleteEditViewGtk::HandlePopulatePopup(GtkMenu* menu) {
GtkWidget* separator = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
gtk_widget_show(separator);
- GtkWidget* menuitem = gtk_menu_item_new_with_mnemonic(
+
+ // Search Engine menu item.
+ GtkWidget* search_engine_menuitem = gtk_menu_item_new_with_mnemonic(
gtk_util::ConvertAcceleratorsFromWindowsStyle(
l10n_util::GetStringUTF8(IDS_EDIT_SEARCH_ENGINES)).c_str());
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
- g_signal_connect(menuitem, "activate",
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), search_engine_menuitem);
+ g_signal_connect(search_engine_menuitem, "activate",
G_CALLBACK(HandleEditSearchEnginesThunk), this);
- gtk_widget_show(menuitem);
+ gtk_widget_show(search_engine_menuitem);
+
+ // Paste and Go menu item.
+ GtkWidget* paste_go_menuitem = gtk_menu_item_new_with_mnemonic(
+ gtk_util::ConvertAcceleratorsFromWindowsStyle(
+ l10n_util::GetStringUTF8(model_->is_paste_and_search() ?
+ IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO)).c_str());
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), paste_go_menuitem);
+ g_signal_connect(paste_go_menuitem, "activate",
+ G_CALLBACK(HandlePasteAndGoThunk), this);
+ gtk_widget_show(paste_go_menuitem);
}
void AutocompleteEditViewGtk::HandleEditSearchEngines() {
command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES);
}
+void AutocompleteEditViewGtk::HandlePasteAndGo() {
+ GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_request_text(x_clipboard, HandlePasteAndGoReceivedTextThunk,
+ this);
+}
+
+void AutocompleteEditViewGtk::HandlePasteAndGoReceivedText(
+ const std::wstring& text) {
+ if (model_->CanPasteAndGo(text))
+ model_->PasteAndGo();
+}
AutocompleteEditViewGtk::CharRange AutocompleteEditViewGtk::GetSelection() {
// You can not just use get_selection_bounds here, since the order will be
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index d22d90e..70e32f3 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/toolbar_model.h"
#include "chrome/common/owned_widget_gtk.h"
@@ -183,6 +184,23 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
}
void HandleEditSearchEngines();
+ static void HandlePasteAndGoThunk(GtkMenuItem* menuitem,
+ AutocompleteEditViewGtk* self) {
+ self->HandlePasteAndGo();
+ }
+ void HandlePasteAndGo();
+
+ static void HandlePasteAndGoReceivedTextThunk(GtkClipboard* clipboard,
+ const gchar* text,
+ gpointer self) {
+ // If there is nothing to paste (|text| is NULL), do nothing.
+ if (!text)
+ return;
+ reinterpret_cast<AutocompleteEditViewGtk*>(self)->
+ HandlePasteAndGoReceivedText(UTF8ToWide(text));
+ }
+ void HandlePasteAndGoReceivedText(const std::wstring& text);
+
// Get the character indices of the current selection. This honors
// direction, cp_max is the insertion point, and cp_min is the bound.
CharRange GetSelection();