From 086140d4b7d8835f4b2928b515a4e3c783b81a50 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Sun, 21 Dec 2008 15:54:49 +0000 Subject: Open links in new tab with middle click. Bug #518338 svn path=/trunk/; revision=8639 --- src/ephy-window.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/ephy-window.c') diff --git a/src/ephy-window.c b/src/ephy-window.c index 98696ad09..5587f9248 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -2481,6 +2481,42 @@ create_web_view_cb (WebKitWebView *web_view, return new_web_view; } +static gboolean +navigation_policy_decision_required_cb (WebKitWebView *web_view, + WebKitWebFrame *web_frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *action, + WebKitWebPolicyDecision *decision, + EphyWindow *window) +{ + WebKitWebNavigationReason reason; + gint button; + + reason = webkit_web_navigation_action_get_reason (action); + button = webkit_web_navigation_action_get_button (action); + + if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED && + button == 2 /* middle button */) { + const char *uri; + EphyEmbed *embed; + + uri = webkit_network_request_get_uri (request); + embed = ephy_embed_container_get_active_child + (EPHY_EMBED_CONTAINER (window)); + + ephy_shell_new_tab (ephy_shell_get_default (), + window, + embed, + uri, + EPHY_NEW_TAB_IN_EXISTING_WINDOW | + EPHY_NEW_TAB_OPEN_PAGE); + + return TRUE; + } + + return FALSE; +} + static void ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed) { @@ -2510,6 +2546,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed) g_signal_handlers_disconnect_by_func (web_view, G_CALLBACK (create_web_view_cb), window); + g_signal_handlers_disconnect_by_func (web_view, + G_CALLBACK (navigation_policy_decision_required_cb), + window); g_signal_handlers_disconnect_by_func (embed, G_CALLBACK (sync_tab_popup_windows), @@ -2594,6 +2633,9 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed) g_signal_connect_object (web_view, "create-web-view", G_CALLBACK (create_web_view_cb), window, 0); + g_signal_connect_object (web_view, "navigation-policy-decision-requested", + G_CALLBACK (navigation_policy_decision_required_cb), + window, 0); g_signal_connect_object (embed, "notify::hidden-popup-count", G_CALLBACK (sync_tab_popup_windows), -- cgit v1.2.3