summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 20:25:58 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-16 20:25:58 +0000
commit126f5006bc8aa83e8e83f4917f33333f10633f21 (patch)
treeebd4984af98c3ed198866c443f315fc461d0b741
parentfff4f6fffb6eb1cf1993beade81577d04198fe75 (diff)
downloadchromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.zip
chromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.tar.gz
chromium_src-126f5006bc8aa83e8e83f4917f33333f10633f21.tar.bz2
GTK: navigate to URL on PRIMARY when middle-clicking the location icon.
BUG=40610 TEST=manual Review URL: http://codereview.chromium.org/1549043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44814 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/gtk_util.cc30
-rw-r--r--chrome/browser/gtk/gtk_util.h7
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc50
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h2
-rw-r--r--chrome/browser/gtk/tabs/tab_strip_gtk.cc24
5 files changed, 75 insertions, 38 deletions
diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc
index 15941cc..0f8b629 100644
--- a/chrome/browser/gtk/gtk_util.cc
+++ b/chrome/browser/gtk/gtk_util.cc
@@ -17,11 +17,13 @@
#include "base/i18n/rtl.h"
#include "base/linux_util.h"
#include "base/logging.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
#include "chrome/common/renderer_preferences.h"
+#include "googleurl/src/gurl.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -859,4 +861,32 @@ gfx::Rect WidgetBounds(GtkWidget* widget) {
return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height);
}
+bool URLFromPrimarySelection(Profile* profile, GURL* url) {
+ GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ DCHECK(clipboard);
+ gchar* selection_text = gtk_clipboard_wait_for_text(clipboard);
+ if (!selection_text)
+ return false;
+
+ // Use autocomplete to clean up the text, going so far as to turn it into
+ // a search query if necessary.
+ AutocompleteController controller(profile);
+ controller.Start(UTF8ToWide(selection_text),
+ std::wstring(), // desired_tld
+ true, // prevent_inline_autocomplete
+ false, // prefer_keyword
+ true); // synchronous_only
+ g_free(selection_text);
+ const AutocompleteResult& result = controller.result();
+ AutocompleteResult::const_iterator it = result.default_match();
+ if (it == result.end())
+ return false;
+
+ if (!it->destination_url.is_valid())
+ return false;
+
+ *url = it->destination_url;
+ return true;
+}
+
} // namespace gtk_util
diff --git a/chrome/browser/gtk/gtk_util.h b/chrome/browser/gtk/gtk_util.h
index b100b1d..02ae615 100644
--- a/chrome/browser/gtk/gtk_util.h
+++ b/chrome/browser/gtk/gtk_util.h
@@ -17,6 +17,8 @@
typedef struct _GtkWidget GtkWidget;
class GtkThemeProvider;
+class GURL;
+class Profile;
struct RendererPreferences; // from common/renderer_preferences.h
namespace event_utils {
@@ -260,6 +262,11 @@ bool GrabAllInput(GtkWidget* widget);
// returns is the same as widget->allocation, but anchored at (0, 0).
gfx::Rect WidgetBounds(GtkWidget* widget);
+// Uses the autocomplete controller for |profile| to convert the contents of the
+// PRIMARY selection to a parsed URL. Returns true and sets |url| on success,
+// otherwise returns false.
+bool URLFromPrimarySelection(Profile* profile, GURL* url);
+
} // namespace gtk_util
#endif // CHROME_BROWSER_GTK_GTK_UTIL_H_
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 6a66cb4..eab7c9b 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -909,24 +909,44 @@ void LocationBarViewGtk::ShowFirstRunBubbleInternal(
gboolean LocationBarViewGtk::OnIconReleased(GtkWidget* sender,
GdkEventButton* event) {
- // Do not show page info if the user has been editing the location
- // bar, or the location bar is at the NTP.
- if (location_entry()->IsEditingOrEmpty())
- return false;
+ TabContents* tab = GetTabContents();
- // (0,0) event coordinates indicates that the release came at the end of
- // a drag.
- if (event->button != 1 || (event->x == 0 && event->y == 0))
- return false;
+ if (event->button == 1) {
+ // Do not show page info if the user has been editing the location
+ // bar, or the location bar is at the NTP.
+ if (location_entry()->IsEditingOrEmpty())
+ return FALSE;
+
+ // (0,0) event coordinates indicates that the release came at the end of
+ // a drag.
+ if (event->x == 0 && event->y == 0)
+ return FALSE;
+
+ NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
+ if (!nav_entry) {
+ NOTREACHED();
+ return FALSE;
+ }
+ tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
+ return TRUE;
+ } else if (event->button == 2) {
+ // When the user middle clicks on the location icon, try to open the
+ // contents of the PRIMARY selection in the current tab.
+ // If the click was outside our bounds, do nothing.
+ if (!gtk_util::WidgetBounds(sender).Contains(
+ gfx::Point(event->x, event->y))) {
+ return FALSE;
+ }
- TabContents* tab = GetTabContents();
- NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
- if (!nav_entry) {
- NOTREACHED();
- return false;
+ GURL url;
+ if (!gtk_util::URLFromPrimarySelection(profile_, &url))
+ return FALSE;
+
+ tab->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::TYPED);
+ return TRUE;
}
- tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
- return true;
+
+ return FALSE;
}
void LocationBarViewGtk::OnIconDragData(GtkWidget* sender,
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index d8ce564..fb8bb38 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -47,7 +47,7 @@ class LocationBarViewGtk : public AutocompleteEditController,
public LocationBarTesting,
public NotificationObserver {
public:
- explicit LocationBarViewGtk(Browser* browser_);
+ explicit LocationBarViewGtk(Browser* browser);
virtual ~LocationBarViewGtk();
void Init(bool popup_window_mode);
diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
index 25a02c3..8d1d1c8 100644
--- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc
+++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc
@@ -1980,28 +1980,8 @@ void TabStripGtk::OnNewTabClicked(GtkWidget* widget, TabStripGtk* tabstrip) {
case 2: {
// On middle-click, try to parse the PRIMARY selection as a URL and load
// it instead of creating a blank page.
- GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
- DCHECK(clipboard);
- gchar* selection_text = gtk_clipboard_wait_for_text(clipboard);
- if (!selection_text)
- return;
-
- // Use autocomplete to clean up the text, going so far as to turn it into
- // a search query if necessary.
- AutocompleteController controller(tabstrip->model_->profile());
- controller.Start(UTF8ToWide(selection_text),
- std::wstring(), // desired_tld
- true, // prevent_inline_autocomplete
- false, // prefer_keyword
- true); // synchronous_only
- g_free(selection_text);
- const AutocompleteResult& result = controller.result();
- AutocompleteResult::const_iterator it = result.default_match();
- if (it == result.end())
- return;
-
- GURL url(it->destination_url);
- if (!url.is_valid())
+ GURL url;
+ if (!gtk_util::URLFromPrimarySelection(tabstrip->model_->profile(), &url))
return;
TabContents* contents =