aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-window.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-07-04 20:42:34 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-10-11 18:33:33 +0800
commit45cadd35c88699e4483f7934aaad7b2ddc0aa3c8 (patch)
treef7c1c4147094663627ba1197961a34b52b0e2f89 /src/ephy-window.c
parentb9a8bb2e69f67085a524733c8a73cf127bfd9dc6 (diff)
downloadgsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar.gz
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar.bz2
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar.lz
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar.xz
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.tar.zst
gsoc2013-epiphany-45cadd35c88699e4483f7934aaad7b2ddc0aa3c8.zip
ephy-window: Simplify ephy_window_dom_mouse_click_cb
Factor out every button press handler into its own function. https://bugzilla.gnome.org/show_bug.cgi?id=679394
Diffstat (limited to 'src/ephy-window.c')
-rw-r--r--src/ephy-window.c199
1 files changed, 101 insertions, 98 deletions
diff --git a/src/ephy-window.c b/src/ephy-window.c
index bbd05f35b..2295aa622 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2095,28 +2095,52 @@ show_embed_popup (EphyWindow *window,
#endif
static gboolean
-save_property_url (EphyEmbed *embed,
- GdkEventButton *gdk_event,
- WebKitHitTestResult *hit_test_result,
- const char *property)
+save_target_uri (EphyWindow *window,
+ WebKitWebView *view,
+ GdkEventButton *event,
+ WebKitHitTestResult *hit_test_result)
{
- const char *location;
- GValue value = { 0, };
- EphyEmbedEvent *event = ephy_embed_event_new (gdk_event, hit_test_result);
- gboolean retval;
+ guint context;
+ char *location = NULL;
+ gboolean retval = FALSE;
- ephy_embed_event_get_property (event, property, &value);
- location = g_value_get_string (&value);
+ if ((event->state & GDK_SHIFT_MASK) != GDK_SHIFT_MASK)
+ {
+ return FALSE;
+ }
+
+ g_object_get (hit_test_result, "context", &context, NULL);
+
+ LOG ("ephy_window_dom_mouse_click_cb: button %d, context %d, modifier %d (%d:%d)",
+ event->button, context, event->state, (int)event->x, (int)event->y);
- LOG ("Location: %s", location);
+ /* shift+click saves the link target */
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
+ {
+ g_object_get (G_OBJECT (hit_test_result), "link-uri", &location, NULL);
+ }
+ /* Note: pressing enter to submit a form synthesizes a mouse
+ * click event
+ */
+ /* shift+click saves the non-link image */
+ else if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE &&
+ !(context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE))
+ {
+ g_object_get (G_OBJECT (hit_test_result), "image-uri", &location, NULL);
+ }
- retval = ephy_embed_utils_address_has_web_scheme (location);
+ if (!location)
+ {
+ LOG ("Location: %s", location);
- if (retval)
- ephy_embed_auto_download_url (embed, location);
+ retval = ephy_embed_utils_address_has_web_scheme (location);
+ if (retval)
+ {
+ ephy_embed_auto_download_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), location);
+ }
- g_value_unset (&value);
- g_object_unref (event);
+ g_free (location);
+ }
return retval;
}
@@ -2147,108 +2171,87 @@ clipboard_text_received_cb (GtkClipboard *clipboard,
}
static gboolean
-ephy_window_dom_mouse_click_cb (WebKitWebView *view,
- GdkEventButton *event,
- EphyWindow *window)
+open_selected_url (EphyWindow *window,
+ WebKitWebView *view,
+ GdkEventButton *event,
+ WebKitHitTestResult *hit_test_result)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Button press actions */
- return FALSE;
-#else
- guint button, modifier, context;
- gboolean handled = FALSE;
- gboolean with_control, with_shift;
- gboolean is_left_click, is_middle_click;
- gboolean is_link, is_image, is_middle_clickable;
- gboolean middle_click_opens;
- gboolean is_input;
- WebKitHitTestResult *hit_test_result;
-
- hit_test_result = webkit_web_view_get_hit_test_result (view, event);
- button = event->button;
+ guint context;
+ ClipboardTextCBData *cb_data;
+ EphyEmbed *embed;
+ EphyEmbed **embed_ptr;
- if (button == 3)
+ if (!g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_MIDDLE_CLICK_OPENS_URL) ||
+ g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN, EPHY_PREFS_LOCKDOWN_ARBITRARY_URL))
{
- show_embed_popup (window, view, event, hit_test_result);
- g_object_unref (hit_test_result);
- return TRUE;
+ return FALSE;
}
- modifier = event->state;
g_object_get (hit_test_result, "context", &context, NULL);
LOG ("ephy_window_dom_mouse_click_cb: button %d, context %d, modifier %d (%d:%d)",
- button, context, modifier, (int)event->x, (int)event->y);
-
- with_control = (modifier & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
- with_shift = (modifier & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
+ event->button, context, event->state, (int)event->x, (int)event->y);
- is_left_click = (button == 1);
- is_middle_click = (button == 2);
-
- middle_click_opens =
- g_settings_get_boolean (EPHY_SETTINGS_MAIN,
- EPHY_PREFS_MIDDLE_CLICK_OPENS_URL) &&
- !g_settings_get_boolean
- (EPHY_SETTINGS_LOCKDOWN,
- EPHY_PREFS_LOCKDOWN_ARBITRARY_URL);
-
- is_link = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) != 0;
- is_image = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) != 0;
- is_middle_clickable = !((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK)
- || (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE));
- is_input = (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) != 0;
-
- if (is_left_click && with_shift && !with_control)
+ if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK ||
+ context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE)
{
- /* shift+click saves the link target */
- if (is_link)
- {
- handled = save_property_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), event, hit_test_result, "link-uri");
- }
-
- /* Note: pressing enter to submit a form synthesizes a mouse
- * click event
- */
- /* shift+click saves the non-link image */
- else if (is_image && !is_input)
- {
- handled = save_property_url (EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view), event, hit_test_result, "image-uri");
- }
+ return FALSE;
}
- /* middle click opens the selection url */
- if (is_middle_clickable && is_middle_click && middle_click_opens)
- {
- /* See bug #133633 for why we do it this way */
+ /* See bug #133633 for why we do it this way */
- /* We need to make sure we know if the embed is destroyed
- * between requesting the clipboard contents, and receiving
- * them.
- */
- ClipboardTextCBData *cb_data;
- EphyEmbed *embed;
- EphyEmbed **embed_ptr;
+ /* We need to make sure we know if the embed is destroyed
+ * between requesting the clipboard contents, and receiving
+ * them.
+ */
+ embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view);
- embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view);
+ cb_data = g_slice_new0 (ClipboardTextCBData);
+ cb_data->embed = embed;
+ cb_data->window = window;
+ embed_ptr = &cb_data->embed;
- cb_data = g_slice_new0 (ClipboardTextCBData);
- cb_data->embed = embed;
- cb_data->window = window;
- embed_ptr = &cb_data->embed;
-
- g_object_add_weak_pointer (G_OBJECT (embed), (gpointer *) embed_ptr);
+ g_object_add_weak_pointer (G_OBJECT (embed), (gpointer *) embed_ptr);
+
+ gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (embed),
+ GDK_SELECTION_PRIMARY),
+ (GtkClipboardTextReceivedFunc) clipboard_text_received_cb,
+ cb_data);
+ return TRUE;
+}
+
+static gboolean
+ephy_window_dom_mouse_click_cb (WebKitWebView *view,
+ GdkEventButton *event,
+ EphyWindow *window)
+{
+#ifdef HAVE_WEBKIT2
+ /* TODO: Button press actions */
+ return FALSE;
+#else
+ WebKitHitTestResult *hit_test_result;
+ gboolean handled = FALSE;
- gtk_clipboard_request_text
- (gtk_widget_get_clipboard (GTK_WIDGET (embed),
- GDK_SELECTION_PRIMARY),
- (GtkClipboardTextReceivedFunc) clipboard_text_received_cb,
- cb_data);
+ hit_test_result = webkit_web_view_get_hit_test_result (view, event);
- handled = TRUE;
+ switch (event->button)
+ {
+ case GDK_BUTTON_PRIMARY:
+ handled = save_target_uri (window, view, event, hit_test_result);
+ break;
+ case GDK_BUTTON_MIDDLE:
+ handled = open_selected_url (window, view, event, hit_test_result);
+ break;
+ case GDK_BUTTON_SECONDARY:
+ show_embed_popup (window, view, event, hit_test_result);
+ handled = TRUE;
+ break;
+ default:
+ break;
}
g_object_unref (hit_test_result);
+
return handled;
#endif
}