From 847f18f6438d8fbdc039e7162fd01c5cb1027642 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Tue, 13 Oct 2009 22:58:50 +0200 Subject: [PATCH] Implement tap and hold with emulated motion and button click events There is no pointer movement on a touchscreen, so we need to pretend there is, to trigger a proper context menu. --- midori/midori-view.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/midori/midori-view.c b/midori/midori-view.c index f87e4440..eb3d4bd0 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -1959,6 +1959,34 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view, gtk_widget_show_all (menu); } +#if HAVE_HILDON +static void +midori_view_web_view_tap_and_hold_cb (GtkWidget* web_view, + MidoriView* view) +{ + gint x, y; + GdkEvent event; + gboolean result; + + /* Emulate a pointer motion above the tap position + and a right click at the according position. */ + gdk_window_get_pointer (web_view->window, &x, &y, NULL); + event.any.type = GDK_MOTION_NOTIFY; + event.any.window = web_view->window; + event.motion.x = x; + event.motion.y = y; + g_signal_emit_by_name (web_view, "motion-notify-event", &event, &result); + + event.any.type = GDK_BUTTON_PRESS; + event.any.window = web_view->window; + event.button.axes = NULL; + event.button.x = x; + event.button.y = y; + event.button.button = 3; + g_signal_emit_by_name (web_view, "button-press-event", &event, &result); +} +#endif + static gboolean webkit_web_view_web_view_ready_cb (GtkWidget* web_view, MidoriView* view) @@ -2634,6 +2662,10 @@ midori_view_construct_web_view (MidoriView* view) webkit_web_view_open (WEBKIT_WEB_VIEW (view->web_view), ""); web_frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view)); + #if HAVE_HILDON + gtk_widget_tap_and_hold_setup (view->web_view, NULL, NULL, 0); + #endif + g_object_connect (view->web_view, "signal::navigation-policy-decision-requested", midori_view_web_view_navigation_decision_cb, view, @@ -2668,6 +2700,10 @@ midori_view_construct_web_view (MidoriView* view) gtk_widget_scroll_event_cb, view, "signal::populate-popup", webkit_web_view_populate_popup_cb, view, + #if HAVE_HILDON + "signal::tap-and-hold", + midori_view_web_view_tap_and_hold_cb, view, + #endif "signal::console-message", webkit_web_view_console_message_cb, view, "signal::window-object-cleared",