Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Unified Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 147246: Linux: middle-click to navigate (Closed)
Patch Set: ... Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/tab_contents_view_gtk.cc
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
index 0ad9d9a20733be91197d83305f25cad40cc28ea8..3507cabc8194869e6bb0a92a78758cddb44271e0 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
@@ -28,6 +28,10 @@
#include "chrome/common/gtk_util.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
+#include "webkit/api/public/WebInputEvent.h"
+
+using WebKit::WebInputEvent;
+using WebKit::WebMouseEvent;
namespace {
@@ -108,7 +112,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
: TabContentsView(tab_contents),
floating_(gtk_floating_container_new()),
fixed_(gtk_fixed_new()),
- popup_view_(NULL) {
+ popup_view_(NULL),
+ outstanding_clipboard_contents_request_(NULL) {
g_signal_connect(fixed_, "size-allocate",
G_CALLBACK(OnSizeAllocate), this);
g_signal_connect(floating_.get(), "set-floating-position",
@@ -123,6 +128,8 @@ TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
TabContentsViewGtk::~TabContentsViewGtk() {
floating_.Destroy();
+ if (outstanding_clipboard_contents_request_)
+ outstanding_clipboard_contents_request_->Cancel();
}
void TabContentsViewGtk::AttachBlockedPopupView(
@@ -323,6 +330,64 @@ void TabContentsViewGtk::HandleKeyboardEvent(
static_cast<GdkModifierType>(event.os_event->state));
}
+TabContentsViewGtk::ClipboardRequestCallback::ClipboardRequestCallback(
+ TabContentsViewGtk* tab_contents_view)
+ : tab_contents_view_(tab_contents_view) {
+}
+
+void TabContentsViewGtk::ClipboardRequestCallback::Cancel() {
+ tab_contents_view_ = NULL;
+}
+
+void TabContentsViewGtk::ClipboardRequestCallback::Callback(
+ const gchar* utf8_string) {
+ if (tab_contents_view_)
+ tab_contents_view_->ClipboardContentsReceived(utf8_string);
+
+ delete this;
+}
+
+static void ClipboardCallback(GtkClipboard *clipboard,
+ const gchar *utf8_string,
+ gpointer arg) {
+ TabContentsViewGtk::ClipboardRequestCallback* callback =
+ reinterpret_cast<TabContentsViewGtk::ClipboardRequestCallback*>(arg);
+ callback->Callback(utf8_string);
+}
+
+void TabContentsViewGtk::HandleMouseButtonEvent(const WebMouseEvent* event) {
+ // We only trigger on middle-button up with Control held down.
+ if (event->type != WebInputEvent::MouseUp ||
+ event->button != WebMouseEvent::ButtonMiddle ||
+ (event->modifiers & WebInputEvent::ControlKey) == 0 ||
+ event->modifiers & WebInputEvent::ShiftKey ||
+ event->modifiers & WebInputEvent::AltKey ||
+ event->modifiers & WebInputEvent::MetaKey ||
+ outstanding_clipboard_contents_request_) {
+ return;
+ }
+
+ outstanding_clipboard_contents_request_ = new ClipboardRequestCallback(this);
+ GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ gtk_clipboard_request_text(x_clipboard, ClipboardCallback,
+ outstanding_clipboard_contents_request_);
+}
+
+void TabContentsViewGtk::ClipboardContentsReceived(const gchar* utf8_contents) {
+ outstanding_clipboard_contents_request_ = NULL;
+ if (!utf8_contents)
+ return;
+
+ GURL target(utf8_contents);
+ if (!target.is_valid())
+ target = GURL(std::string("http://") + utf8_contents);
+ if (!target.is_valid())
+ return;
+
+ tab_contents()->RequestOpenURL(target, GURL() /* referrer */,
+ NEW_FOREGROUND_TAB);
+}
+
void TabContentsViewGtk::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/browser/views/tab_contents/tab_contents_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698