[evolution/wip/webkit2] Move functions from e-html-editor-utils.* to e-dom-utils.*



commit f94f61aafb6e58491e8196e791c7b31fbff9cdfe
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Sep 16 15:23:42 2014 +0200

    Move functions from e-html-editor-utils.* to e-dom-utils.*

 doc/reference/evolution-util/Makefile.am |    1 -
 e-util/Makefile.am                       |    2 -
 e-util/e-dom-utils.c                     |   92 +++++++++++++++++++++++
 e-util/e-dom-utils.h                     |    8 ++
 e-util/e-html-editor-actions.c           |    1 -
 e-util/e-html-editor-cell-dialog.c       |    1 -
 e-util/e-html-editor-hrule-dialog.c      |    1 -
 e-util/e-html-editor-image-dialog.c      |    1 -
 e-util/e-html-editor-link-dialog.c       |    1 -
 e-util/e-html-editor-selection.c         |    1 -
 e-util/e-html-editor-table-dialog.c      |    1 -
 e-util/e-html-editor-utils.c             |  116 ------------------------------
 e-util/e-html-editor-utils.h             |   44 -----------
 e-util/e-html-editor.c                   |    1 -
 e-util/e-util.h                          |    1 -
 15 files changed, 100 insertions(+), 172 deletions(-)
---
diff --git a/doc/reference/evolution-util/Makefile.am b/doc/reference/evolution-util/Makefile.am
index 48d1d13..c047909 100644
--- a/doc/reference/evolution-util/Makefile.am
+++ b/doc/reference/evolution-util/Makefile.am
@@ -18,7 +18,6 @@ CFILE_GLOB = $(top_srcdir)/e-util/*.c
 IGNORE_HFILES = \
        e-html-editor-actions.h \
        e-html-editor-private.h \
-       e-html-editor-utils.h \
        e-marshal.h \
        e-table-col-dnd.h \
        e-table-defines.h \
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index ba2222a..2c4c4af 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -212,7 +212,6 @@ evolution_util_include_HEADERS =  \
        e-html-editor-spell-check-dialog.h \
        e-html-editor-table-dialog.h \
        e-html-editor-text-dialog.h \
-       e-html-editor-utils.h \
        e-html-editor-view.h \
        e-html-editor.h \
        e-html-utils.h \
@@ -486,7 +485,6 @@ libevolution_util_la_SOURCES = \
        e-html-editor-spell-check-dialog.c \
        e-html-editor-table-dialog.c \
        e-html-editor-text-dialog.c \
-       e-html-editor-utils.c \
        e-html-editor-view.c \
        e-html-editor.c \
        e-html-utils.c \
diff --git a/e-util/e-dom-utils.c b/e-util/e-dom-utils.c
index 377d174..f8f4176 100644
--- a/e-util/e-dom-utils.c
+++ b/e-util/e-dom-utils.c
@@ -27,6 +27,8 @@
 
 #include <config.h>
 
+#include <string.h>
+
 static void
 replace_local_image_links (WebKitDOMElement *element)
 {
@@ -1278,3 +1280,93 @@ e_dom_utils_module_vcard_inline_set_iframe_src (WebKitDOMDocument *document,
        webkit_dom_html_iframe_element_set_src (
                WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe), src);
 }
+
+/**
+ * e_html_editor_dom_node_find_parent_element:
+ * @node: Start node
+ * @tagname: Tag name of element to search
+ *
+ * Recursively searches for first occurance of element with given @tagname
+ * that is parent of given @node.
+ *
+ * Returns: A #WebKitDOMElement with @tagname representing parent of @node or
+ * @NULL when @node has no parent with given @tagname. When @node matches @tagname,
+ * then the @node is returned.
+ */
+WebKitDOMElement *
+e_html_editor_dom_node_find_parent_element (WebKitDOMNode *node,
+                                            const gchar *tagname)
+{
+       gint taglen = strlen (tagname);
+
+       while (node) {
+
+               if (WEBKIT_DOM_IS_ELEMENT (node)) {
+                       gchar *node_tagname;
+
+                       node_tagname = webkit_dom_element_get_tag_name (
+                                               WEBKIT_DOM_ELEMENT (node));
+
+                       if (node_tagname &&
+                           (strlen (node_tagname) == taglen) &&
+                           (g_ascii_strncasecmp (node_tagname, tagname, taglen) == 0)) {
+                               g_free (node_tagname);
+                               return WEBKIT_DOM_ELEMENT (node);
+                       }
+
+                       g_free (node_tagname);
+               }
+
+               node = WEBKIT_DOM_NODE (webkit_dom_node_get_parent_element (node));
+       }
+
+       return NULL;
+}
+
+/**
+ * e_html_editor_dom_node_find_child_element:
+ * @node: Start node
+ * @tagname: Tag name of element to search.
+ *
+ * Recursively searches for first occurence of element with given @tagname that
+ * is a child of @node.
+ *
+ * Returns: A #WebKitDOMElement with @tagname representing a child of @node or
+ * @NULL when @node has no child with given @tagname. When @node matches @tagname,
+ * then the @node is returned.
+ */
+WebKitDOMElement *
+e_html_editor_dom_node_find_child_element (WebKitDOMNode *node,
+                                           const gchar *tagname)
+{
+       WebKitDOMNode *start_node = node;
+       gint taglen = strlen (tagname);
+
+       do {
+               if (WEBKIT_DOM_IS_ELEMENT (node)) {
+                       gchar *node_tagname;
+
+                       node_tagname = webkit_dom_element_get_tag_name (
+                                       WEBKIT_DOM_ELEMENT (node));
+
+                       if (node_tagname &&
+                           (strlen (node_tagname) == taglen) &&
+                           (g_ascii_strncasecmp (node_tagname, tagname, taglen) == 0)) {
+                               g_free (node_tagname);
+                               return WEBKIT_DOM_ELEMENT (node);
+                       }
+
+                       g_free (node_tagname);
+               }
+
+               if (webkit_dom_node_has_child_nodes (node)) {
+                       node = webkit_dom_node_get_first_child (node);
+               } else if (webkit_dom_node_get_next_sibling (node)) {
+                       node = webkit_dom_node_get_next_sibling (node);
+               } else {
+                       node = webkit_dom_node_get_parent_node (node);
+               }
+       } while (!webkit_dom_node_is_same_node (node, start_node));
+
+       return NULL;
+}
diff --git a/e-util/e-dom-utils.h b/e-util/e-dom-utils.h
index 2da7d94..ae29176 100644
--- a/e-util/e-dom-utils.h
+++ b/e-util/e-dom-utils.h
@@ -102,6 +102,14 @@ void               e_dom_utils_module_vcard_inline_set_iframe_src
                                                (WebKitDOMDocument *document,
                                                 const gchar *button_id,
                                                 const gchar *src);
+WebKitDOMElement *
+               e_html_editor_dom_node_find_parent_element (
+                                               WebKitDOMNode *node,
+                                               const gchar *tagname);
+WebKitDOMElement *
+               e_html_editor_dom_node_find_child_element (
+                                               WebKitDOMNode *node,
+                                               const gchar *tagname);
 G_END_DECLS
 
 #endif /* E_DOM_UTILS_H */
diff --git a/e-util/e-html-editor-actions.c b/e-util/e-html-editor-actions.c
index 7bb7e23..d4cd329 100644
--- a/e-util/e-html-editor-actions.c
+++ b/e-util/e-html-editor-actions.c
@@ -29,7 +29,6 @@
 #include "e-html-editor.h"
 #include "e-html-editor-private.h"
 #include "e-html-editor-actions.h"
-#include "e-html-editor-utils.h"
 #include "e-emoticon-action.h"
 #include "e-emoticon-chooser.h"
 #include "e-image-chooser-dialog.h"
diff --git a/e-util/e-html-editor-cell-dialog.c b/e-util/e-html-editor-cell-dialog.c
index 0a93645..f33de92 100644
--- a/e-util/e-html-editor-cell-dialog.c
+++ b/e-util/e-html-editor-cell-dialog.c
@@ -28,7 +28,6 @@
 #include <stdlib.h>
 
 #include "e-color-combo.h"
-#include "e-html-editor-utils.h"
 #include "e-image-chooser-dialog.h"
 #include "e-misc-utils.h"
 
diff --git a/e-util/e-html-editor-hrule-dialog.c b/e-util/e-html-editor-hrule-dialog.c
index 9ace655..528f084 100644
--- a/e-util/e-html-editor-hrule-dialog.c
+++ b/e-util/e-html-editor-hrule-dialog.c
@@ -23,7 +23,6 @@
 #endif
 
 #include "e-html-editor-hrule-dialog.h"
-#include "e-html-editor-utils.h"
 #include "e-html-editor-view.h"
 
 #include <glib/gi18n-lib.h>
diff --git a/e-util/e-html-editor-image-dialog.c b/e-util/e-html-editor-image-dialog.c
index 346de44..d79304a 100644
--- a/e-util/e-html-editor-image-dialog.c
+++ b/e-util/e-html-editor-image-dialog.c
@@ -27,7 +27,6 @@
 #include <stdlib.h>
 #include <glib/gi18n-lib.h>
 
-#include "e-html-editor-utils.h"
 #include "e-image-chooser-dialog.h"
 
 #define E_HTML_EDITOR_IMAGE_DIALOG_GET_PRIVATE(obj) \
diff --git a/e-util/e-html-editor-link-dialog.c b/e-util/e-html-editor-link-dialog.c
index 89113e3..1cfddfe 100644
--- a/e-util/e-html-editor-link-dialog.c
+++ b/e-util/e-html-editor-link-dialog.c
@@ -24,7 +24,6 @@
 
 #include "e-html-editor-link-dialog.h"
 #include "e-html-editor-selection.h"
-#include "e-html-editor-utils.h"
 #include "e-html-editor-view.h"
 
 #include <glib/gi18n-lib.h>
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index 84f6fbc..2acbb82 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -25,7 +25,6 @@
 #include "e-html-editor-selection.h"
 #include "e-html-editor-view.h"
 #include "e-html-editor.h"
-#include "e-html-editor-utils.h"
 
 #include <e-util/e-util.h>
 
diff --git a/e-util/e-html-editor-table-dialog.c b/e-util/e-html-editor-table-dialog.c
index 467d2a6..863d206 100644
--- a/e-util/e-html-editor-table-dialog.c
+++ b/e-util/e-html-editor-table-dialog.c
@@ -27,7 +27,6 @@
 #include <glib/gi18n-lib.h>
 
 #include "e-color-combo.h"
-#include "e-html-editor-utils.h"
 #include "e-image-chooser-dialog.h"
 #include "e-misc-utils.h"
 
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index aef38bc..f3e6c46 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -31,7 +31,6 @@
 #include "e-alert-dialog.h"
 #include "e-alert-sink.h"
 #include "e-html-editor-private.h"
-#include "e-html-editor-utils.h"
 #include "e-html-editor-selection.h"
 
 #define E_HTML_EDITOR_GET_PRIVATE(obj) \
diff --git a/e-util/e-util.h b/e-util/e-util.h
index e03f6b6..0bf3301 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -125,7 +125,6 @@
 #include <e-util/e-html-editor-spell-check-dialog.h>
 #include <e-util/e-html-editor-table-dialog.h>
 #include <e-util/e-html-editor-text-dialog.h>
-#include <e-util/e-html-editor-utils.h>
 #include <e-util/e-html-editor-view.h>
 #include <e-util/e-html-editor.h>
 #include <e-util/e-html-utils.h>


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