[evolution/wip-webkit2] TextHiglight - Make the module work under WK2



commit 9dd8e983dba5e96b196c67493b09e1d423367c4e
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Nov 19 15:08:02 2013 +0100

    TextHiglight - Make the module work under WK2

 e-util/e-dom-utils.c                               |    3 +
 .../e-mail-display-popup-text-highlight.c          |  199 +++++++++++---------
 modules/text-highlight/web-extension/Makefile.am   |    5 +-
 .../module-text-highlight-web-extension.c          |   28 ++--
 4 files changed, 127 insertions(+), 108 deletions(-)
---
diff --git a/e-util/e-dom-utils.c b/e-util/e-dom-utils.c
index 234076e..c46598e 100644
--- a/e-util/e-dom-utils.c
+++ b/e-util/e-dom-utils.c
@@ -932,6 +932,9 @@ find_element_from_point (WebKitDOMDocument *document,
                        document, x - left, y - top);
        }
 
+       if (!element)
+               return element_on_point;
+
        if (element_on_point && webkit_dom_node_is_equal_node (
                WEBKIT_DOM_NODE (element),
                WEBKIT_DOM_NODE (element_on_point))) {
diff --git a/modules/text-highlight/e-mail-display-popup-text-highlight.c 
b/modules/text-highlight/e-mail-display-popup-text-highlight.c
index 59ea5d1..39098d3 100644
--- a/modules/text-highlight/e-mail-display-popup-text-highlight.c
+++ b/modules/text-highlight/e-mail-display-popup-text-highlight.c
@@ -166,38 +166,24 @@ mail_display_popup_prefer_plain_watch_web_extension (EMailDisplayPopupTextHighli
 }
 
 static void
-reformat (GtkAction *old,
-          GtkAction *action,
-          gpointer user_data)
+reformat_get_document_uri_cb (GDBusProxy *web_extension,
+                              GAsyncResult *result,
+                              GtkAction *action)
 {
-       EMailDisplayPopupTextHighlight *th_extension;
-       GVariant *result;
        SoupURI *soup_uri;
        GHashTable *query;
-       const gchar *document_uri;
        gchar *uri;
+       GVariant *result_variant;
 
-       th_extension = E_MAIL_DISPLAY_POPUP_TEXT_HIGHLIGHT (user_data);
+       result_variant = g_dbus_proxy_call_finish (web_extension, result, NULL);
+       if (result_variant) {
+               const gchar *document_uri;
 
-       if (!th_extension->web_extension)
-               return;
-
-       /* Get URI from saved document */
-       result = g_dbus_proxy_call_sync (
-                       th_extension->web_extension,
-                       "GetDocumentURI",
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result) {
-               document_uri = g_variant_get_string (result, NULL);
-               g_variant_unref (result);
+               g_variant_get (result_variant, "(&s)", &document_uri);
+               soup_uri = soup_uri_new (document_uri);
+               g_variant_unref (result_variant);
        }
 
-       soup_uri = soup_uri_new (document_uri);
-
        if (!soup_uri)
                return;
 
@@ -219,20 +205,43 @@ reformat (GtkAction *old,
        soup_uri_free (soup_uri);
 
        /* Get frame's window and from the window the actual <iframe> element */
-       result = g_dbus_proxy_call_sync (
-                       th_extension->web_extension,
-                       "ChangeIFrameSource",
-                       g_variant_new ("(s)", uri),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result)
-               g_variant_unref (result);
+       g_dbus_proxy_call (
+               web_extension,
+               "ChangeIFrameSource",
+               g_variant_new ("(s)", uri),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
 
        g_free (uri);
 }
 
+static void
+reformat (GtkAction *old,
+          GtkAction *action,
+          gpointer user_data)
+{
+       EMailDisplayPopupTextHighlight *th_extension;
+
+       th_extension = E_MAIL_DISPLAY_POPUP_TEXT_HIGHLIGHT (user_data);
+
+       if (!th_extension->web_extension)
+               return;
+
+       /* Get URI from saved document */
+       g_dbus_proxy_call (
+               th_extension->web_extension,
+               "GetDocumentURI",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               (GAsyncReadyCallback) reformat_get_document_uri_cb,
+               action);
+}
+
 static GtkActionGroup *
 create_group (EMailDisplayPopupExtension *extension)
 {
@@ -344,66 +353,19 @@ create_group (EMailDisplayPopupExtension *extension)
 }
 
 static void
-update_actions (EMailDisplayPopupExtension *extension)
+get_document_uri_cb (GDBusProxy *web_extension,
+                     GAsyncResult *result,
+                     EMailDisplayPopupTextHighlight *th_extension)
 {
-       EMailDisplay *display;
-       EMailDisplayPopupTextHighlight *th_extension;
-       const gchar *document_uri;
-       GVariant *result;
-       gint32 x, y;
-       GdkDeviceManager *device_manager;
-       GdkDevice *pointer;
-
-       display = E_MAIL_DISPLAY (e_extension_get_extensible (
-                       E_EXTENSION (extension)));
-
-       th_extension = E_MAIL_DISPLAY_POPUP_TEXT_HIGHLIGHT (extension);
-
-       if (th_extension->action_group == NULL) {
-               th_extension->action_group = create_group (extension);
-       }
-
-       /* In WK2 you can't get the node on what WebKitHitTest was performed,
-        * we have to use other way */
-       device_manager = gdk_display_get_device_manager (
-               gtk_widget_get_display (GTK_WIDGET(display)));
-       pointer = gdk_device_manager_get_client_pointer (device_manager);
-       gdk_window_get_device_position (
-               gtk_widget_get_window (GTK_WIDGET (display)), pointer, &x, &y, NULL);
-
-       if (!th_extension->web_extension)
-                       return;
+       GVariant *result_variant;
+       gchar *document_uri;
 
-       result = g_dbus_proxy_call_sync (
-                       th_extension->web_extension,
-                       "SaveDocumentFromPoint",
-                       g_variant_new (
-                               "(tii)",
-                               webkit_web_view_get_page_id (
-                                       WEBKIT_WEB_VIEW (display)),
-                               x, y),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result)
-               g_variant_unref (result);
-
-       /* Get URI from saved document */
-       result = g_dbus_proxy_call_sync (
-                       th_extension->web_extension,
-                       "GetDocumentURI",
-                       NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1,
-                       NULL,
-                       NULL);
-       if (result) {
-               document_uri = g_variant_get_string (result, NULL);
-               g_variant_unref (result);
+       result_variant = g_dbus_proxy_call_finish (web_extension, result, NULL);
+       if (result_variant) {
+               g_variant_get (result_variant, "(s)", &document_uri);
+               g_variant_unref (result_variant);
        }
 
-
        /* If the part below context menu was made by text-highlight formatter,
         * then try to check what formatter it's using at the moment and set
         * it as active in the popup menu */
@@ -436,11 +398,66 @@ update_actions (EMailDisplayPopupExtension *extension)
                if (soup_uri) {
                        soup_uri_free (soup_uri);
                }
-
        } else {
                gtk_action_group_set_visible (
                        th_extension->action_group, FALSE);
        }
+
+       g_free (document_uri);
+}
+static void
+update_actions (EMailDisplayPopupExtension *extension)
+{
+       EMailDisplay *display;
+       EMailDisplayPopupTextHighlight *th_extension;
+       gint32 x, y;
+       GdkDeviceManager *device_manager;
+       GdkDevice *pointer;
+
+       display = E_MAIL_DISPLAY (e_extension_get_extensible (
+                       E_EXTENSION (extension)));
+
+       th_extension = E_MAIL_DISPLAY_POPUP_TEXT_HIGHLIGHT (extension);
+
+       if (th_extension->action_group == NULL) {
+               th_extension->action_group = create_group (extension);
+       }
+
+       /* In WK2 you can't get the node on what WebKitHitTest was performed,
+        * we have to use other way */
+       device_manager = gdk_display_get_device_manager (
+               gtk_widget_get_display (GTK_WIDGET(display)));
+       pointer = gdk_device_manager_get_client_pointer (device_manager);
+       gdk_window_get_device_position (
+               gtk_widget_get_window (GTK_WIDGET (display)), pointer, &x, &y, NULL);
+
+       if (!th_extension->web_extension)
+                       return;
+
+       g_dbus_proxy_call (
+               th_extension->web_extension,
+               "SaveDocumentFromPoint",
+               g_variant_new (
+                       "(tii)",
+                       webkit_web_view_get_page_id (
+                               WEBKIT_WEB_VIEW (display)),
+                       x, y),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
+
+       /* Get URI from saved document */
+       g_dbus_proxy_call (
+               th_extension->web_extension,
+               "GetDocumentURI",
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               (GAsyncReadyCallback) get_document_uri_cb,
+               th_extension);
 }
 
 void
diff --git a/modules/text-highlight/web-extension/Makefile.am 
b/modules/text-highlight/web-extension/Makefile.am
index 745c47f..014fb77 100644
--- a/modules/text-highlight/web-extension/Makefile.am
+++ b/modules/text-highlight/web-extension/Makefile.am
@@ -2,10 +2,13 @@ webextensions_LTLIBRARIES = libmoduletexthighlightwebextension.la
 
 libmoduletexthighlightwebextension_la_SOURCES =                \
        module-text-highlight-web-extension.c           \
-       module-text-highlight-web-extension.h
+       module-text-highlight-web-extension.h           \
+       $(top_srcdir)/e-util/e-dom-utils.c              \
+       $(top_srcdir)/e-util/e-dom-utils.h
 
 libmoduletexthighlightwebextension_la_CPPFLAGS =       \
        -DWEBEXTENSIONS_COMPILATION                     \
+       -DEVOLUTION_IMAGESDIR=\"${imagesdir}\"          \
        $(GNOME_PLATFORM_CFLAGS)                        \
        $(AM_CPPFLAGS)                                  \
        $(WEB_EXTENSIONS_CFLAGS)
diff --git a/modules/text-highlight/web-extension/module-text-highlight-web-extension.c 
b/modules/text-highlight/web-extension/module-text-highlight-web-extension.c
index 204bac2..1299b69 100644
--- a/modules/text-highlight/web-extension/module-text-highlight-web-extension.c
+++ b/modules/text-highlight/web-extension/module-text-highlight-web-extension.c
@@ -22,6 +22,8 @@
 #include <gtk/gtk.h>
 #include <webkit2/webkit-web-extension.h>
 
+#include "../../../e-util/e-dom-utils.h"
+
 /* FIXME Clean it */
 static GDBusConnection *dbus_connection;
 
@@ -81,7 +83,7 @@ handle_method_call (GDBusConnection *connection,
                WebKitDOMElement *frame_element;
                const gchar *new_uri;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &new_uri);
+               g_variant_get (parameters, "(&s)", &new_uri);
 
                /* Get frame's window and from the window the actual <iframe> element */
                window = webkit_dom_document_get_default_view (document_saved);
@@ -92,7 +94,6 @@ handle_method_call (GDBusConnection *connection,
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "SaveDocumentFromPoint") == 0) {
                gint32 x = 0, y = 0;
-               WebKitDOMElement *active_element;
 
                g_variant_get (parameters, "(tii)", &page_id, &x, &y);
                web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
@@ -100,26 +101,21 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               document_saved = document;
-
-               if (x == 0 && y == 0)
-                       active_element = webkit_dom_html_document_get_active_element 
(WEBKIT_DOM_HTML_DOCUMENT (document));
-               else
-                       active_element = webkit_dom_document_element_from_point (document, x,y);
-
-               if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (active_element)) {
-                       document_saved =
-                               webkit_dom_html_iframe_element_get_content_document (
-                                       WEBKIT_DOM_HTML_IFRAME_ELEMENT (active_element));
-               }
+               document_saved = e_dom_utils_get_document_from_point (document, x, y);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "GetDocumentURI") == 0) {
                gchar *document_uri;
 
-               document_uri = webkit_dom_document_get_document_uri (document_saved);
+               if (document_saved)
+                       document_uri = webkit_dom_document_get_document_uri (document_saved);
+               else
+                       document_uri = g_strdup ("");
+
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new ("(s)", document_uri));
 
-               g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", document_uri));
+               g_free (document_uri);
        }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]