diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tab-body.c | 54 | ||||
-rw-r--r-- | src/tab-body.h | 1 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/tab-body.c b/src/tab-body.c index 58f3eea..6bf95b1 100644 --- a/src/tab-body.c +++ b/src/tab-body.c @@ -418,6 +418,56 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view, return FALSE; } +static void +clipboard_text_recv_cb(GtkClipboard *clipboard, const gchar *text, + MqTabBody *body) +{ + webkit_web_view_load_uri(body->web_view, text); +} + +/* This callback is a hack to determine on middle mouse click whether to open a + * link in a new tab or to load a URI from the primary clipboard. The WebKit1 + * API provided webkit_web_view_get_hit_test_result() which would have been + * easier. */ +static void +mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view, + WebKitHitTestResult *hit_test_result, + guint __attribute__((unused)) modifiers, + MqTabBody *body) +{ + body->mouse_target_hit_test_result = hit_test_result; + g_object_ref(body->mouse_target_hit_test_result); +} + +static gboolean +button_press_cb(WebKitWebView *web_view, GdkEvent *event, MqTabBody *body) +{ + WebKitHitTestResult *hit_test_result; + GtkClipboard *clipboard; + + /* Make sure this is a middle mouse button press event. */ + if (event->type != GDK_BUTTON_PRESS || event->button.button != 2) { + return FALSE; + } + + hit_test_result = body->mouse_target_hit_test_result; + + if (webkit_hit_test_result_context_is_link(hit_test_result)) { + mq_tab_new_relative( + webkit_hit_test_result_get_link_uri(hit_test_result), + body->tab); + } else { + clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_request_text(clipboard, + (GtkClipboardTextReceivedFunc) clipboard_text_recv_cb, + body); + } + + g_object_unref(hit_test_result); + + return TRUE; +} + MqTabBody * mq_tab_body_new(MqTab *tab, const gchar *uri) { @@ -439,6 +489,10 @@ mq_tab_body_new(MqTab *tab, const gchar *uri) body->hit_test_result = NULL; g_signal_connect(body->web_view, "context-menu", G_CALLBACK(context_menu_cb), body); + g_signal_connect(body->web_view, "mouse-target-changed", + G_CALLBACK(mouse_target_changed_cb), body); + g_signal_connect(body->web_view, "button-press-event", + G_CALLBACK(button_press_cb), body); return body; } diff --git a/src/tab-body.h b/src/tab-body.h index 1e3b3f9..0b75b4c 100644 --- a/src/tab-body.h +++ b/src/tab-body.h @@ -34,6 +34,7 @@ struct MqTabBody { GtkWidget *container; WebKitWebView *web_view; WebKitHitTestResult *hit_test_result; + WebKitHitTestResult *mouse_target_hit_test_result; }; MqTabBody * |