[evolution/wip/mcrha/webkit-jsc-api] Remove unused functions from e-dom-utils.c/.h and move it to editor web-extension



commit 96aa82c6e37d6db82ee85576aa02c635bf3bf73c
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 8 14:52:16 2019 +0200

    Remove unused functions from e-dom-utils.c/.h and move it to editor web-extension

 src/modules/CMakeLists.txt                         |   29 -
 .../webkit-editor/web-extension/CMakeLists.txt     |   26 +
 .../web-extension/e-composer-dom-functions.c       |    3 +-
 .../web-extension/e-dialogs-dom-functions.c        |    3 +-
 .../webkit-editor/web-extension/e-dom-utils.c      |  621 ++++++
 .../webkit-editor/web-extension}/e-dom-utils.h     |   80 +-
 .../web-extension/e-editor-dom-functions.c         |    3 +-
 .../webkit-editor/web-extension/e-editor-page.c    |    3 +-
 .../web-extension/e-editor-undo-redo-manager.c     |    3 +-
 .../web-extension/e-editor-web-extension.c         |    3 +-
 src/web-extensions/CMakeLists.txt                  |   50 -
 src/web-extensions/e-dom-utils.c                   | 2166 --------------------
 src/web-extensions/e-web-extension-main.c          |    4 -
 13 files changed, 654 insertions(+), 2340 deletions(-)
---
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt
index 9e326d99e5..88fefb2f49 100644
--- a/src/modules/CMakeLists.txt
+++ b/src/modules/CMakeLists.txt
@@ -58,35 +58,6 @@ macro(add_evolution_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdi
        add_simple_module(${_name} ${_sourcesvar} ${_depsvar} ${_defsvar} ${_cflagsvar} ${_incdirsvar} 
${_ldflagsvar} ${moduledir})
 endmacro(add_evolution_module)
 
-macro(add_simple_webextension_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdirsvar _ldflagsvar 
_destdir)
-       set(wex_deps
-               ${${_depsvar}}
-               edomutils
-       )
-       set(wex_cflags
-               ${${_cflagsvar}}
-               ${WEB_EXTENSIONS_CFLAGS}
-       )
-       set(wex_incdirs
-               ${${_incdirsvar}}
-               ${WEB_EXTENSIONS_INCLUDE_DIRS}
-       )
-       set(wex_ldflags
-               ${${_ldflagsvar}}
-               ${WEB_EXTENSIONS_LDFLAGS}
-       )
-
-       add_simple_module(${_name} ${_sourcesvar} wex_deps ${_defsvar} wex_cflags wex_incdirs wex_ldflags 
${_destdir})
-endmacro(add_simple_webextension_module)
-
-macro(add_webextension_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdirsvar _ldflagsvar)
-       add_simple_webextension_module(${_name} ${_sourcesvar} ${_depsvar} ${_defsvar} ${_cflagsvar} 
${_incdirsvar} ${_ldflagsvar} "${webextensionsdir}")
-endmacro(add_webextension_module)
-
-macro(add_webextension_editor_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdirsvar _ldflagsvar)
-       add_simple_webextension_module(${_name} ${_sourcesvar} ${_depsvar} ${_defsvar} ${_cflagsvar} 
${_incdirsvar} ${_ldflagsvar} "${webextensionswebkiteditordir}")
-endmacro(add_webextension_editor_module)
-
 add_subdirectory(addressbook)
 add_subdirectory(calendar)
 add_subdirectory(mail)
diff --git a/src/modules/webkit-editor/web-extension/CMakeLists.txt 
b/src/modules/webkit-editor/web-extension/CMakeLists.txt
index a7f07ff742..ed59c7ebc7 100644
--- a/src/modules/webkit-editor/web-extension/CMakeLists.txt
+++ b/src/modules/webkit-editor/web-extension/CMakeLists.txt
@@ -1,3 +1,27 @@
+macro(add_simple_webextension_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdirsvar _ldflagsvar 
_destdir)
+       set(wex_deps
+               ${${_depsvar}}
+       )
+       set(wex_cflags
+               ${${_cflagsvar}}
+               ${WEB_EXTENSIONS_CFLAGS}
+       )
+       set(wex_incdirs
+               ${${_incdirsvar}}
+               ${WEB_EXTENSIONS_INCLUDE_DIRS}
+       )
+       set(wex_ldflags
+               ${${_ldflagsvar}}
+               ${WEB_EXTENSIONS_LDFLAGS}
+       )
+
+       add_simple_module(${_name} ${_sourcesvar} wex_deps ${_defsvar} wex_cflags wex_incdirs wex_ldflags 
${_destdir})
+endmacro(add_simple_webextension_module)
+
+macro(add_webextension_editor_module _name _sourcesvar _depsvar _defsvar _cflagsvar _incdirsvar _ldflagsvar)
+       add_simple_webextension_module(${_name} ${_sourcesvar} ${_depsvar} ${_defsvar} ${_cflagsvar} 
${_incdirsvar} ${_ldflagsvar} "${webextensionswebkiteditordir}")
+endmacro(add_webextension_editor_module)
+
 set(extra_deps
        evolution-mail
 )
@@ -6,6 +30,8 @@ set(sources
        e-composer-dom-functions.h
        e-dialogs-dom-functions.c
        e-dialogs-dom-functions.h
+       e-dom-utils.c
+       e-dom-utils.h
        e-editor-dom-functions.c
        e-editor-dom-functions.h
        e-editor-page.c
diff --git a/src/modules/webkit-editor/web-extension/e-composer-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-composer-dom-functions.c
index 4e1b7d1cc5..bd840c2537 100644
--- a/src/modules/webkit-editor/web-extension/e-composer-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-composer-dom-functions.c
@@ -24,8 +24,7 @@
 
 #include <camel/camel.h>
 
-#include "web-extensions/e-dom-utils.h"
-
+#include "e-dom-utils.h"
 #include "e-editor-page.h"
 #include "e-editor-dom-functions.h"
 #include "e-editor-undo-redo-manager.h"
diff --git a/src/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
index 64f6c28c10..ce3c2d6ad4 100644
--- a/src/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-dialogs-dom-functions.c
@@ -19,8 +19,7 @@
 
 #include <webkitdom/webkitdom.h>
 
-#include "web-extensions/e-dom-utils.h"
-
+#include "e-dom-utils.h"
 #include "e-editor-dom-functions.h"
 #include "e-editor-undo-redo-manager.h"
 
diff --git a/src/modules/webkit-editor/web-extension/e-dom-utils.c 
b/src/modules/webkit-editor/web-extension/e-dom-utils.c
new file mode 100644
index 0000000000..33776dc0dd
--- /dev/null
+++ b/src/modules/webkit-editor/web-extension/e-dom-utils.c
@@ -0,0 +1,621 @@
+/*
+ * e-dom-utils.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "evolution-config.h"
+
+#include <string.h>
+
+#include <webkitdom/webkitdom.h>
+
+#include "e-dom-utils.h"
+
+void
+e_dom_utils_create_and_add_css_style_sheet (WebKitDOMDocument *document,
+                                            const gchar *style_sheet_id)
+{
+       WebKitDOMElement *style_element;
+
+       style_element = webkit_dom_document_get_element_by_id (document, style_sheet_id);
+
+       if (!style_element) {
+               WebKitDOMText *dom_text;
+               WebKitDOMHTMLHeadElement *head;
+
+               dom_text = webkit_dom_document_create_text_node (document, "");
+
+               /* Create new <style> element */
+               style_element = webkit_dom_document_create_element (document, "style", NULL);
+               webkit_dom_element_set_id (
+                       style_element,
+                       style_sheet_id);
+               webkit_dom_html_style_element_set_media (
+                       WEBKIT_DOM_HTML_STYLE_ELEMENT (style_element),
+                       "screen");
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (style_element),
+                       /* WebKit hack - we have to insert empty TextNode into style element */
+                       WEBKIT_DOM_NODE (dom_text),
+                       NULL);
+
+               head = webkit_dom_document_get_head (document);
+
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (head),
+                       WEBKIT_DOM_NODE (style_element),
+                       NULL);
+       }
+}
+
+/**
+ * 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 *
+dom_node_find_parent_element (WebKitDOMNode *node,
+                              const gchar *tagname)
+{
+       WebKitDOMNode *tmp_node = node;
+       gint taglen = strlen (tagname);
+
+       while (tmp_node) {
+               if (WEBKIT_DOM_IS_ELEMENT (tmp_node)) {
+                       gchar *node_tagname;
+
+                       node_tagname = webkit_dom_element_get_tag_name (
+                               WEBKIT_DOM_ELEMENT (tmp_node));
+
+                       if (node_tagname &&
+                           (strlen (node_tagname) == taglen) &&
+                           (g_ascii_strncasecmp (node_tagname, tagname, taglen) == 0)) {
+                               g_free (node_tagname);
+                               return WEBKIT_DOM_ELEMENT (tmp_node);
+                       }
+
+                       g_free (node_tagname);
+               }
+
+               tmp_node = webkit_dom_node_get_parent_node (tmp_node);
+       }
+
+       return NULL;
+}
+
+gboolean
+element_has_id (WebKitDOMElement *element,
+                const gchar* id)
+{
+       gchar *element_id;
+
+       if (!element)
+               return FALSE;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (element))
+               return FALSE;
+
+       element_id = webkit_dom_element_get_id (element);
+
+       if (element_id && g_ascii_strcasecmp (element_id, id) == 0) {
+               g_free (element_id);
+               return TRUE;
+       }
+       g_free (element_id);
+
+       return FALSE;
+}
+
+gboolean
+element_has_tag (WebKitDOMElement *element,
+                 const gchar* tag)
+{
+       gchar *element_tag;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (element))
+               return FALSE;
+
+       element_tag = webkit_dom_element_get_tag_name (element);
+
+       if (g_ascii_strcasecmp (element_tag, tag) != 0) {
+               g_free (element_tag);
+               return FALSE;
+       }
+       g_free (element_tag);
+
+       return TRUE;
+}
+
+gboolean
+element_has_class (WebKitDOMElement *element,
+                   const gchar* class)
+{
+       gchar *element_class;
+
+       if (!element)
+               return FALSE;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (element))
+               return FALSE;
+
+       element_class = webkit_dom_element_get_class_name (element);
+
+       if (element_class && g_strstr_len (element_class, -1, class)) {
+               g_free (element_class);
+               return TRUE;
+       }
+       g_free (element_class);
+
+       return FALSE;
+}
+
+void
+element_add_class (WebKitDOMElement *element,
+                   const gchar* class)
+{
+       gchar *element_class;
+       gchar *new_class;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (element))
+               return;
+
+       if (element_has_class (element, class))
+               return;
+
+       element_class = webkit_dom_element_get_class_name (element);
+
+       if (!element_class)
+               new_class = g_strdup (class);
+       else
+               new_class = g_strconcat (element_class, " ", class, NULL);
+
+       webkit_dom_element_set_class_name (element, new_class);
+
+       g_free (element_class);
+       g_free (new_class);
+}
+
+void
+element_remove_class (WebKitDOMElement *element,
+                      const gchar* class)
+{
+       gchar *element_class, *final_class;
+       GRegex *regex;
+       gchar *pattern = NULL;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (element))
+               return;
+
+       if (!element_has_class (element, class))
+               return;
+
+       element_class = webkit_dom_element_get_class_name (element);
+
+       pattern = g_strconcat ("[\\s]*", class, "[\\s]*", NULL);
+       regex = g_regex_new (pattern, 0, 0, NULL);
+       final_class = g_regex_replace (regex, element_class, -1, 0, " ", 0, NULL);
+
+       if (g_strcmp0 (final_class, " ") != 0)
+               webkit_dom_element_set_class_name (element, final_class);
+       else
+               webkit_dom_element_remove_attribute (element, "class");
+
+       g_free (element_class);
+       g_free (final_class);
+       g_free (pattern);
+       g_regex_unref (regex);
+}
+
+void
+element_rename_attribute (WebKitDOMElement *element,
+                      const gchar *from,
+                      const gchar *to)
+{
+       gchar *value;
+
+       if (!webkit_dom_element_has_attribute (element, from))
+               return;
+
+       value = webkit_dom_element_get_attribute (element, from);
+       webkit_dom_element_set_attribute (element, to, (value && *value) ? value : "", NULL);
+       webkit_dom_element_remove_attribute (element, from);
+       g_free (value);
+}
+
+void
+remove_node (WebKitDOMNode *node)
+{
+       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
+
+       if (parent)
+               webkit_dom_node_remove_child (parent, node, NULL);
+}
+
+void
+remove_node_if_empty (WebKitDOMNode *node)
+{
+       WebKitDOMNode *child;
+
+       if (!WEBKIT_DOM_IS_NODE (node))
+               return;
+
+       if ((child = webkit_dom_node_get_first_child (node))) {
+               WebKitDOMNode *prev_sibling, *next_sibling;
+
+               prev_sibling = webkit_dom_node_get_previous_sibling (child);
+               next_sibling = webkit_dom_node_get_next_sibling (child);
+               /* Empty or BR as sibling, but no sibling after it. */
+               if (!webkit_dom_node_get_first_child (child) &&
+                   !WEBKIT_DOM_IS_TEXT (child) &&
+                   (!prev_sibling ||
+                    (WEBKIT_DOM_IS_HTML_BR_ELEMENT (prev_sibling) &&
+                     !webkit_dom_node_get_previous_sibling (prev_sibling))) &&
+                   (!next_sibling ||
+                    (WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling) &&
+                     !webkit_dom_node_get_next_sibling (next_sibling)))) {
+
+                       remove_node (node);
+               } else {
+                       gchar *text_content;
+
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (!text_content)
+                               remove_node (node);
+
+                       if (text_content && !*text_content)
+                               remove_node (node);
+
+                       if (g_strcmp0 (text_content, UNICODE_ZERO_WIDTH_SPACE) == 0)
+                               remove_node (node);
+
+                       g_free (text_content);
+               }
+       } else
+               remove_node (node);
+}
+
+WebKitDOMNode *
+split_list_into_two (WebKitDOMNode *item,
+                    gint level)
+{
+       gint current_level = 1;
+       WebKitDOMDocument *document;
+       WebKitDOMDocumentFragment *fragment;
+       WebKitDOMNode *parent, *prev_parent = NULL, *tmp;
+
+       document = webkit_dom_node_get_owner_document (item);
+       fragment = webkit_dom_document_create_document_fragment (document);
+
+       tmp = item;
+       parent = webkit_dom_node_get_parent_node (item);
+       while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
+               WebKitDOMNode *clone, *first_child, *insert_before = NULL, *sibling;
+
+               first_child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (fragment));
+               clone = webkit_dom_node_clone_node_with_error (parent, FALSE, NULL);
+               webkit_dom_node_insert_before (
+                       WEBKIT_DOM_NODE (fragment), clone, first_child, NULL);
+
+               if (first_child)
+                       insert_before = webkit_dom_node_get_first_child (first_child);
+
+               while (first_child && (sibling = webkit_dom_node_get_next_sibling (first_child)))
+                       webkit_dom_node_insert_before (first_child, sibling, insert_before, NULL);
+
+               while (tmp && (sibling = webkit_dom_node_get_next_sibling (tmp)))
+                       webkit_dom_node_append_child (clone, sibling, NULL);
+
+               if (tmp)
+                       webkit_dom_node_insert_before (
+                               clone, tmp, webkit_dom_node_get_first_child (clone), NULL);
+
+               prev_parent = parent;
+               tmp = webkit_dom_node_get_next_sibling (parent);
+               parent = webkit_dom_node_get_parent_node (parent);
+               if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
+                       first_child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (fragment));
+                       insert_before = webkit_dom_node_get_first_child (first_child);
+                       while (first_child && (sibling = webkit_dom_node_get_next_sibling (first_child))) {
+                               webkit_dom_node_insert_before (
+                                       first_child, sibling, insert_before, NULL);
+                       }
+               }
+
+               if (current_level >= level && level >= 0)
+                       break;
+
+               current_level++;
+       }
+
+       tmp = webkit_dom_node_insert_before (
+               parent,
+               webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (fragment)),
+               prev_parent ? webkit_dom_node_get_next_sibling (prev_parent) : NULL,
+               NULL);
+       remove_node_if_empty (prev_parent);
+
+       return tmp;
+}
+
+WebKitDOMElement *
+dom_create_selection_marker (WebKitDOMDocument *document,
+                             gboolean selection_start_marker)
+{
+       WebKitDOMElement *element;
+
+       element = webkit_dom_document_create_element (
+               document, "SPAN", NULL);
+       webkit_dom_element_set_id (
+               element,
+               selection_start_marker ?
+                       "-x-evo-selection-start-marker" :
+                       "-x-evo-selection-end-marker");
+
+       return element;
+}
+
+void
+dom_remove_selection_markers (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *marker;
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
+       if (marker)
+               remove_node (WEBKIT_DOM_NODE (marker));
+}
+
+void
+dom_add_selection_markers_into_element_start (WebKitDOMDocument *document,
+                                              WebKitDOMElement *element,
+                                              WebKitDOMElement **selection_start_marker,
+                                              WebKitDOMElement **selection_end_marker)
+{
+       WebKitDOMElement *marker;
+
+       dom_remove_selection_markers (document);
+       marker = dom_create_selection_marker (document, FALSE);
+       webkit_dom_node_insert_before (
+               WEBKIT_DOM_NODE (element),
+               WEBKIT_DOM_NODE (marker),
+               webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+               NULL);
+       if (selection_end_marker)
+               *selection_end_marker = marker;
+
+       marker = dom_create_selection_marker (document, TRUE);
+       webkit_dom_node_insert_before (
+               WEBKIT_DOM_NODE (element),
+               WEBKIT_DOM_NODE (marker),
+               webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)),
+               NULL);
+       if (selection_start_marker)
+               *selection_start_marker = marker;
+}
+
+void
+dom_add_selection_markers_into_element_end (WebKitDOMDocument *document,
+                                            WebKitDOMElement *element,
+                                            WebKitDOMElement **selection_start_marker,
+                                            WebKitDOMElement **selection_end_marker)
+{
+       WebKitDOMElement *marker;
+
+       dom_remove_selection_markers (document);
+       marker = dom_create_selection_marker (document, TRUE);
+       webkit_dom_node_append_child (
+               WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (marker), NULL);
+       if (selection_start_marker)
+               *selection_start_marker = marker;
+
+       marker = dom_create_selection_marker (document, FALSE);
+       webkit_dom_node_append_child (
+               WEBKIT_DOM_NODE (element), WEBKIT_DOM_NODE (marker), NULL);
+       if (selection_end_marker)
+               *selection_end_marker = marker;
+}
+
+gboolean
+node_is_list_or_item (WebKitDOMNode *node)
+{
+       return node && (
+               WEBKIT_DOM_IS_HTML_O_LIST_ELEMENT (node) ||
+               WEBKIT_DOM_IS_HTML_U_LIST_ELEMENT (node) ||
+               WEBKIT_DOM_IS_HTML_LI_ELEMENT (node));
+}
+
+gboolean
+node_is_list (WebKitDOMNode *node)
+{
+       return node && (
+               WEBKIT_DOM_IS_HTML_O_LIST_ELEMENT (node) ||
+               WEBKIT_DOM_IS_HTML_U_LIST_ELEMENT (node));
+}
+
+/**
+ * e_html_editor_selection_get_list_format_from_node:
+ * @node: an #WebKitDOMNode
+ *
+ * Returns block format of given list.
+ *
+ * Returns: #EContentEditorBlockFormat
+ */
+EContentEditorBlockFormat
+dom_get_list_format_from_node (WebKitDOMNode *node)
+{
+       EContentEditorBlockFormat format =
+               E_CONTENT_EDITOR_BLOCK_FORMAT_UNORDERED_LIST;
+
+       if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (node))
+               return E_CONTENT_EDITOR_BLOCK_FORMAT_NONE;
+
+       if (WEBKIT_DOM_IS_HTML_U_LIST_ELEMENT (node))
+               return format;
+
+       if (WEBKIT_DOM_IS_HTML_O_LIST_ELEMENT (node)) {
+               gchar *type_value = webkit_dom_element_get_attribute (
+                       WEBKIT_DOM_ELEMENT (node), "type");
+
+               if (!type_value)
+                       return E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST;
+
+               if (!*type_value)
+                       format = E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST;
+               else if (g_ascii_strcasecmp (type_value, "A") == 0)
+                       format = E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST_ALPHA;
+               else if (g_ascii_strcasecmp (type_value, "I") == 0)
+                       format = E_CONTENT_EDITOR_BLOCK_FORMAT_ORDERED_LIST_ROMAN;
+               g_free (type_value);
+
+               return format;
+       }
+
+       return E_CONTENT_EDITOR_BLOCK_FORMAT_NONE;
+}
+
+void
+merge_list_into_list (WebKitDOMNode *from,
+                      WebKitDOMNode *to,
+                      gboolean insert_before)
+{
+       WebKitDOMNode *item, *insert_before_node;
+
+       if (!(to && from))
+               return;
+
+       insert_before_node = webkit_dom_node_get_first_child (to);
+       while ((item = webkit_dom_node_get_first_child (from)) != NULL) {
+               if (insert_before)
+                       webkit_dom_node_insert_before (
+                               to, item, insert_before_node, NULL);
+               else
+                       webkit_dom_node_append_child (to, item, NULL);
+       }
+
+       if (!webkit_dom_node_has_child_nodes (from))
+               remove_node (from);
+
+}
+
+void
+merge_lists_if_possible (WebKitDOMNode *list)
+{
+       EContentEditorBlockFormat format, prev, next;
+       gint ii, length;
+       WebKitDOMNode *prev_sibling, *next_sibling;
+       WebKitDOMNodeList *lists = NULL;
+
+       prev_sibling = webkit_dom_node_get_previous_sibling (WEBKIT_DOM_NODE (list));
+       next_sibling = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (list));
+
+       format = dom_get_list_format_from_node (list),
+       prev = dom_get_list_format_from_node (prev_sibling);
+       next = dom_get_list_format_from_node (next_sibling);
+
+       if (format != E_CONTENT_EDITOR_BLOCK_FORMAT_NONE) {
+               if (format == prev && prev != E_CONTENT_EDITOR_BLOCK_FORMAT_NONE)
+                       merge_list_into_list (prev_sibling, list, TRUE);
+
+               if (format == next && next != E_CONTENT_EDITOR_BLOCK_FORMAT_NONE)
+                       merge_list_into_list (next_sibling, list, FALSE);
+       }
+
+       lists = webkit_dom_element_query_selector_all (
+               WEBKIT_DOM_ELEMENT (list), "ol + ol, ul + ul", NULL);
+       length = webkit_dom_node_list_get_length (lists);
+       for (ii = 0; ii < length; ii++) {
+               WebKitDOMNode *node;
+
+               node = webkit_dom_node_list_item (lists, ii);
+               merge_lists_if_possible (node);
+       }
+       g_clear_object (&lists);
+}
+
+WebKitDOMElement *
+get_parent_block_element (WebKitDOMNode *node)
+{
+       WebKitDOMElement *parent = webkit_dom_node_get_parent_element (node);
+
+       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent))
+               return WEBKIT_DOM_IS_ELEMENT (node) ? WEBKIT_DOM_ELEMENT (node) : NULL;
+
+       while (parent &&
+              !WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_U_LIST_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_O_LIST_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_PRE_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_HEADING_ELEMENT (parent) &&
+              !WEBKIT_DOM_IS_HTML_TABLE_CELL_ELEMENT (parent) &&
+              !element_has_tag (parent, "address")) {
+               parent = webkit_dom_node_get_parent_element (
+                       WEBKIT_DOM_NODE (parent));
+       }
+
+       return parent;
+}
+
+gchar *
+dom_get_node_inner_html (WebKitDOMNode *node)
+{
+       gchar *inner_html;
+       WebKitDOMDocument *document;
+       WebKitDOMElement *div;
+
+       document = webkit_dom_node_get_owner_document (node);
+       div = webkit_dom_document_create_element (document, "div", NULL);
+       webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (div),
+                       webkit_dom_node_clone_node_with_error (node, TRUE, NULL),
+                       NULL);
+
+       inner_html = webkit_dom_element_get_inner_html (div);
+       remove_node (WEBKIT_DOM_NODE (div));
+
+       return inner_html;
+}
+
+void
+dom_element_swap_attributes (WebKitDOMElement *element,
+                             const gchar *from,
+                             const gchar *to)
+{
+       gchar *value_from, *value_to;
+
+       if (!webkit_dom_element_has_attribute (element, from) ||
+           !webkit_dom_element_has_attribute (element, to))
+               return;
+
+       value_from = webkit_dom_element_get_attribute (element, from);
+       value_to = webkit_dom_element_get_attribute (element, to);
+       webkit_dom_element_set_attribute (element, to, (value_from && *value_from) ? value_from : "", NULL);
+       webkit_dom_element_set_attribute (element, from, (value_to && *value_to) ? value_to : "", NULL);
+       g_free (value_from);
+       g_free (value_to);
+}
diff --git a/src/web-extensions/e-dom-utils.h b/src/modules/webkit-editor/web-extension/e-dom-utils.h
similarity index 52%
rename from src/web-extensions/e-dom-utils.h
rename to src/modules/webkit-editor/web-extension/e-dom-utils.h
index 27b2350cb9..dceb65c17e 100644
--- a/src/web-extensions/e-dom-utils.h
+++ b/src/modules/webkit-editor/web-extension/e-dom-utils.h
@@ -34,86 +34,12 @@
 
 G_BEGIN_DECLS
 
-void           e_dom_utils_replace_local_image_links
-                                               (WebKitDOMDocument *document);
-gboolean       e_dom_utils_document_has_selection
-                                               (WebKitDOMDocument *document);
-gchar *                e_dom_utils_get_document_content_html
-                                               (WebKitDOMDocument *document);
-gchar *                e_dom_utils_get_selection_content_html
-                                               (WebKitDOMDocument *document);
-gchar *                e_dom_utils_get_selection_content_text
-                                               (WebKitDOMDocument *document);
-gchar *                e_dom_utils_get_selection_content_multipart
-                                               (WebKitDOMDocument *document,
-                                                gboolean *is_html);
 void           e_dom_utils_create_and_add_css_style_sheet
                                                (WebKitDOMDocument *document,
                                                 const gchar *style_sheet_id);
-void           e_dom_utils_add_css_rule_into_style_sheet_in_document
-                                               (WebKitDOMDocument *document,
-                                                const gchar *style_sheet_id,
-                                                const gchar *selector,
-                                                const gchar *style);
-void           e_dom_utils_add_css_rule_into_style_sheet
-                                               (WebKitDOMDocument *document,
-                                                const gchar *style_sheet_id,
-                                                const gchar *selector,
-                                                const gchar *style);
-void           e_dom_utils_eab_contact_formatter_bind_dom
-                                               (WebKitDOMDocument *document);
-void           e_dom_resize_document_content_to_preview_width
-                                               (WebKitDOMDocument *document);
-void           e_dom_utils_e_mail_display_bind_dom
-                                               (WebKitDOMDocument *document,
-                                                GDBusConnection *connection);
-void           e_dom_utils_e_mail_display_unstyle_blockquotes
-                                               (WebKitDOMDocument *document);
-WebKitDOMElement *
-               e_dom_utils_find_element_by_selector
-                                               (WebKitDOMDocument *document,
-                                                const gchar *selector);
-WebKitDOMElement *
-               e_dom_utils_find_element_by_id  (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-gboolean       e_dom_utils_element_exists
-                                               (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-gchar *                e_dom_utils_get_active_element_name
-                                               (WebKitDOMDocument *document);
-void           e_dom_utils_e_mail_part_headers_bind_dom_element
-                                               (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-void           e_dom_utils_element_set_inner_html
-                                               (WebKitDOMDocument *document,
-                                                const gchar *element_id,
-                                                const gchar *inner_html);
-void           e_dom_utils_remove_element      (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-void           e_dom_utils_element_remove_child_nodes
-                                               (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-void           e_dom_utils_hide_element        (WebKitDOMDocument *document,
-                                                const gchar *element_id,
-                                                 gboolean hide);
-gboolean       e_dom_utils_element_is_hidden   (WebKitDOMDocument *document,
-                                                const gchar *element_id);
-WebKitDOMElement *
-               e_dom_utils_get_element_from_point
-                                               (WebKitDOMDocument *document,
-                                                gint32 x,
-                                                gint32 y);
-WebKitDOMDocument *
-               e_dom_utils_get_document_from_point
-                                               (WebKitDOMDocument *document,
-                                                gint32 x,
-                                                gint32 y);
 WebKitDOMElement *
                dom_node_find_parent_element    (WebKitDOMNode *node,
                                                 const gchar *tagname);
-WebKitDOMElement *
-               dom_node_find_child_element     (WebKitDOMNode *node,
-                                                const gchar *tagname);
 gboolean       element_has_id                  (WebKitDOMElement *element,
                                                 const gchar* id);
 gboolean       element_has_tag                 (WebKitDOMElement *element,
@@ -156,11 +82,7 @@ void                merge_lists_if_possible         (WebKitDOMNode *list);
 WebKitDOMElement *
                get_parent_block_element        (WebKitDOMNode *node);
 gchar *                dom_get_node_inner_html         (WebKitDOMNode *node);
-WebKitDOMDocument *
-               e_dom_utils_find_document_with_uri
-                                               (WebKitDOMDocument *root_document,
-                                                const gchar *find_document_uri);
-void           dom_element_swap_attributes     (WebKitDOMElement *element,
+void           dom_element_swap_attributes     (WebKitDOMElement *element,
                                                  const gchar *from,
                                                  const gchar *to);
 
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 97bf1ac350..35cab8cc10 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -20,8 +20,7 @@
 
 #include <webkitdom/webkitdom.h>
 
-#include "web-extensions/e-dom-utils.h"
-
+#include "e-dom-utils.h"
 #include "e-editor-page.h"
 #include "e-editor-undo-redo-manager.h"
 
diff --git a/src/modules/webkit-editor/web-extension/e-editor-page.c 
b/src/modules/webkit-editor/web-extension/e-editor-page.c
index 18d50837b6..8164900575 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-page.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-page.c
@@ -20,8 +20,7 @@
 #include <glib.h>
 #include <webkit2/webkit-web-extension.h>
 
-#include "web-extensions/e-dom-utils.h"
-
+#include "e-dom-utils.h"
 #include "e-editor-dom-functions.h"
 #include "e-editor-web-extension.h"
 #include "e-editor-undo-redo-manager.h"
diff --git a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c 
b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
index ff1b8f5c63..c4053eb47f 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-undo-redo-manager.c
@@ -20,8 +20,7 @@
 
 #include <webkitdom/webkitdom.h>
 
-#include "web-extensions/e-dom-utils.h"
-
+#include "e-dom-utils.h"
 #include "e-editor-page.h"
 #include "e-editor-dom-functions.h"
 #include "e-editor-undo-redo-manager.h"
diff --git a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 3138556dcd..05a1d4ac8d 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -32,8 +32,7 @@
 #include "mail/e-http-request.h"
 #undef E_UTIL_INCLUDE_WITHOUT_WEBKIT
 
-#include "web-extensions/e-dom-utils.h"
-
+//#include "e-dom-utils.h"
 #include "e-editor-page.h"
 #include "e-composer-dom-functions.h"
 #include "e-dialogs-dom-functions.h"
diff --git a/src/web-extensions/CMakeLists.txt b/src/web-extensions/CMakeLists.txt
index cb53096496..2e2c817f35 100644
--- a/src/web-extensions/CMakeLists.txt
+++ b/src/web-extensions/CMakeLists.txt
@@ -4,52 +4,6 @@ set(GRESOURCE_FILES
 
 glib_compile_resources(${CMAKE_CURRENT_SOURCE_DIR} evolution-web-extension-resource 
evolution_web_extension_resource evolution-web-process-extension.gresource.xml ${GRESOURCE_FILES})
 
-set(DEPENDENCIES
-       evolution-util
-)
-
-set(SOURCES
-       e-dom-utils.h
-       e-dom-utils.c
-)
-
-add_library(edomutils SHARED
-       ${SOURCES}
-)
-
-add_dependencies(edomutils
-       ${DEPENDENCIES}
-)
-
-target_compile_definitions(edomutils PRIVATE
-       -DG_LOG_DOMAIN=\"edomutils\"
-       -DEVOLUTION_IMAGESDIR=\"${imagesdir}\"
-)
-
-target_compile_options(edomutils PUBLIC
-       ${EVOLUTION_DATA_SERVER_CFLAGS}
-       ${GNOME_PLATFORM_CFLAGS}
-)
-
-target_include_directories(edomutils PUBLIC
-       ${CMAKE_BINARY_DIR}
-       ${CMAKE_BINARY_DIR}/src
-       ${CMAKE_SOURCE_DIR}/src
-       ${CMAKE_CURRENT_BINARY_DIR}
-       ${EVOLUTION_DATA_SERVER_INCLUDE_DIRS}
-       ${GNOME_PLATFORM_INCLUDE_DIRS}
-)
-
-target_link_libraries(edomutils
-       ${DEPENDENCIES}
-       ${EVOLUTION_DATA_SERVER_LDFLAGS}
-       ${GNOME_PLATFORM_LDFLAGS}
-)
-
-install(TARGETS edomutils
-       DESTINATION ${privsolibdir}
-)
-
 set(SOURCES
        e-web-extension.h
        e-web-extension.c
@@ -62,10 +16,6 @@ add_library(ewebextension MODULE
        ${SOURCES}
 )
 
-add_dependencies(ewebextension
-       ${DEPENDENCIES}
-)
-
 target_compile_definitions(ewebextension PRIVATE
        -DG_LOG_DOMAIN=\"ewebextension\"
        -DEVOLUTION_IMAGESDIR=\"${imagesdir}\"
diff --git a/src/web-extensions/e-web-extension-main.c b/src/web-extensions/e-web-extension-main.c
index a094c97056..82ddea22b3 100644
--- a/src/web-extensions/e-web-extension-main.c
+++ b/src/web-extensions/e-web-extension-main.c
@@ -20,10 +20,6 @@
 
 #include <camel/camel.h>
 
-#define E_UTIL_INCLUDE_WITHOUT_WEBKIT
-#include <e-util/e-util.h>
-#undef E_UTIL_INCLUDE_WITHOUT_WEBKIT
-
 #include "e-web-extension.h"
 
 /* Forward declaration */


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