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 | |
parent | 0fa8e2fb6780e75923da248bb5d94e30d8556dd7 (diff) | |
download | gsoc2013-epiphany-98361f61fcdfc52d2ae2682234778f3e1b384916.tar.gz 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
-rw-r--r-- | embed/ephy-embed-event.c | 165 | ||||
-rw-r--r-- | embed/ephy-embed-event.h | 88 | ||||
-rw-r--r-- | embed/ephy-web-view.c | 19 | ||||
-rw-r--r-- | embed/ephy-web-view.h | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ephy-window.c | 103 | ||||
-rw-r--r-- | src/popup-commands.c | 115 |
7 files changed, 269 insertions, 225 deletions
diff --git a/embed/ephy-embed-event.c b/embed/ephy-embed-event.c index 352215ae2..c217e6951 100644 --- a/embed/ephy-embed-event.c +++ b/embed/ephy-embed-event.c @@ -1,5 +1,7 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * Copyright © 2000-2003 Marco Pesenti Gritti + * Copyright © 2009 Igalia S.L. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,87 +27,152 @@ #include <glib.h> #include <gtk/gtk.h> -static void ephy_embed_event_base_init (gpointer g_class); +#define EPHY_EMBED_EVENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_EVENT, EphyEmbedEventPrivate)) -GType -ephy_embed_event_get_type (void) +struct EphyEmbedEventPrivate { - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - const GTypeInfo our_info = - { - sizeof (EphyEmbedEventIface), - ephy_embed_event_base_init, - NULL, - }; - - type = g_type_register_static (G_TYPE_INTERFACE, - "EphyEmbedEvent", - &our_info, - (GTypeFlags) 0); - } - - return type; + guint button; + guint modifier; + guint x; + guint y; + WebKitHitTestResult *hit_test_result; +}; + +G_DEFINE_TYPE (EphyEmbedEvent, ephy_embed_event, G_TYPE_OBJECT) + +static void +dispose (GObject *object) +{ + EphyEmbedEventPrivate *priv = EPHY_EMBED_EVENT (object)->priv; + + if (priv->hit_test_result) { + g_object_unref (priv->hit_test_result); + priv->hit_test_result = NULL; + } + + G_OBJECT_CLASS (ephy_embed_event_parent_class)->dispose (object); } static void -ephy_embed_event_base_init (gpointer g_class) +ephy_embed_event_class_init (EphyEmbedEventClass *klass) { - static gboolean initialised = FALSE; + GObjectClass *object_class = (GObjectClass *)klass; + + object_class->dispose = dispose; - initialised = TRUE; + g_type_class_add_private (G_OBJECT_CLASS (klass), sizeof(EphyEmbedEventPrivate)); } -EphyEmbedEventContext +static void +ephy_embed_event_init (EphyEmbedEvent *embed_event) +{ + embed_event->priv = EPHY_EMBED_EVENT_GET_PRIVATE (embed_event); +} + +EphyEmbedEvent * +ephy_embed_event_new (GdkEventButton *event, WebKitHitTestResult *hit_test_result) +{ + EphyEmbedEvent *embed_event; + EphyEmbedEventPrivate *priv; + + embed_event = g_object_new (EPHY_TYPE_EMBED_EVENT, NULL); + priv = embed_event->priv; + + priv->hit_test_result = g_object_ref (hit_test_result); + priv->button = event->button; + priv->modifier = event->state; + priv->x = event->x; + priv->y = event->y; + + return embed_event; +} + +guint ephy_embed_event_get_context (EphyEmbedEvent *event) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->get_context (event); + EphyEmbedEventPrivate *priv; + guint context; + + g_return_val_if_fail (EPHY_IS_EMBED_EVENT (event), 0); + + priv = event->priv; + g_object_get (priv->hit_test_result, "context", &context, NULL); + return context; } guint ephy_embed_event_get_button (EphyEmbedEvent *event) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->get_button (event); + EphyEmbedEventPrivate *priv; + + g_return_val_if_fail (EPHY_IS_EMBED_EVENT (event), 0); + + priv = event->priv; + + return priv->button; } guint ephy_embed_event_get_modifier (EphyEmbedEvent *event) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->get_modifier (event); + EphyEmbedEventPrivate *priv; + + g_return_val_if_fail (EPHY_IS_EMBED_EVENT (event), 0); + + priv = event->priv; + + return priv->modifier; } void ephy_embed_event_get_coords (EphyEmbedEvent *event, - guint *x, guint *y) + guint *x, guint *y) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - iface->get_coordinates (event, x, y); + EphyEmbedEventPrivate *priv; + + g_return_if_fail (EPHY_IS_EMBED_EVENT (event)); + + priv = event->priv; + + if (x) + *x = priv->x; + + if (y) + *y = priv->y; } -const GValue* -ephy_embed_event_get_property (EphyEmbedEvent *event, - const char *name) +void +ephy_embed_event_get_property (EphyEmbedEvent *event, + const char *name, + GValue *value) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->get_property (event, name); + EphyEmbedEventPrivate *priv; + + g_return_if_fail (EPHY_IS_EMBED_EVENT (event)); + g_return_if_fail (name); + + priv = event->priv; + + /* FIXME: ugly hack! This only works for now because all properties + we have are strings */ + g_value_init (value, G_TYPE_STRING); + + g_object_get_property (G_OBJECT (priv->hit_test_result), name, value); } gboolean -ephy_embed_event_has_property (EphyEmbedEvent *event, - const char *name) +ephy_embed_event_has_property (EphyEmbedEvent *event, + const char *name) { - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->has_property (event, name); -} + EphyEmbedEventPrivate *priv; -gpointer -ephy_embed_event_get_dom_event (EphyEmbedEvent *event) -{ - EphyEmbedEventIface *iface = EPHY_EMBED_EVENT_GET_IFACE (event); - return iface->get_dom_event (event); + g_return_val_if_fail (EPHY_IS_EMBED_EVENT (event), FALSE); + g_return_val_if_fail (name, FALSE); + + priv = event->priv; + + return g_object_class_find_property (G_OBJECT_GET_CLASS (priv->hit_test_result), + name) != NULL; + } + diff --git a/embed/ephy-embed-event.h b/embed/ephy-embed-event.h index 0c7d9aa8c..6347be957 100644 --- a/embed/ephy-embed-event.h +++ b/embed/ephy-embed-event.h @@ -1,6 +1,8 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * Copyright © 2000-2003 Marco Pesenti Gritti * Copyright © 2004 Christian Persch + * Copyright © 2009 Igalia S.L. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,71 +29,47 @@ #include <glib-object.h> #include <glib.h> +#include <webkit/webkit.h> G_BEGIN_DECLS -#define EPHY_TYPE_EMBED_EVENT (ephy_embed_event_get_type ()) -#define EPHY_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_EMBED_EVENT, EphyEmbedEvent)) -#define EPHY_EMBED_EVENT_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_EMBED_EVENT, EphyEmbedEventIface)) -#define EPHY_IS_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_EMBED_EVENT)) -#define EPHY_IS_EMBED_EVENT_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_EMBED_EVENT)) -#define EPHY_EMBED_EVENT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EPHY_TYPE_EMBED_EVENT, EphyEmbedEventIface)) +#define EPHY_TYPE_EMBED_EVENT (ephy_embed_event_get_type ()) +#define EPHY_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_EMBED_EVENT, EphyEmbedEvent)) +#define EPHY_EMBED_EVENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EPHY_TYPE_EMBED_EVENT, EphyEmbedEventClass)) +#define EPHY_IS_EMBED_EVENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_EMBED_EVENT)) +#define EPHY_IS_EMBED_EVENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_EMBED_EVENT)) +#define EPHY_EMBED_EVENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_EMBED_EVENT, EphyEmbedEventClass)) -typedef struct _EphyEmbedEventIface EphyEmbedEventIface; -typedef struct _EphyEmbedEvent EphyEmbedEvent; +typedef struct EphyEmbedEventClass EphyEmbedEventClass; +typedef struct EphyEmbedEvent EphyEmbedEvent; +typedef struct EphyEmbedEventPrivate EphyEmbedEventPrivate; -typedef enum -{ - EPHY_EMBED_CONTEXT_NONE = 0, - EPHY_EMBED_CONTEXT_DEFAULT = 1 << 1, - EPHY_EMBED_CONTEXT_LINK = 1 << 2, - EPHY_EMBED_CONTEXT_IMAGE = 1 << 3, - EPHY_EMBED_CONTEXT_DOCUMENT = 1 << 4, - EPHY_EMBED_CONTEXT_INPUT = 1 << 5, - EPHY_EMBED_CONTEXT_INPUT_PASSWORD = 1 << 6, - EPHY_EMBED_CONTEXT_XUL = 1 << 7, - EPHY_EMBED_CONTEXT_EMAIL_LINK = 1 << 8 -} EphyEmbedEventContext; +struct EphyEmbedEvent { + GObject parent_instance; -struct _EphyEmbedEventIface -{ - GTypeInterface parent_iface; - - /* Methods */ - EphyEmbedEventContext (* get_context) (EphyEmbedEvent *event); - guint (* get_button) (EphyEmbedEvent *event); - guint (* get_modifier) (EphyEmbedEvent *event); - void (* get_coordinates) (EphyEmbedEvent *event, - guint *x, - guint *y); - const GValue* (* get_property) (EphyEmbedEvent *event, - const char *name); - gboolean (* has_property) (EphyEmbedEvent *event, - const char *name); - gpointer (* get_dom_event) (EphyEmbedEvent *event); + /*< private >*/ + EphyEmbedEventPrivate *priv; }; -GType ephy_embed_event_get_type (void); - -GType ephy_embed_event_context_get_type (void); - -EphyEmbedEventContext ephy_embed_event_get_context (EphyEmbedEvent *event); - -guint ephy_embed_event_get_button (EphyEmbedEvent *event); - -guint ephy_embed_event_get_modifier (EphyEmbedEvent *event); - - -void ephy_embed_event_get_coords (EphyEmbedEvent *event, - guint *x, guint *y); - -const GValue* ephy_embed_event_get_property (EphyEmbedEvent *event, - const char *name); +struct EphyEmbedEventClass { + GObjectClass parent_class; +}; -gboolean ephy_embed_event_has_property (EphyEmbedEvent *event, - const char *name); -gpointer ephy_embed_event_get_dom_event (EphyEmbedEvent *event); +GType ephy_embed_event_get_type (void); +EphyEmbedEvent *ephy_embed_event_new (GdkEventButton *event, + WebKitHitTestResult *hit_test_result); +guint ephy_embed_event_get_context (EphyEmbedEvent *event); +guint ephy_embed_event_get_button (EphyEmbedEvent *event); +guint ephy_embed_event_get_modifier (EphyEmbedEvent *event); +void ephy_embed_event_get_coords (EphyEmbedEvent *event, + guint *x, + guint *y); +void ephy_embed_event_get_property (EphyEmbedEvent *event, + const char *name, + GValue *value); +gboolean ephy_embed_event_has_property (EphyEmbedEvent *event, + const char *name); G_END_DECLS diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 5f1f49af0..3ef682669 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -688,24 +688,7 @@ ephy_web_view_class_init (EphyWebViewClass *klass) G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE); -/** - * EphyWebView::ge-context-menu: - * @embed: - * @event: the #EphyEmbedEvent which triggered this signal - * - * The ::ge_context_menu signal is emitted when a context menu is to be - * displayed. This will usually happen when the user right-clicks on a part of - * @embed. - **/ - g_signal_new ("ge_context_menu", - EPHY_TYPE_WEB_VIEW, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EphyWebViewClass, context_menu), - g_signal_accumulator_true_handled, NULL, - ephy_marshal_BOOLEAN__OBJECT, - G_TYPE_BOOLEAN, - 1, - G_TYPE_OBJECT); + /** * EphyWebView::ge-favicon: * @embed: diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h index 29f1bd34b..6625689f3 100644 --- a/embed/ephy-web-view.h +++ b/embed/ephy-web-view.h @@ -121,8 +121,6 @@ struct _EphyWebViewClass WebKitWebViewClass parent_class; /* Signals */ - int (* context_menu) (EphyWebView *view, - EphyEmbedEvent *event); void (* favicon) (EphyWebView *view, const char *location); void (* feed_link) (EphyWebView *view, 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); } |