diff options
author | Xan Lopez <xan@gnome.org> | 2009-09-20 05:06:01 +0800 |
---|---|---|
committer | Xan Lopez <xan@gnome.org> | 2009-09-20 05:06:01 +0800 |
commit | 98361f61fcdfc52d2ae2682234778f3e1b384916 (patch) | |
tree | b31f644a5fb16a636cf872408840e4cba971bc86 /src | |
parent | 0fa8e2fb6780e75923da248bb5d94e30d8556dd7 (diff) | |
download | gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.gz gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.bz2 gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.lz gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.xz gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.zst gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.zip |
Bring back epiphany context menu
There's a few items (like email link) and actions (like bookmark link)
missing or not working because of missing information in the
WebKitHitTestResult object, but most of the stuff is working.
For some reason the g-ir-scanner is not picking up the correct type
name for WebKitHitTestResult (it uses WebKitHitTestResult instead of
WebKit.HitTestResult), so the introspection support is broken unless
that error is fixed manually. Looking into that ...
Bug #562617
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ephy-window.c | 103 | ||||
-rw-r--r-- | src/popup-commands.c | 115 |
3 files changed, 119 insertions, 101 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index df99d39f9..1b48bb924 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -282,8 +282,8 @@ MAINTAINERCLEANFILES = $(stamp_files) $(BUILT_SOURCES) if ENABLE_INTROSPECTION EPHY_GIR_H_FILES = \ - $(top_srcdir)/embed/ephy-embed-event.h \ $(top_srcdir)/embed/ephy-embed.h \ + $(top_srcdir)/embed/ephy-embed-event.h \ $(top_srcdir)/embed/ephy-embed-persist.h \ $(top_srcdir)/embed/ephy-embed-shell.h \ $(top_srcdir)/embed/ephy-embed-single.h \ diff --git a/src/ephy-window.c b/src/ephy-window.c index 888d14f89..360eaf110 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -2050,30 +2050,30 @@ embed_popup_deactivate_cb (GtkWidget *popup, } static char * -get_name_from_address_value (const GValue *value) +get_name_from_address_value (const char *path) { char *name; - name = g_path_get_basename (g_value_get_string (value)); + name = g_path_get_basename (path); return name != NULL ? name : g_strdup (""); } static void -update_popups_tooltips (EphyWindow *window, EphyEmbedEvent *event) +update_popups_tooltips (EphyWindow *window, GdkEventButton *event, WebKitHitTestResult *hit_test_result) { - EphyEmbedEventContext context; + guint context; GtkActionGroup *group = window->priv->popups_action_group; - const GValue *value; GtkAction *action; char *tooltip, *name; - context = ephy_embed_event_get_context (event); + g_object_get (hit_test_result, "context", &context, NULL); - if (context & EPHY_EMBED_CONTEXT_IMAGE) + if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) { - value = ephy_embed_event_get_property (event, "image"); - name = get_name_from_address_value (value); + char *uri; + g_object_get (hit_test_result, "image-uri", &uri, NULL); + name = get_name_from_address_value (uri); action = gtk_action_group_get_action (group, "OpenImage"); tooltip = g_strdup_printf (_("Open image “%s”"), name); @@ -2091,14 +2091,15 @@ update_popups_tooltips (EphyWindow *window, EphyEmbedEvent *event) g_free (tooltip); action = gtk_action_group_get_action (group, "CopyImageLocation"); - tooltip = g_strdup_printf (_("Copy image address “%s”"), - g_value_get_string (value)); + tooltip = g_strdup_printf (_("Copy image address “%s”"), uri); g_object_set (action, "tooltip", tooltip, NULL); g_free (tooltip); + g_free (uri); g_free (name); } +#if 0 if (context & EPHY_EMBED_CONTEXT_EMAIL_LINK) { value = ephy_embed_event_get_property (event, "link"); @@ -2115,46 +2116,49 @@ update_popups_tooltips (EphyWindow *window, EphyEmbedEvent *event) g_object_set (action, "tooltip", tooltip, NULL); g_free (tooltip); } +#endif - if (context & EPHY_EMBED_CONTEXT_LINK) + if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { - value = ephy_embed_event_get_property (event, "link"); + char *uri; + g_object_get (hit_test_result, "link-uri", &uri, NULL); action = gtk_action_group_get_action (group, "DownloadLink"); - name = get_name_from_address_value (value); + name = get_name_from_address_value (uri); tooltip = g_strdup_printf (_("Save link “%s”"), name); g_object_set (action, "tooltip", tooltip, NULL); g_free (name); g_free (tooltip); action = gtk_action_group_get_action (group, "BookmarkLink"); - tooltip = g_strdup_printf (_("Bookmark link “%s”"), - g_value_get_string (value)); + tooltip = g_strdup_printf (_("Bookmark link “%s”"), uri); g_object_set (action, "tooltip", tooltip, NULL); g_free (tooltip); action = gtk_action_group_get_action (group, "CopyLinkAddress"); - tooltip = g_strdup_printf (_("Copy link's address “%s”"), - g_value_get_string (value)); + tooltip = g_strdup_printf (_("Copy link's address “%s”"), uri); g_object_set (action, "tooltip", tooltip, NULL); g_free (tooltip); + g_free (uri); } } static void show_embed_popup (EphyWindow *window, - EphyEmbed *embed, - EphyEmbedEvent *event) + WebKitWebView *view, + GdkEventButton *event, + WebKitHitTestResult *hit_test_result) { EphyWindowPrivate *priv = window->priv; GtkActionGroup *action_group; GtkAction *action; - EphyEmbedEventContext context; + guint context; const char *popup; - const GValue *value; - gboolean framed, can_open_in_new; + gboolean framed = FALSE, can_open_in_new; GtkWidget *widget; guint button; + char *uri; + EphyEmbedEvent *embed_event; /* Do not show the menu in print preview mode */ if (priv->ppv_mode) @@ -2162,26 +2166,32 @@ show_embed_popup (EphyWindow *window, return; } +#if 0 value = ephy_embed_event_get_property (event, "framed_page"); framed = g_value_get_int (value); +#endif - can_open_in_new = ephy_embed_event_has_property (event, "link-has-web-scheme"); + g_object_get (hit_test_result, "link-uri", &uri, NULL); + can_open_in_new = uri && ephy_embed_utils_address_has_web_scheme (uri); + g_free (uri); - context = ephy_embed_event_get_context (event); + g_object_get (hit_test_result, "context", &context, NULL); LOG ("show_embed_popup context %x", context); +#if 0 if (context & EPHY_EMBED_CONTEXT_EMAIL_LINK) { popup = "/EphyEmailLinkPopup"; update_edit_actions_sensitivity (window, TRUE); } - else if (context & EPHY_EMBED_CONTEXT_LINK) +#endif + if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { popup = "/EphyLinkPopup"; update_edit_actions_sensitivity (window, TRUE); } - else if (context & EPHY_EMBED_CONTEXT_INPUT) + else if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE) { popup = "/EphyInputPopup"; update_edit_actions_sensitivity (window, FALSE); @@ -2192,7 +2202,7 @@ show_embed_popup (EphyWindow *window, update_edit_actions_sensitivity (window, TRUE); } - update_popups_tooltips (window, event); + update_popups_tooltips (window, event, hit_test_result); widget = gtk_ui_manager_get_widget (priv->manager, popup); g_return_if_fail (widget != NULL); @@ -2207,15 +2217,17 @@ show_embed_popup (EphyWindow *window, update_popup_actions_visibility (window, - context & EPHY_EMBED_CONTEXT_IMAGE, + context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE, framed); - _ephy_window_set_context_event (window, event); + embed_event = ephy_embed_event_new (event, hit_test_result); + _ephy_window_set_context_event (window, embed_event); + g_object_unref (embed_event); g_signal_connect (widget, "deactivate", G_CALLBACK (embed_popup_deactivate_cb), window); - button = ephy_embed_event_get_button (event); + button = event->button; if (button == 0) { @@ -2232,22 +2244,6 @@ show_embed_popup (EphyWindow *window, } } -static gboolean -tab_context_menu_cb (EphyWebView *view, - EphyEmbedEvent *event, - EphyWindow *window) -{ - EphyEmbed *embed; - - g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), FALSE); - embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view); - g_return_val_if_fail (window->priv->active_embed == embed, FALSE); - - show_embed_popup (window, embed, event); - - return TRUE; -} - #if 0 static gboolean save_property_url (EphyEmbed *embed, @@ -2321,6 +2317,14 @@ ephy_window_dom_mouse_click_cb (WebKitWebView *view, hit_test_result = webkit_web_view_get_hit_test_result (view, event); button = event->button; + + if (event->button == 3) + { + show_embed_popup (window, view, event, hit_test_result); + g_object_unref (hit_test_result); + return TRUE; + } + modifier = event->state; g_object_get (hit_test_result, "context", &context, NULL); g_object_unref (hit_test_result); @@ -2731,8 +2735,6 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed) window); g_signal_handlers_disconnect_by_func - (view, G_CALLBACK (tab_context_menu_cb), window); - g_signal_handlers_disconnect_by_func (view, G_CALLBACK (ephy_window_dom_mouse_click_cb), window); } @@ -2816,9 +2818,6 @@ ephy_window_set_active_tab (EphyWindow *window, EphyEmbed *new_embed) g_signal_connect_object (view, "notify::navigation", G_CALLBACK (sync_tab_navigation), window, 0); - g_signal_connect_object (view, "ge-context-menu", - G_CALLBACK (tab_context_menu_cb), - window, G_CONNECT_AFTER); g_signal_connect_object (view, "notify::progress", G_CALLBACK (sync_tab_load_progress), window, 0); diff --git a/src/popup-commands.c b/src/popup-commands.c index 282020818..cbaf1e46b 100644 --- a/src/popup-commands.c +++ b/src/popup-commands.c @@ -34,6 +34,7 @@ #include <string.h> #include <glib/gi18n.h> #include <gtk/gtk.h> +#include <webkit/webkit.h> void popup_cmd_link_in_new_window (GtkAction *action, @@ -41,7 +42,7 @@ popup_cmd_link_in_new_window (GtkAction *action, { EphyEmbedEvent *event; EphyEmbed *embed; - const GValue *value; + GValue value = { 0, }; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); @@ -49,12 +50,13 @@ popup_cmd_link_in_new_window (GtkAction *action, event = ephy_window_get_context_event (window); g_return_if_fail (event != NULL); - value = ephy_embed_event_get_property (event, "link"); + ephy_embed_event_get_property (event, "link-uri", &value); ephy_shell_new_tab (ephy_shell, NULL, embed, - g_value_get_string (value), + g_value_get_string (&value), EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_IN_NEW_WINDOW); + g_value_unset (&value); } void @@ -63,7 +65,7 @@ popup_cmd_link_in_new_tab (GtkAction *action, { EphyEmbedEvent *event; EphyEmbed *embed; - const GValue *value; + GValue value = { 0, }; embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); @@ -71,12 +73,13 @@ popup_cmd_link_in_new_tab (GtkAction *action, event = ephy_window_get_context_event (window); g_return_if_fail (event != NULL); - value = ephy_embed_event_get_property (event, "link"); + ephy_embed_event_get_property (event, "link-uri", &value); ephy_shell_new_tab (ephy_shell, window, embed, - g_value_get_string (value), + g_value_get_string (&value), EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_IN_EXISTING_WINDOW); + g_value_unset (&value); } void @@ -84,11 +87,11 @@ popup_cmd_bookmark_link (GtkAction *action, EphyWindow *window) { EphyEmbedEvent *event; - const GValue *link_title; - const GValue *link_rel; - const GValue *link; - const GValue *link_is_smart; - const GValue *linktext; + GValue link_title = { 0, }; + GValue link_rel = { 0, }; + GValue link = { 0, }; + GValue link_is_smart = { 0, }; + GValue linktext = { 0, }; const char *title; const char *location; const char *rel; @@ -97,23 +100,24 @@ popup_cmd_bookmark_link (GtkAction *action, event = ephy_window_get_context_event (window); g_return_if_fail (event != NULL); - link_is_smart = ephy_embed_event_get_property (event, "link_is_smart"); - link = ephy_embed_event_get_property (event, "link"); - link_title = ephy_embed_event_get_property (event, "link_title"); - link_rel = ephy_embed_event_get_property (event, "link_rel"); - linktext = ephy_embed_event_get_property (event, "linktext"); + /* FIXME: this is pretty much broken */ + ephy_embed_event_get_property (event, "link_is_smart", &link_is_smart); + ephy_embed_event_get_property (event, "link-uri", &link); + ephy_embed_event_get_property (event, "link_title", &link_title); + ephy_embed_event_get_property (event, "link_rel", &link_rel); + ephy_embed_event_get_property (event, "linktext", &linktext); - location = g_value_get_string (link); + location = g_value_get_string (&link); g_return_if_fail (location); - rel = g_value_get_string (link_rel); - is_smart = g_value_get_int (link_is_smart); + rel = g_value_get_string (&link_rel); + is_smart = g_value_get_int (&link_is_smart); - title = g_value_get_string (link_title); + title = g_value_get_string (&link_title); if (title == NULL || title[0] == '\0') { - title = g_value_get_string (linktext); + title = g_value_get_string (&linktext); } if (title == NULL || title[0] == '\0') @@ -127,6 +131,11 @@ popup_cmd_bookmark_link (GtkAction *action, } ephy_bookmarks_ui_add_bookmark (GTK_WINDOW (window), location, title); + g_value_unset (&link); + g_value_unset (&link_rel); + g_value_unset (&linktext); + g_value_unset (&link_title); + g_value_unset (&link_is_smart); } static void @@ -143,26 +152,30 @@ popup_cmd_copy_link_address (GtkAction *action, EphyWindow *window) { EphyEmbedEvent *event; - EphyEmbedEventContext context; + guint context; const char *address; - const GValue *value; + GValue value = { 0, }; event = ephy_window_get_context_event (window); g_return_if_fail (event != NULL); context = ephy_embed_event_get_context (event); +#if 0 if (context & EPHY_EMBED_CONTEXT_EMAIL_LINK) { value = ephy_embed_event_get_property (event, "email"); - address = g_value_get_string (value); + address = g_value_get_string (&value); popup_cmd_copy_to_clipboard (window, address); } - else if (context & EPHY_EMBED_CONTEXT_LINK) +#endif + + if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { - value = ephy_embed_event_get_property (event, "link"); - address = g_value_get_string (value); + ephy_embed_event_get_property (event, "link-uri", &value); + address = g_value_get_string (&value); popup_cmd_copy_to_clipboard (window, address); + g_value_unset (&value); } } @@ -200,7 +213,7 @@ save_property_url (GtkAction *action, { EphyEmbedEvent *event; const char *location; - const GValue *value; + GValue value = { 0, }; EphyEmbedPersist *persist; EphyEmbed *embed; @@ -210,8 +223,8 @@ save_property_url (GtkAction *action, embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - value = ephy_embed_event_get_property (event, property); - location = g_value_get_string (value); + ephy_embed_event_get_property (event, property, &value); + location = g_value_get_string (&value); persist = EPHY_EMBED_PERSIST (g_object_new (EPHY_TYPE_EMBED_PERSIST, NULL)); @@ -230,7 +243,8 @@ save_property_url (GtkAction *action, ephy_embed_persist_save (persist); - g_object_unref (G_OBJECT(persist)); + g_object_unref (G_OBJECT (persist)); + g_value_unset (&value); } void @@ -239,7 +253,7 @@ popup_cmd_open_link (GtkAction *action, { EphyEmbedEvent *event; const char *location; - const GValue *value; + GValue value = { 0, }; EphyEmbed *embed; embed = ephy_embed_container_get_active_child @@ -247,9 +261,10 @@ popup_cmd_open_link (GtkAction *action, g_return_if_fail (embed != NULL); event = ephy_window_get_context_event (window); - value = ephy_embed_event_get_property (event, "link"); - location = g_value_get_string (value); + ephy_embed_event_get_property (event, "link-uri", &value); + location = g_value_get_string (&value); ephy_web_view_load_url (EPHY_WEB_VIEW (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed)), location); + g_value_unset (&value); } void @@ -257,7 +272,7 @@ popup_cmd_download_link (GtkAction *action, EphyWindow *window) { save_property_url (action, _("Download Link"), window, - FALSE, "link"); + FALSE, "link-uri"); } void @@ -265,14 +280,14 @@ popup_cmd_download_link_as (GtkAction *action, EphyWindow *window) { save_property_url (action, _("Save Link As"), window, - TRUE, "link"); + TRUE, "link-uri"); } void popup_cmd_save_image_as (GtkAction *action, EphyWindow *window) { save_property_url (action, _("Save Image As"), - window, TRUE, "image"); + window, TRUE, "image-uri"); } #define GNOME_APPEARANCE_PROPERTIES "gnome-appearance-properties.desktop" @@ -311,7 +326,7 @@ popup_cmd_set_image_as_background (GtkAction *action, EphyEmbedEvent *event; const char *location; char *dest, *base, *base_converted; - const GValue *value; + GValue value = { 0, }; EphyEmbedPersist *persist; EphyEmbed *embed; @@ -321,8 +336,8 @@ popup_cmd_set_image_as_background (GtkAction *action, embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - value = ephy_embed_event_get_property (event, "image"); - location = g_value_get_string (value); + ephy_embed_event_get_property (event, "image-uri", &value); + location = g_value_get_string (&value); persist = EPHY_EMBED_PERSIST (g_object_new (EPHY_TYPE_EMBED_PERSIST, NULL)); @@ -342,6 +357,7 @@ popup_cmd_set_image_as_background (GtkAction *action, ephy_embed_persist_save (persist); + g_value_unset (&value); g_free (dest); g_free (base); g_free (base_converted); @@ -353,12 +369,13 @@ popup_cmd_copy_image_location (GtkAction *action, { EphyEmbedEvent *event; const char *location; - const GValue *value; + GValue value = { 0, }; event = ephy_window_get_context_event (window); - value = ephy_embed_event_get_property (event, "image"); - location = g_value_get_string (value); + ephy_embed_event_get_property (event, "image-uri", &value); + location = g_value_get_string (&value); popup_cmd_copy_to_clipboard (window, location); + g_value_unset (&value); } void @@ -469,8 +486,8 @@ popup_cmd_open_image (GtkAction *action, { EphyEmbedEvent *event; const char *address; - char *scheme; - const GValue *value; + char *scheme = NULL; + GValue value = { 0, }; EphyEmbed *embed; event = ephy_window_get_context_event (window); @@ -480,11 +497,11 @@ popup_cmd_open_image (GtkAction *action, (EPHY_EMBED_CONTAINER (window)); g_return_if_fail (embed != NULL); - value = ephy_embed_event_get_property (event, "image"); - address = g_value_get_string (value); + ephy_embed_event_get_property (event, "image-uri", &value); + address = g_value_get_string (&value); scheme = g_uri_parse_scheme (address); - if (scheme == NULL) return; + if (scheme == NULL) goto out; if (strcmp (scheme, "file") == 0) { @@ -500,5 +517,7 @@ popup_cmd_open_image (GtkAction *action, save_temp_source (address); } + out: + g_value_unset (&value); g_free (scheme); } |