[evolution/wip/webkit2: 127/128] Slowly start to port EHTMLEditorView and EHTMLEditorSelection



commit 1174f3bbf7f021f9fa5bfea9836cf6263b200098
Author: Tomas Popela <tpopela redhat com>
Date:   Tue Oct 21 14:43:56 2014 +0200

    Slowly start to port EHTMLEditorView and EHTMLEditorSelection
    
    Also simplify how the dialogs are working with DOM.

 e-util/e-html-editor-cell-dialog.c                 |  113 +--
 e-util/e-html-editor-hrule-dialog.c                |  132 +--
 e-util/e-html-editor-image-dialog.c                |  185 +---
 e-util/e-html-editor-link-dialog-dom-functions.c   |    3 +-
 e-util/e-html-editor-page-dialog.c                 |  117 +--
 e-util/e-html-editor-selection-dom-functions.c     | 1410 +++++++++++++++++++-
 e-util/e-html-editor-selection-dom-functions.h     |    6 +
 e-util/e-html-editor-selection.c                   | 1302 ------------------
 e-util/e-html-editor-table-dialog-dom-functions.c  |  248 +---
 e-util/e-html-editor-table-dialog-dom-functions.h  |   54 +-
 e-util/e-html-editor-table-dialog.c                |  430 +++----
 e-util/e-html-editor-view.c                        |   80 +-
 e-util/e-html-editor-view.h                        |   13 +
 e-util/e-html-editor.c                             |    5 +-
 .../web-extensions/e-html-editor-web-extension.c   |  989 +++++---------
 15 files changed, 2192 insertions(+), 2895 deletions(-)
---
diff --git a/e-util/e-html-editor-cell-dialog.c b/e-util/e-html-editor-cell-dialog.c
index 61e2746..d63ee0e 100644
--- a/e-util/e-html-editor-cell-dialog.c
+++ b/e-util/e-html-editor-cell-dialog.c
@@ -29,10 +29,8 @@
 
 #include "e-color-combo.h"
 #include "e-dialog-widgets.h"
-#include "e-html-editor-utils.h"
 #include "e-image-chooser-dialog.h"
 #include "e-misc-utils.h"
-#include "e-misc-utils.h"
 
 #define E_HTML_EDITOR_CELL_DIALOG_GET_PRIVATE(obj) \
        (G_TYPE_INSTANCE_GET_PRIVATE \
@@ -371,7 +369,7 @@ html_editor_cell_dialog_set_background_image (EHTMLEditorCellDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        GDBusProxy *web_extension;
-       const gchar *uri;
+       gchar *uri;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
@@ -382,15 +380,10 @@ html_editor_cell_dialog_set_background_image (EHTMLEditorCellDialog *dialog)
        uri = gtk_file_chooser_get_uri (
                GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
 
-       if (!uri || !*uri) {
-               e_html_editor_selection_replace_image_src (
-                       e_html_editor_view_get_selection (view),
-                       "#-x-evo-current-cell",
-                       uri);
-       } else {
+       if (uri && *uri)
                g_dbus_proxy_call (
                        web_extension,
-                       "RemoveImageAttributesFromElement",
+                       "RemoveImageAttributesFromElementBySelector",
                        g_variant_new (
                                "(ts)",
                                webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -400,9 +393,15 @@ html_editor_cell_dialog_set_background_image (EHTMLEditorCellDialog *dialog)
                        NULL,
                        NULL,
                        NULL);
-       }
+       else
+               e_html_editor_selection_replace_image_src (
+                       e_html_editor_view_get_selection (view),
+                       "#-x-evo-current-cell",
+                       uri);
 
        gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
+
+       g_free (uri);
 }
 
 static void
@@ -411,7 +410,6 @@ html_editor_cell_dialog_remove_image (EHTMLEditorCellDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        GDBusProxy *web_extension;
-       const gchar *uri;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
@@ -421,7 +419,7 @@ html_editor_cell_dialog_remove_image (EHTMLEditorCellDialog *dialog)
 
        g_dbus_proxy_call (
                web_extension,
-               "RemoveImageAttributesFromElement",
+               "RemoveImageAttributesFromElementBySelector",
                g_variant_new (
                        "(ts)",
                        webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -448,7 +446,7 @@ html_editor_cell_dialog_show (GtkWidget *widget)
        GVariant *result;
        GdkRGBA color;
 
-       dialog = E_HTML_EDITOR_CELL_DIALOG (dialog);
+       dialog = E_HTML_EDITOR_CELL_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
        web_extension = e_html_editor_view_get_web_extension_proxy (view);
@@ -458,17 +456,8 @@ html_editor_cell_dialog_show (GtkWidget *widget)
        gtk_toggle_button_set_active (
                GTK_TOGGLE_BUTTON (dialog->priv->scope_cell_button), TRUE);
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "TableCellElementGetAlign",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-cell"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-cell", "align");
 
        if (result) {
                const gchar *align;
@@ -480,17 +469,8 @@ html_editor_cell_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "TableCellElementGetVAlign",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-cell"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-cell", "valign");
 
        if (result) {
                const gchar *v_align;
@@ -545,17 +525,8 @@ html_editor_cell_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "TableCellElementGetWidth",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-cell"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-cell", "width");
 
        if (result) {
                const gchar *width;
@@ -640,19 +611,9 @@ html_editor_cell_dialog_show (GtkWidget *widget)
                g_variant_get (result, "(b)", &has_background);
                if (has_background) {
                        g_variant_unref (result);
-                       result = g_dbus_proxy_call_sync (
-                               web_extension,
-                               "ElementGetAttribute",
-                               g_variant_new (
-                                       "(tss)",
-                                       webkit_web_view_get_page_id (
-                                               WEBKIT_WEB_VIEW (view)),
-                                       "-x-evo-current-cell",
-                                       "data-uri"),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               NULL);
+
+                       result = e_html_editor_view_get_element_attribute (
+                               view, "#-x-evo-current-cell", "data-uri");
 
                        if (result) {
                                const gchar *value;
@@ -672,17 +633,8 @@ html_editor_cell_dialog_show (GtkWidget *widget)
                }
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "TableCellElementGetBgColor",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-cell"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-cell", "bgcolor");
 
        if (result) {
                const gchar *bg_color;
@@ -716,28 +668,13 @@ html_editor_cell_dialog_hide (GtkWidget *widget)
        EHTMLEditor *editor;
        EHTMLEditorCellDialog *dialog;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
 
        dialog = E_HTML_EDITOR_CELL_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "ElementRemoveAttribute",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-cell",
-                       "id"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_remove_element_attribute (
+               view, "#-x-evo-current-cell", "id");
 
        GTK_WIDGET_CLASS (e_html_editor_cell_dialog_parent_class)->hide (widget);
 }
diff --git a/e-util/e-html-editor-hrule-dialog.c b/e-util/e-html-editor-hrule-dialog.c
index a5162c4..4b8ff38 100644
--- a/e-util/e-html-editor-hrule-dialog.c
+++ b/e-util/e-html-editor-hrule-dialog.c
@@ -51,28 +51,16 @@ html_editor_hrule_dialog_set_alignment (EHTMLEditorHRuleDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
+       const gchar *value;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "HRElementSetAlign",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr",
-                       gtk_combo_box_get_active_id (
-                               GTK_COMBO_BOX (dialog->priv->alignment_combo))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       value = gtk_combo_box_get_active_id (
+               GTK_COMBO_BOX (dialog->priv->alignment_combo));
+
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-hr", "align", value);
 }
 
 static void
@@ -80,26 +68,13 @@ html_editor_hrule_dialog_get_alignment (EHTMLEditorHRuleDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "HRElementGetAlign",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-hr", "align");
 
        if (result) {
                const gchar *value;
@@ -117,32 +92,17 @@ html_editor_hrule_dialog_set_size (EHTMLEditorHRuleDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        gchar *size;
-       GDBusProxy *web_extension;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        size = g_strdup_printf (
                "%d",
                (gint) gtk_spin_button_get_value (
                        GTK_SPIN_BUTTON (dialog->priv->size_edit)));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "HRElementGetAlign",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr",
-                       size),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-hr", "size", size);
 
        g_free (size);
 }
@@ -153,25 +113,12 @@ html_editor_hrule_dialog_get_size (EHTMLEditorHRuleDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        GVariant *result;
-       GDBusProxy *web_extension;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "HRElementGetSize",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-hr", "size");
 
        if (result) {
                const gchar *value;
@@ -198,13 +145,9 @@ html_editor_hrule_dialog_set_width (EHTMLEditorHRuleDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        gchar *width, *units;
-       GDBusProxy *web_extension;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        units = gtk_combo_box_text_get_active_text (
                        GTK_COMBO_BOX_TEXT (dialog->priv->unit_combo));
@@ -214,19 +157,8 @@ html_editor_hrule_dialog_set_width (EHTMLEditorHRuleDialog *dialog)
                        GTK_SPIN_BUTTON (dialog->priv->width_edit)),
                units);
 
-       g_dbus_proxy_call (
-               web_extension,
-               "HRElementSetWidth",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr",
-                       width),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-hr", "width", width);
 
        g_free (units);
        g_free (width);
@@ -238,25 +170,12 @@ html_editor_hrule_dialog_get_width (EHTMLEditorHRuleDialog *dialog)
        EHTMLEditor *editor;
        EHTMLEditorView *view;
        GVariant *result;
-       GDBusProxy *web_extension;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "HRElementGetWidth",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-hr", "width");
 
        if (result) {
                const gchar *value, *units;
@@ -357,28 +276,13 @@ html_editor_hrule_dialog_hide (GtkWidget *widget)
        EHTMLEditor *editor;
        EHTMLEditorHRuleDialog *dialog;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
 
        dialog = E_HTML_EDITOR_HRULE_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "ElementRemoveAttribute",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-hr",
-                       "id"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_remove_element_attribute (
+               view, "#-x-evo-current-hr", "id");
 
        GTK_WIDGET_CLASS (e_html_editor_hrule_dialog_parent_class)->hide (widget);
 }
diff --git a/e-util/e-html-editor-image-dialog.c b/e-util/e-html-editor-image-dialog.c
index 79382ff..ad7dd20 100644
--- a/e-util/e-html-editor-image-dialog.c
+++ b/e-util/e-html-editor-image-dialog.c
@@ -82,28 +82,15 @@ html_editor_image_dialog_set_alt (EHTMLEditorImageDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
+       const gchar *value;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "ImageElementSetAlt",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img",
-                       gtk_entry_get_text (GTK_ENTRY (
-                               dialog->priv->description_edit))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       value = gtk_entry_get_text (GTK_ENTRY (dialog->priv->description_edit));
+
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-img", "alt", value);
 }
 
 static void
@@ -176,29 +163,6 @@ html_editor_image_dialog_set_width (EHTMLEditorImageDialog *dialog)
 }
 
 static void
-remove_attribute (EHTMLEditorView *view,
-                  GDBusProxy *web_extension,
-                  const gchar *attribute)
-{
-       if (!web_extension)
-               return;
-
-       g_dbus_proxy_call (
-               web_extension,
-               "ElementRemoveAttribute",
-               g_variant_new (
-                       "(tsi)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img",
-                       attribute),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
-}
-
-static void
 html_editor_image_dialog_set_width_units (EHTMLEditorImageDialog *dialog)
 {
        EHTMLEditor *editor;
@@ -244,7 +208,8 @@ html_editor_image_dialog_set_width_units (EHTMLEditorImageDialog *dialog)
                        } else {
                                width = natural;
                        }
-                       remove_attribute (view, web_extension, "style");
+                       e_html_editor_view_remove_element_attribute (
+                               view, "#-x-evo-current-img", "style");
                        gtk_widget_set_sensitive (dialog->priv->width_edit, TRUE);
                        break;
 
@@ -254,33 +219,21 @@ html_editor_image_dialog_set_width_units (EHTMLEditorImageDialog *dialog)
                        } else {
                                width = 100;
                        }
-                       remove_attribute (view, web_extension, "style");
+                       e_html_editor_view_remove_element_attribute (
+                               view, "#-x-evo-current-img", "style");
                        gtk_widget_set_sensitive (dialog->priv->width_edit, TRUE);
                        break;
 
                case 2: /* follow */
-                       g_dbus_proxy_call (
-                               web_extension,
-                               "ElementSetAttribute",
-                               g_variant_new (
-                                       "(tsi)",
-                                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                                       "-x-evo-current-img",
-                                       "style",
-                                       "width: auto;"),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               NULL,
-                               NULL);
+                       e_html_editor_view_set_element_attribute (
+                               view, "#-x-evo-current-img", "style", "width: auto;");
                        gtk_widget_set_sensitive (dialog->priv->width_edit, FALSE);
                        break;
        }
 
-       if (width != 0) {
+       if (width != 0)
                gtk_spin_button_set_value (
                        GTK_SPIN_BUTTON (dialog->priv->width_edit), width);
-       }
 }
 
 static void
@@ -398,7 +351,8 @@ html_editor_image_dialog_set_height_units (EHTMLEditorImageDialog *dialog)
                        } else {
                                height = natural;
                        }
-                       remove_attribute (view, web_extension, "style");
+                       e_html_editor_view_remove_element_attribute (
+                               view, "#-x-evo-current-img", "style");
                        gtk_widget_set_sensitive (dialog->priv->height_edit, TRUE);
                        break;
 
@@ -408,33 +362,21 @@ html_editor_image_dialog_set_height_units (EHTMLEditorImageDialog *dialog)
                        } else {
                                height = 100;
                        }
-                       remove_attribute (view, web_extension, "style");
+                       e_html_editor_view_remove_element_attribute (
+                               view, "#-x-evo-current-img", "style");
                        gtk_widget_set_sensitive (dialog->priv->height_edit, TRUE);
                        break;
 
                case 2: /* follow */
-                       g_dbus_proxy_call (
-                               web_extension,
-                               "ElementSetAttribute",
-                               g_variant_new (
-                                       "(tsi)",
-                                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                                       "-x-evo-current-img",
-                                       "style",
-                                       "height: auto;"),
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               NULL,
-                               NULL);
+                       e_html_editor_view_set_element_attribute (
+                               view, "#-x-evo-current-img", "style", "height: auto;");
                        gtk_widget_set_sensitive (dialog->priv->height_edit, FALSE);
                        break;
        }
 
-       if (height != -1) {
+       if (height != -1)
                gtk_spin_button_set_value (
                        GTK_SPIN_BUTTON (dialog->priv->height_edit), height);
-       }
 }
 
 static void
@@ -442,28 +384,14 @@ html_editor_image_dialog_set_alignment (EHTMLEditorImageDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
+       const gchar *value;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "ImageElementSetAlign",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img",
-                       gtk_combo_box_get_active_id (
-                               GTK_COMBO_BOX (dialog->priv->alignment))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       value = gtk_combo_box_get_active_id (GTK_COMBO_BOX (dialog->priv->alignment));
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-img", "align", value);
 }
 
 static void
@@ -529,32 +457,17 @@ html_editor_image_dialog_set_border (EHTMLEditorImageDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        gchar *value;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        value = g_strdup_printf (
                "%d", gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->border_edit)));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "ImageElementSetVSpace",
-               g_variant_new (
-                       "(tsi)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img",
-                       value),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-img", "border", value);
 
        g_free (value);
 }
@@ -612,18 +525,8 @@ html_editor_image_dialog_show (GtkWidget *widget)
        if (!web_extension)
                return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "ElementGetAttribute",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img",
-                       "data-uri"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-img", "data-uri");
 
        if (result) {
                const gchar *value;
@@ -643,17 +546,8 @@ html_editor_image_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "ImageElementGetAlt",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-img", "alt");
 
        if (result) {
                const gchar *value;
@@ -711,17 +605,8 @@ html_editor_image_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "ImageElementGetBorder",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       "-x-evo-current-img"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-img", "border");
 
        if (result) {
                const gchar *value;
@@ -804,16 +689,12 @@ html_editor_image_dialog_hide (GtkWidget *widget)
        EHTMLEditor *editor;
        EHTMLEditorImageDialog *dialog;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
 
        dialog = E_HTML_EDITOR_IMAGE_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
-
-       remove_attribute (view, web_extension, "id");
+       e_html_editor_view_remove_element_attribute (
+               view, "#-x-evo-current-img", "id");
 
        GTK_WIDGET_CLASS (e_html_editor_image_dialog_parent_class)->hide (widget);
 }
diff --git a/e-util/e-html-editor-link-dialog-dom-functions.c 
b/e-util/e-html-editor-link-dialog-dom-functions.c
index 8695b21..c3176ae 100644
--- a/e-util/e-html-editor-link-dialog-dom-functions.c
+++ b/e-util/e-html-editor-link-dialog-dom-functions.c
@@ -119,7 +119,8 @@ e_html_editor_link_dialog_show (WebKitDOMDocument *document)
        /* No selection at all */
        if (!dom_selection ||
            webkit_dom_dom_selection_get_range_count (dom_selection) < 1) {
-               return;
+               result = g_variant_new ("(ss)", "", "");
+               return result;
        }
 
        range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
diff --git a/e-util/e-html-editor-page-dialog.c b/e-util/e-html-editor-page-dialog.c
index c1c1f69..bf6fccb 100644
--- a/e-util/e-html-editor-page-dialog.c
+++ b/e-util/e-html-editor-page-dialog.c
@@ -148,33 +148,19 @@ html_editor_page_dialog_set_text_color (EHTMLEditorPageDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GdkRGBA rgba;
        gchar *color;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        e_color_combo_get_current_color (
                E_COLOR_COMBO (dialog->priv->text_color_picker), &rgba);
 
        color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "BodySetTextColor",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       color),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "body", "text", color);
 
        g_free (color);
 }
@@ -199,18 +185,8 @@ html_editor_page_dialog_set_link_color (EHTMLEditorPageDialog *dialog)
 
        color = g_strdup_printf ("#%06x", e_rgba_to_value (&rgba));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "BodySetLinkColor",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       color),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "body", "link", color);
 
        g_free (color);
 }
@@ -237,18 +213,8 @@ html_editor_page_dialog_set_background_color (EHTMLEditorPageDialog *dialog)
        else
                color = g_strdup ("");
 
-       g_dbus_proxy_call (
-               web_extension,
-               "BodySetBgColor",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       color),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "body", "bgcolor", color);
 
        g_free (color);
 }
@@ -312,7 +278,7 @@ html_editor_page_dialog_set_background_image (EHTMLEditorPageDialog *dialog)
        else
                g_dbus_proxy_call (
                        web_extension,
-                       "RemoveImageAttributesFromElement",
+                       "RemoveImageAttributesFromElementBySelector",
                        g_variant_new (
                                "(ts)",
                                webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -333,15 +299,26 @@ html_editor_page_dialog_remove_image (EHTMLEditorPageDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       WebKitDOMDocument *document;
-       WebKitDOMHTMLElement *body;
+       GDBusProxy *web_extension;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-       body = webkit_dom_document_get_body (document);
+       web_extension = e_html_editor_view_get_web_extension_proxy (view);
+       if (!web_extension)
+               return;
 
-       remove_image_attributes_from_element (WEBKIT_DOM_ELEMENT (body));
+       g_dbus_proxy_call (
+               web_extension,
+               "RemoveImageAttributesFromElementBySelector",
+               g_variant_new (
+                       "(ts)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       "body"),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
 
        gtk_file_chooser_unselect_all (
                GTK_FILE_CHOOSER (dialog->priv->background_image_filechooser));
@@ -366,19 +343,8 @@ html_editor_page_dialog_show (GtkWidget *widget)
        if (!web_extension)
                return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "ElementGetAttributeBySelector",
-               g_variant_new (
-                       "(tss)",
-                       webkit_web_view_get_page_id (
-                               WEBKIT_WEB_VIEW (view)),
-                       "body",
-                       "data-uri"),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "body", "data-uri");
 
        if (result) {
                const gchar *value;
@@ -406,16 +372,7 @@ html_editor_page_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "BodyGetTextColor",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (view, "body", "text");
 
        if (result) {
                const gchar *value;
@@ -432,16 +389,7 @@ html_editor_page_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "BodyGetLinkColor",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (view, "body", "link");
 
        if (result) {
                const gchar *value;
@@ -464,16 +412,7 @@ html_editor_page_dialog_show (GtkWidget *widget)
                g_variant_unref (result);
        }
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "BodyGetBgColor",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (view, "body", "bgcolor");
 
        if (result) {
                const gchar *value;
diff --git a/e-util/e-html-editor-selection-dom-functions.c b/e-util/e-html-editor-selection-dom-functions.c
index f645c25..40a00a3 100644
--- a/e-util/e-html-editor-selection-dom-functions.c
+++ b/e-util/e-html-editor-selection-dom-functions.c
@@ -19,14 +19,15 @@
 #include "e-html-editor-selection-dom-functions.h"
 
 #include "e-util-enums.h"
-
 #include "e-dom-utils.h"
-
 #include "e-html-editor-view-dom-functions.h"
 
+#include <string.h>
+
 #define WEBKIT_DOM_USE_UNSTABLE_API
 #include <webkitdom/WebKitDOMDOMSelection.h>
 #include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+#include <webkitdom/WebKitDOMDocumentFragmentUnstable.h>
 
 #define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
 #define UNICODE_NBSP "\xc2\xa0"
@@ -531,6 +532,73 @@ set_ordered_list_type_to_element (WebKitDOMElement *list,
                webkit_dom_element_set_attribute (list, "type", "I", NULL);
 }
 
+static const gchar *
+get_css_alignment_value_class (EHTMLEditorSelectionAlignment alignment)
+{
+       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT)
+               return ""; /* Left is by default on ltr */
+
+       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER)
+               return "-x-evo-align-center";
+
+       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT)
+               return "-x-evo-align-right";
+
+       return "";
+}
+
+/**
+ * e_html_editor_selection_get_alignment:
+ * @selection: #an EHTMLEditorSelection
+ *
+ * Returns alignment of current paragraph
+ *
+ * Returns: #EHTMLEditorSelectionAlignment
+ */
+static EHTMLEditorSelectionAlignment
+e_html_editor_selection_get_alignment (WebKitDOMDocument *document)
+{
+       EHTMLEditorSelectionAlignment alignment;
+       gchar *value;
+       WebKitDOMCSSStyleDeclaration *style;
+       WebKitDOMDOMWindow *window;
+       WebKitDOMElement *element;
+       WebKitDOMNode *node;
+       WebKitDOMRange *range;
+
+       window = webkit_dom_document_get_default_view (document);
+       range = html_editor_selection_dom_get_current_range (document);
+       if (!range)
+               return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+
+       node = webkit_dom_range_get_start_container (range, NULL);
+       if (!node)
+               return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+
+       if (WEBKIT_DOM_IS_ELEMENT (node))
+               element = WEBKIT_DOM_ELEMENT (node);
+       else
+               element = webkit_dom_node_get_parent_element (node);
+
+       style = webkit_dom_dom_window_get_computed_style (window, element, NULL);
+       value = webkit_dom_css_style_declaration_get_property_value (style, "text-align");
+
+       if (!value || !*value ||
+           (g_ascii_strncasecmp (value, "left", 4) == 0)) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       } else if (g_ascii_strncasecmp (value, "center", 6) == 0) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
+       } else if (g_ascii_strncasecmp (value, "right", 5) == 0) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
+       } else {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       }
+
+       g_free (value);
+
+       return alignment;
+}
+
 static void
 e_html_editor_selection_dom_set_paragraph_style (WebKitDOMDocument *document,
                                                  WebKitDOMElement *element,
@@ -542,7 +610,7 @@ e_html_editor_selection_dom_set_paragraph_style (WebKitDOMDocument *document,
        char *style = NULL;
        gint word_wrap_length = (width == -1) ? WORD_WRAP_LENGTH : width;
 
-       alignment = e_html_editor_selection_get_alignment (selection);
+       alignment = e_html_editor_selection_get_alignment (document);
 
        element_add_class (element, "-x-evo-paragraph");
        element_add_class (element, get_css_alignment_value_class (alignment));
@@ -586,6 +654,70 @@ create_list_element (WebKitDOMDocument *document,
        return list;
 }
 
+static WebKitDOMNode *
+get_parent_block_node_from_child (WebKitDOMNode *node)
+{
+       WebKitDOMElement *parent = WEBKIT_DOM_ELEMENT (
+               webkit_dom_node_get_parent_node (node));
+
+        if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) ||
+            element_has_tag (parent, "b") ||
+            element_has_tag (parent, "i") ||
+            element_has_tag (parent, "u"))
+               parent = WEBKIT_DOM_ELEMENT (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent)));
+
+       if (element_has_class (parent, "-x-evo-temp-text-wrapper") ||
+           element_has_class (parent, "-x-evo-signature"))
+               parent = WEBKIT_DOM_ELEMENT (
+                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent)));
+
+       return WEBKIT_DOM_NODE (parent);
+}
+
+static void
+merge_list_into_list (WebKitDOMNode *from,
+                      WebKitDOMNode *to,
+                      gboolean insert_before)
+{
+       WebKitDOMNode *item;
+
+       if (!(to && from))
+               return;
+
+       while ((item = webkit_dom_node_get_first_child (from)) != NULL) {
+               if (insert_before)
+                       webkit_dom_node_insert_before (
+                               to, item, webkit_dom_node_get_last_child (to), NULL);
+               else
+                       webkit_dom_node_append_child (to, item, NULL);
+       }
+
+       if (!webkit_dom_node_has_child_nodes (from))
+               remove_node (from);
+
+}
+
+static void
+merge_lists_if_possible (WebKitDOMNode *list)
+{
+       EHTMLEditorSelectionBlockFormat format, prev, next;
+       WebKitDOMNode *prev_sibling, *next_sibling;
+
+       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 = e_html_editor_selection_dom_get_list_format_from_node (list),
+       prev = e_html_editor_selection_dom_get_list_format_from_node (prev_sibling);
+       next = e_html_editor_selection_dom_get_list_format_from_node (next_sibling);
+
+       if (format == prev && format != -1 && prev != -1)
+               merge_list_into_list (prev_sibling, list, TRUE);
+
+       if (format == next && format != -1 && next != -1)
+               merge_list_into_list (next_sibling, list, FALSE);
+}
+
 static void
 indent_list (WebKitDOMDocument *document)
 {
@@ -611,7 +743,7 @@ indent_list (WebKitDOMDocument *document)
                format = e_html_editor_selection_dom_get_list_format_from_node (source_list);
 
                list = create_list_element (
-                       selection, document, format, get_list_level (item), html_mode);
+                       document, format, get_list_level (item), html_mode);
 
                element_add_class (list, "-x-evo-indented");
 
@@ -635,7 +767,8 @@ indent_list (WebKitDOMDocument *document)
 }
 
 static void
-e_html_editor_selection_set_indented_style (WebKitDOMElement *element,
+e_html_editor_selection_set_indented_style (WebKitDOMDocument *document,
+                                            WebKitDOMElement *element,
                                             gint width)
 {
        gchar *style;
@@ -661,7 +794,7 @@ e_html_editor_selection_get_indented_element (WebKitDOMDocument *document,
        WebKitDOMElement *element;
 
        element = webkit_dom_document_create_element (document, "DIV", NULL);
-       e_html_editor_selection_set_indented_style (element, width);
+       e_html_editor_selection_set_indented_style (document, element, width);
 
        return element;
 }
@@ -713,6 +846,69 @@ get_indentation_level (WebKitDOMElement *element)
        return level;
 }
 
+static WebKitDOMNode *
+get_parent_indented_block (WebKitDOMNode *node)
+{
+       WebKitDOMNode *parent, *block = NULL;
+
+       parent = webkit_dom_node_get_parent_node (node);
+       if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented"))
+               block = parent;
+
+       while (parent && !WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
+               if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented"))
+                       block = parent;
+               parent = webkit_dom_node_get_parent_node (parent);
+       }
+
+       return block;
+}
+
+static WebKitDOMElement*
+get_element_for_inspection (WebKitDOMRange *range)
+{
+       WebKitDOMNode *node;
+
+       node = webkit_dom_range_get_end_container (range, NULL);
+       /* No selection or whole body selected */
+       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (node))
+               return NULL;
+
+       return WEBKIT_DOM_ELEMENT (get_parent_indented_block (node));
+}
+
+static EHTMLEditorSelectionAlignment
+e_html_editor_selection_get_alignment_from_node (WebKitDOMNode *node)
+{
+       EHTMLEditorSelectionAlignment alignment;
+       gchar *value;
+       WebKitDOMCSSStyleDeclaration *style;
+       WebKitDOMDocument *document;
+       WebKitDOMDOMWindow *window;
+
+       document = webkit_dom_node_get_owner_document (node);
+       window = webkit_dom_document_get_default_view (document);
+
+       style = webkit_dom_dom_window_get_computed_style (
+               window, WEBKIT_DOM_ELEMENT (node), NULL);
+       value = webkit_dom_css_style_declaration_get_property_value (style, "text-align");
+
+       if (!value || !*value ||
+           (g_ascii_strncasecmp (value, "left", 4) == 0)) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       } else if (g_ascii_strncasecmp (value, "center", 6) == 0) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
+       } else if (g_ascii_strncasecmp (value, "right", 5) == 0) {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
+       } else {
+               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
+       }
+
+       g_free (value);
+
+       return alignment;
+}
+
 /**
  * e_html_editor_selection_indent:
  * @selection: an #EHTMLEditorSelection
@@ -842,21 +1038,6 @@ e_html_editor_selection_indent (WebKitDOMDocument *document)
        g_object_notify (G_OBJECT (selection), "indented"); */
 }
 
-static const gchar *
-get_css_alignment_value_class (EHTMLEditorSelectionAlignment alignment)
-{
-       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT)
-               return ""; /* Left is by default on ltr */
-
-       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER)
-               return "-x-evo-align-center";
-
-       if (alignment == E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT)
-               return "-x-evo-align-right";
-
-       return "";
-}
-
 static void
 unindent_list (WebKitDOMDocument *document)
 {
@@ -957,13 +1138,13 @@ unindent_block (WebKitDOMDocument *document,
         * create new blockquote that will include them */
        if (webkit_dom_node_get_previous_sibling (block_to_process))
                prev_blockquote = e_html_editor_selection_get_indented_element (
-                       selection, document, width);
+                       document, width);
 
        /* Look if we have next siblings, if so, we have to
         * create new blockquote that will include them */
        if (webkit_dom_node_get_next_sibling (block_to_process))
                next_blockquote = e_html_editor_selection_get_indented_element (
-                       selection, document, width);
+                       document, width);
 
        /* Copy nodes that are before / after the element that we want to unindent */
        while ((child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (element)))) {
@@ -1148,3 +1329,1186 @@ e_html_editor_selection_unindent (WebKitDOMDocument *document)
 
        g_object_notify (G_OBJECT (selection), "indented"); */
 }
+
+static WebKitDOMNode *
+in_empty_block_in_quoted_content (WebKitDOMNode *element)
+{
+       WebKitDOMNode *first_child, *next_sibling;
+
+       if (!WEBKIT_DOM_IS_HTML_DIV_ELEMENT (element))
+               return NULL;
+
+       first_child = webkit_dom_node_get_first_child (element);
+       if (!WEBKIT_DOM_IS_ELEMENT (first_child))
+               return NULL;
+
+       if (!element_has_class (WEBKIT_DOM_ELEMENT (first_child), "-x-evo-quoted"))
+               return NULL;
+
+       next_sibling = webkit_dom_node_get_next_sibling (first_child);
+       if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling))
+               return next_sibling;
+
+       if (!WEBKIT_DOM_IS_ELEMENT (next_sibling))
+               return NULL;
+
+       if (!element_has_id (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-selection-start-marker"))
+               return NULL;
+
+       next_sibling = webkit_dom_node_get_next_sibling (next_sibling);
+       if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (next_sibling))
+               return next_sibling;
+
+       return NULL;
+}
+
+/**
+ * e_html_editor_selection_save:
+ * @selection: an #EHTMLEditorSelection
+ *
+ * Saves current cursor position or current selection range. The selection can
+ * be later restored by calling e_html_editor_selection_restore().
+ *
+ * Note that calling e_html_editor_selection_save() overwrites previously saved
+ * position.
+ *
+ * Note that this method inserts special markings into the HTML code that are
+ * used to later restore the selection. It can happen that by deleting some
+ * segments of the document some of the markings are deleted too. In that case
+ * restoring the selection by e_html_editor_selection_restore() can fail. Also by
+ * moving text segments (Cut & Paste) can result in moving the markings
+ * elsewhere, thus e_html_editor_selection_restore() will restore the selection
+ * incorrectly.
+ *
+ * It is recommended to use this method only when you are not planning to make
+ * bigger changes to content or structure of the document (formatting changes
+ * are usually OK).
+ */
+void
+e_html_editor_selection_dom_save (WebKitDOMDocument *document)
+{
+       glong offset;
+       WebKitDOMRange *range;
+       WebKitDOMNode *container, *next_sibling, *marker_node;
+       WebKitDOMNode *split_node, *parent_node;
+       WebKitDOMElement *marker;
+
+       /* First remove all markers (if present) */
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (marker != NULL)
+               remove_node (WEBKIT_DOM_NODE (marker));
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
+       if (marker != NULL)
+               remove_node (WEBKIT_DOM_NODE (marker));
+
+       range = html_editor_selection_dom_get_current_range (document);
+
+       if (!range)
+               return;
+
+       marker = webkit_dom_document_create_element (document, "SPAN", NULL);
+       webkit_dom_element_set_id (marker, "-x-evo-selection-start-marker");
+
+       container = webkit_dom_range_get_start_container (range, NULL);
+       offset = webkit_dom_range_get_start_offset (range, NULL);
+
+       if (WEBKIT_DOM_IS_TEXT (container)) {
+               if (offset != 0) {
+                       WebKitDOMText *split_text;
+
+                       split_text = webkit_dom_text_split_text (
+                               WEBKIT_DOM_TEXT (container), offset, NULL);
+                       split_node = WEBKIT_DOM_NODE (split_text);
+               } else {
+                       marker_node = webkit_dom_node_insert_before (
+                               webkit_dom_node_get_parent_node (container),
+                               WEBKIT_DOM_NODE (marker),
+                               container,
+                               NULL);
+                       goto end_marker;
+               }
+       } else if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (container)) {
+               marker_node = webkit_dom_node_insert_before (
+                       container,
+                       WEBKIT_DOM_NODE (marker),
+                       webkit_dom_node_get_first_child (container),
+                       NULL);
+               goto end_marker;
+       } else {
+               /* Insert the selection marker on the right position in
+                * an empty paragraph in the quoted content */
+               if ((next_sibling = in_empty_block_in_quoted_content (container))) {
+                       marker_node = webkit_dom_node_insert_before (
+                               container,
+                               WEBKIT_DOM_NODE (marker),
+                               next_sibling,
+                               NULL);
+                       goto end_marker;
+               }
+               if (!webkit_dom_node_get_previous_sibling (container)) {
+                       marker_node = webkit_dom_node_insert_before (
+                               container,
+                               WEBKIT_DOM_NODE (marker),
+                               webkit_dom_node_get_first_child (container),
+                               NULL);
+                       goto end_marker;
+               } else if (!webkit_dom_node_get_next_sibling (container)) {
+                       marker_node = webkit_dom_node_append_child (
+                               container,
+                               WEBKIT_DOM_NODE (marker),
+                               NULL);
+                       goto end_marker;
+               } else {
+                       if (webkit_dom_node_get_first_child (container)) {
+                               marker_node = webkit_dom_node_insert_before (
+                                       container,
+                                       WEBKIT_DOM_NODE (marker),
+                                       webkit_dom_node_get_first_child (container),
+                                       NULL);
+                               goto end_marker;
+                       }
+                       split_node = container;
+               }
+       }
+
+       /* Don't save selection straight into body */
+       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node))
+               return;
+
+       if (!split_node) {
+               marker_node = webkit_dom_node_insert_before (
+                       container,
+                       WEBKIT_DOM_NODE (marker),
+                       webkit_dom_node_get_first_child (
+                               WEBKIT_DOM_NODE (container)),
+                       NULL);
+       } else {
+               marker_node = WEBKIT_DOM_NODE (marker);
+               parent_node = webkit_dom_node_get_parent_node (split_node);
+
+               webkit_dom_node_insert_before (
+                       parent_node, marker_node, split_node, NULL);
+       }
+
+ end_marker:
+       marker = webkit_dom_document_create_element (document, "SPAN", NULL);
+       webkit_dom_element_set_id (marker, "-x-evo-selection-end-marker");
+
+       if (webkit_dom_range_get_collapsed (range, NULL)) {
+               webkit_dom_node_insert_before (
+                       /* Selection start marker */
+                       webkit_dom_node_get_parent_node (marker_node),
+                       WEBKIT_DOM_NODE (marker),
+                       webkit_dom_node_get_next_sibling (marker_node),
+                       NULL);
+               return;
+       }
+
+       container = webkit_dom_range_get_end_container (range, NULL);
+       offset = webkit_dom_range_get_end_offset (range, NULL);
+
+       if (WEBKIT_DOM_IS_TEXT (container)) {
+               if (offset != 0) {
+                       WebKitDOMText *split_text;
+
+                       split_text = webkit_dom_text_split_text (
+                               WEBKIT_DOM_TEXT (container), offset, NULL);
+                       split_node = WEBKIT_DOM_NODE (split_text);
+               } else {
+                       marker_node = webkit_dom_node_insert_before (
+                               webkit_dom_node_get_parent_node (container),
+                               WEBKIT_DOM_NODE (marker),
+                               container,
+                               NULL);
+                       goto check;
+
+               }
+       } else if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (container)) {
+               webkit_dom_node_append_child (
+                       container, WEBKIT_DOM_NODE (marker), NULL);
+               return;
+       } else {
+               /* Insert the selection marker on the right position in
+                * an empty paragraph in the quoted content */
+               if ((next_sibling = in_empty_block_in_quoted_content (container))) {
+                       webkit_dom_node_insert_before (
+                               container,
+                               WEBKIT_DOM_NODE (marker),
+                               next_sibling,
+                               NULL);
+                       return;
+               }
+               if (!webkit_dom_node_get_previous_sibling (container)) {
+                       split_node = webkit_dom_node_get_parent_node (container);
+               } else if (!webkit_dom_node_get_next_sibling (container)) {
+                       split_node = webkit_dom_node_get_parent_node (container);
+                       split_node = webkit_dom_node_get_next_sibling (split_node);
+               } else
+                       split_node = container;
+       }
+
+       /* Don't save selection straight into body */
+       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node)) {
+               marker = webkit_dom_document_get_element_by_id (
+                       document, "-x-evo-selection-start-marker");
+               remove_node (WEBKIT_DOM_NODE (marker));
+               return;
+       }
+
+       marker_node = WEBKIT_DOM_NODE (marker);
+
+       if (split_node) {
+               parent_node = webkit_dom_node_get_parent_node (split_node);
+
+               webkit_dom_node_insert_before (
+                       parent_node, marker_node, split_node, NULL);
+       } else
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (container), marker_node, NULL);
+
+ check:
+       if ((next_sibling = webkit_dom_node_get_next_sibling (marker_node))) {
+               if (!WEBKIT_DOM_IS_ELEMENT (next_sibling))
+                       next_sibling = webkit_dom_node_get_next_sibling (next_sibling);
+               /* If the selection is collapsed ensure that the selection start marker
+                * is before the end marker */
+               if (next_sibling && WEBKIT_DOM_IS_ELEMENT (next_sibling) &&
+                   element_has_id (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-selection-start-marker")) {
+                       webkit_dom_node_insert_before (
+                               webkit_dom_node_get_parent_node (marker_node),
+                               next_sibling,
+                               marker_node,
+                               NULL);
+               }
+       }
+}
+
+static gboolean
+is_selection_position_node (WebKitDOMNode *node)
+{
+       WebKitDOMElement *element;
+
+       if (!node || !WEBKIT_DOM_IS_ELEMENT (node))
+               return FALSE;
+
+       element = WEBKIT_DOM_ELEMENT (node);
+
+       return element_has_id (element, "-x-evo-caret-position") ||
+              element_has_id (element, "-x-evo-selection-start-marker") ||
+              element_has_id (element, "-x-evo-selection-end-marker");
+}
+
+/**
+ * e_html_editor_selection_restore:
+ * @selection: an #EHTMLEditorSelection
+ *
+ * Restores cursor position or selection range that was saved by
+ * e_html_editor_selection_save().
+ *
+ * Note that calling this function without calling e_html_editor_selection_save()
+ * before is a programming error and the behavior is undefined.
+ */
+void
+e_html_editor_selection_dom_restore (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *marker;
+       WebKitDOMNode *selection_start_marker, *selection_end_marker;
+       WebKitDOMRange *range;
+       WebKitDOMDOMSelection *dom_selection;
+       WebKitDOMDOMWindow *window;
+
+       window = webkit_dom_document_get_default_view (document);
+       dom_selection = webkit_dom_dom_window_get_selection (window);
+       range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
+       if (!range)
+               return;
+
+       selection_start_marker = webkit_dom_range_get_start_container (range, NULL);
+       if (selection_start_marker) {
+               gboolean ok = FALSE;
+               selection_start_marker =
+                       webkit_dom_node_get_next_sibling (selection_start_marker);
+
+               ok = is_selection_position_node (selection_start_marker);
+
+               if (ok) {
+                       ok = FALSE;
+                       if (webkit_dom_range_get_collapsed (range, NULL)) {
+                               selection_end_marker = webkit_dom_node_get_next_sibling (
+                                       selection_start_marker);
+
+                               ok = is_selection_position_node (selection_end_marker);
+                               if (ok) {
+                                       remove_node (selection_start_marker);
+                                       remove_node (selection_end_marker);
+
+                                       return;
+                               }
+                       }
+               }
+       }
+
+       range = webkit_dom_document_create_range (document);
+       if (!range)
+               return;
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (!marker) {
+               marker = webkit_dom_document_get_element_by_id (
+                       document, "-x-evo-selection-end-marker");
+               if (marker)
+                       remove_node (WEBKIT_DOM_NODE (marker));
+               return;
+       }
+
+       webkit_dom_range_set_start_after (range, WEBKIT_DOM_NODE (marker), NULL);
+       remove_node (WEBKIT_DOM_NODE (marker));
+
+       marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-end-marker");
+       if (!marker) {
+               marker = webkit_dom_document_get_element_by_id (
+                       document, "-x-evo-selection-start-marker");
+               if (marker)
+                       remove_node (WEBKIT_DOM_NODE (marker));
+               return;
+       }
+
+       webkit_dom_range_set_end_before (range, WEBKIT_DOM_NODE (marker), NULL);
+       remove_node (WEBKIT_DOM_NODE (marker));
+
+       webkit_dom_dom_selection_remove_all_ranges (dom_selection);
+       webkit_dom_dom_selection_add_range (dom_selection, range);
+}
+
+static gint
+find_where_to_break_line (WebKitDOMNode *node,
+                          gint max_len,
+                         gint word_wrap_length)
+{
+       gchar *str, *text_start;
+       gunichar uc;
+       gint pos;
+       gint last_space = 0;
+       gint length;
+       gint ret_val = 0;
+       gchar* position;
+
+       text_start =  webkit_dom_character_data_get_data (WEBKIT_DOM_CHARACTER_DATA (node));
+       length = g_utf8_strlen (text_start, -1);
+
+       pos = 1;
+       last_space = 0;
+       str = text_start;
+       do {
+               uc = g_utf8_get_char (str);
+               if (!uc) {
+                       g_free (text_start);
+                       if (pos <= max_len)
+                               return pos;
+                       else
+                               return last_space;
+               }
+
+               /* If last_space is zero then the word is longer than
+                * word_wrap_length characters, so continue until we find
+                * a space */
+               if ((pos > max_len) && (last_space > 0)) {
+                       if (last_space > word_wrap_length) {
+                               g_free (text_start);
+                               return last_space - 1;
+                       }
+
+                       if (last_space > max_len) {
+                               if (g_unichar_isspace (g_utf8_get_char (text_start)))
+                                       ret_val = 1;
+
+                               g_free (text_start);
+                               return ret_val;
+                       }
+
+                       if (last_space == max_len - 1) {
+                               uc = g_utf8_get_char (str);
+                               if (g_unichar_isspace (uc) || str[0] == '-')
+                                       last_space++;
+                       }
+
+                       g_free (text_start);
+                       return last_space;
+               }
+
+               if (g_unichar_isspace (uc) || str[0] == '-')
+                       last_space = pos;
+
+               pos += 1;
+               str = g_utf8_next_char (str);
+       } while (*str);
+
+       position = g_utf8_offset_to_pointer (text_start, max_len);
+
+       if (g_unichar_isspace (g_utf8_get_char (position))) {
+               ret_val = max_len + 1;
+       } else {
+               if (last_space == 0) {
+                       /* If word is longer than word_wrap_length, we cannot wrap it */
+                       ret_val = length;
+               } else if (last_space < max_len) {
+                       ret_val = last_space;
+               } else {
+                       if (length > word_wrap_length)
+                               ret_val = last_space;
+                       else
+                               ret_val = 0;
+               }
+       }
+
+       g_free (text_start);
+
+       return ret_val;
+}
+
+/**
+ * e_html_editor_selection_is_collapsed:
+ * @selection: an #EHTMLEditorSelection
+ *
+ * Returns if selection is collapsed.
+ *
+ * Returns: Whether the selection is collapsed (just caret) or not (someting is selected).
+ */
+static gboolean
+e_html_editor_selection_is_collapsed (WebKitDOMDocument *document)
+{
+       WebKitDOMRange *range;
+
+       range = html_editor_selection_dom_get_current_range (document);
+       if (!range)
+               return TRUE;
+
+       return webkit_dom_range_get_collapsed (range, NULL);
+}
+
+/**
+ * e_html_editor_selection_get_string:
+ * @selection: an #EHTMLEditorSelection
+ *
+ * Returns currently selected string.
+ *
+ * Returns: A pointer to content of current selection. The string is owned by
+ * #EHTMLEditorSelection and should not be free'd.
+ */
+static gchar *
+e_html_editor_selection_get_string (WebKitDOMDocument *document)
+{
+       WebKitDOMRange *range;
+
+       range = html_editor_selection_dom_get_current_range (document);
+       if (!range)
+               return NULL;
+
+       return webkit_dom_range_get_text (range);
+}
+
+static WebKitDOMElement *
+wrap_lines (WebKitDOMNode *paragraph,
+           WebKitDOMDocument *document,
+           gboolean remove_all_br,
+           gint word_wrap_length)
+{
+       WebKitDOMNode *node, *start_node;
+       WebKitDOMNode *paragraph_clone;
+       WebKitDOMDocumentFragment *fragment;
+       WebKitDOMElement *element;
+       WebKitDOMNodeList *wrap_br;
+       gboolean has_selection;
+       gint len, ii, br_count;
+       gulong length_left;
+       glong paragraph_char_count;
+       gchar *text_content;
+
+       has_selection = !e_html_editor_selection_is_collapsed (document);
+
+       if (has_selection) {
+               gchar *text_content;
+
+               text_content = e_html_editor_selection_get_string (document);
+               paragraph_char_count = g_utf8_strlen (text_content, -1);
+               g_free (text_content);
+
+               fragment = webkit_dom_range_clone_contents (
+                       html_editor_selection_dom_get_current_range (document), NULL);
+
+               /* Select all BR elements or just ours that are used for wrapping.
+                * We are not removing user BR elements when this function is activated
+                * from Format->Wrap Lines action */
+               wrap_br = webkit_dom_document_fragment_query_selector_all (
+                       fragment,
+                       remove_all_br ? "br" : "br.-x-evo-wrap-br",
+                       NULL);
+               br_count = webkit_dom_node_list_get_length (wrap_br);
+               /* And remove them */
+               for (ii = 0; ii < br_count; ii++)
+                       remove_node (webkit_dom_node_list_item (wrap_br, ii));
+               g_object_unref (wrap_br);
+       } else {
+               if (!webkit_dom_node_has_child_nodes (paragraph))
+                       return WEBKIT_DOM_ELEMENT (paragraph);
+
+               paragraph_clone = webkit_dom_node_clone_node (paragraph, TRUE);
+               element = webkit_dom_element_query_selector (
+                       WEBKIT_DOM_ELEMENT (paragraph_clone),
+                       "span#-x-evo-caret-position",
+                       NULL);
+               text_content = webkit_dom_node_get_text_content (paragraph_clone);
+               paragraph_char_count = g_utf8_strlen (text_content, -1);
+               if (element)
+                       paragraph_char_count--;
+               g_free (text_content);
+
+               /* When we wrap, we are wrapping just the text after caret, text
+                * before the caret is already wrapped, so unwrap the text after
+                * the caret position */
+               element = webkit_dom_element_query_selector (
+                       WEBKIT_DOM_ELEMENT (paragraph_clone),
+                       "span#-x-evo-selection-end-marker",
+                       NULL);
+
+               if (element) {
+                       WebKitDOMNode *nd = WEBKIT_DOM_NODE (element);
+
+                       while (nd) {
+                               WebKitDOMNode *next_nd = webkit_dom_node_get_next_sibling (nd);
+                               if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (nd)) {
+                                       if (remove_all_br)
+                                               remove_node (nd);
+                                       else if (element_has_class (WEBKIT_DOM_ELEMENT (nd), 
"-x-evo-wrap-br"))
+                                               remove_node (nd);
+                               }
+                               nd = next_nd;
+                       }
+               }
+       }
+
+       if (has_selection) {
+               node = WEBKIT_DOM_NODE (fragment);
+               start_node = node;
+       } else {
+               webkit_dom_node_normalize (paragraph_clone);
+               node = webkit_dom_node_get_first_child (paragraph_clone);
+               if (node) {
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (g_strcmp0 ("\n", text_content) == 0)
+                               node = webkit_dom_node_get_next_sibling (node);
+                       g_free (text_content);
+               }
+
+               /* We have to start from the end of the last wrapped line */
+               element = webkit_dom_element_query_selector (
+                       WEBKIT_DOM_ELEMENT (paragraph_clone),
+                       "span#-x-evo-selection-start-marker",
+                       NULL);
+
+               if (element) {
+                       WebKitDOMNode *nd = WEBKIT_DOM_NODE (element);
+
+                       while ((nd = webkit_dom_node_get_previous_sibling (nd))) {
+                               if (WEBKIT_DOM_IS_HTML_BR_ELEMENT (nd)) {
+                                       element = WEBKIT_DOM_ELEMENT (nd);
+                                       break;
+                               } else
+                                       element = NULL;
+                       }
+               }
+
+               if (element) {
+                       node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element));
+                       start_node = paragraph_clone;
+               } else
+                       start_node = node;
+       }
+
+       len = 0;
+       while (node) {
+               gint offset = 0;
+
+               if (WEBKIT_DOM_IS_TEXT (node)) {
+                       const gchar *newline;
+                       WebKitDOMNode *next_sibling;
+
+                       /* If there is temporary hidden space we remove it */
+                       text_content = webkit_dom_node_get_text_content (node);
+                       if (strstr (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+                               if (g_str_has_prefix (text_content, UNICODE_ZERO_WIDTH_SPACE))
+                                       webkit_dom_character_data_delete_data (
+                                               WEBKIT_DOM_CHARACTER_DATA (node),
+                                               0,
+                                               1,
+                                               NULL);
+                               if (g_str_has_suffix (text_content, UNICODE_ZERO_WIDTH_SPACE))
+                                       webkit_dom_character_data_delete_data (
+                                               WEBKIT_DOM_CHARACTER_DATA (node),
+                                               g_utf8_strlen (text_content, -1) - 1,
+                                               1,
+                                               NULL);
+                               g_free (text_content);
+                               text_content = webkit_dom_node_get_text_content (node);
+                       }
+                       newline = g_strstr_len (text_content, -1, "\n");
+
+                       next_sibling = node;
+                       while (newline) {
+                               next_sibling = WEBKIT_DOM_NODE (webkit_dom_text_split_text (
+                                       WEBKIT_DOM_TEXT (next_sibling),
+                                       g_utf8_pointer_to_offset (text_content, newline),
+                                       NULL));
+
+                               if (!next_sibling)
+                                       break;
+
+                               element = webkit_dom_document_create_element (
+                                       document, "BR", NULL);
+                               element_add_class (element, "-x-evo-temp-wrap-text-br");
+
+                               webkit_dom_node_insert_before (
+                                       webkit_dom_node_get_parent_node (next_sibling),
+                                       WEBKIT_DOM_NODE (element),
+                                       next_sibling,
+                                       NULL);
+
+                               g_free (text_content);
+
+                               text_content = webkit_dom_node_get_text_content (next_sibling);
+                               if (g_str_has_prefix (text_content, "\n")) {
+                                       webkit_dom_character_data_delete_data (
+                                               WEBKIT_DOM_CHARACTER_DATA (next_sibling), 0, 1, NULL);
+                                       g_free (text_content);
+                                       text_content =
+                                               webkit_dom_node_get_text_content (next_sibling);
+                               }
+                               newline = g_strstr_len (text_content, -1, "\n");
+                       }
+                       g_free (text_content);
+               } else {
+                       if (is_selection_position_node (node)) {
+                               node = webkit_dom_node_get_next_sibling (node);
+                               continue;
+                       }
+
+                       /* If element is ANCHOR we wrap it separately */
+                       if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) {
+                               glong anchor_length;
+
+                               text_content = webkit_dom_node_get_text_content (node);
+                               anchor_length = g_utf8_strlen (text_content, -1);
+                               if (len + anchor_length > word_wrap_length) {
+                                       element = webkit_dom_document_create_element (
+                                               document, "BR", NULL);
+                                       element_add_class (element, "-x-evo-wrap-br");
+                                       webkit_dom_node_insert_before (
+                                               webkit_dom_node_get_parent_node (node),
+                                               WEBKIT_DOM_NODE (element),
+                                               node,
+                                               NULL);
+                                       len = anchor_length;
+                               } else
+                                       len += anchor_length;
+
+                               g_free (text_content);
+                               /* If there is space after the anchor don't try to
+                                * wrap before it */
+                               node = webkit_dom_node_get_next_sibling (node);
+                               if (WEBKIT_DOM_IS_TEXT (node)) {
+                                       text_content = webkit_dom_node_get_text_content (node);
+                                       if (g_strcmp0 (text_content, " ") == 0) {
+                                               node = webkit_dom_node_get_next_sibling (node);
+                                               len++;
+                                       }
+                                       g_free (text_content);
+                               }
+                               continue;
+                       }
+
+                       /* When we are not removing user-entered BR elements (lines wrapped by user),
+                        * we need to skip those elements */
+                       if (!remove_all_br && WEBKIT_DOM_IS_HTML_BR_ELEMENT (node)) {
+                               if (!element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-wrap-br")) {
+                                       len = 0;
+                                       node = webkit_dom_node_get_next_sibling (node);
+                                       continue;
+                               }
+                       }
+                       goto next_node;
+               }
+
+               /* If length of this node + what we already have is still less
+                * then word_wrap_length characters, then just join it and continue to next
+                * node */
+               length_left = webkit_dom_character_data_get_length (
+                       WEBKIT_DOM_CHARACTER_DATA (node));
+
+               if ((length_left + len) < word_wrap_length) {
+                       len += length_left;
+                       goto next_node;
+               }
+
+               /* wrap until we have something */
+               while ((length_left + len) > word_wrap_length) {
+                       gint max_length;
+
+                       max_length = word_wrap_length - len;
+                       if (max_length < 0)
+                               max_length = word_wrap_length;
+                       /* Find where we can line-break the node so that it
+                        * effectively fills the rest of current row */
+                       offset = find_where_to_break_line (
+                               node, max_length, word_wrap_length);
+
+                       element = webkit_dom_document_create_element (document, "BR", NULL);
+                       element_add_class (element, "-x-evo-wrap-br");
+
+                       if (offset > 0 && offset <= word_wrap_length) {
+                               if (offset != length_left)
+                                       webkit_dom_text_split_text (
+                                               WEBKIT_DOM_TEXT (node), offset, NULL);
+
+                               if (webkit_dom_node_get_next_sibling (node)) {
+                                       gchar *nd_content;
+                                       WebKitDOMNode *nd = webkit_dom_node_get_next_sibling (node);
+
+                                       nd = webkit_dom_node_get_next_sibling (node);
+                                       nd_content = webkit_dom_node_get_text_content (nd);
+                                       if (nd_content && *nd_content) {
+                                               if (g_str_has_prefix (nd_content, " "))
+                                                       webkit_dom_character_data_replace_data (
+                                                               WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "", 
NULL);
+                                               g_free (nd_content);
+                                               nd_content = webkit_dom_node_get_text_content (nd);
+                                               if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
+                                                       remove_node (nd);
+                                               g_free (nd_content);
+                                       }
+
+                                       webkit_dom_node_insert_before (
+                                               webkit_dom_node_get_parent_node (node),
+                                               WEBKIT_DOM_NODE (element),
+                                               nd,
+                                               NULL);
+                               } else {
+                                       webkit_dom_node_append_child (
+                                               webkit_dom_node_get_parent_node (node),
+                                               WEBKIT_DOM_NODE (element),
+                                               NULL);
+                               }
+                       } else if (offset > word_wrap_length) {
+                               if (offset != length_left)
+                                       webkit_dom_text_split_text (
+                                               WEBKIT_DOM_TEXT (node), offset + 1, NULL);
+
+                               if (webkit_dom_node_get_next_sibling (node)) {
+                                       gchar *nd_content;
+                                       WebKitDOMNode *nd = webkit_dom_node_get_next_sibling (node);
+
+                                       nd = webkit_dom_node_get_next_sibling (node);
+                                       nd_content = webkit_dom_node_get_text_content (nd);
+                                       if (nd_content && *nd_content) {
+                                               if (g_str_has_prefix (nd_content, " "))
+                                                       webkit_dom_character_data_replace_data (
+                                                               WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "", 
NULL);
+                                               g_free (nd_content);
+                                               nd_content = webkit_dom_node_get_text_content (nd);
+                                               if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
+                                                       remove_node (nd);
+                                               g_free (nd_content);
+                                       }
+
+                                       webkit_dom_node_insert_before (
+                                               webkit_dom_node_get_parent_node (node),
+                                               WEBKIT_DOM_NODE (element),
+                                               nd,
+                                               NULL);
+                               } else {
+                                       webkit_dom_node_append_child (
+                                               webkit_dom_node_get_parent_node (node),
+                                               WEBKIT_DOM_NODE (element),
+                                               NULL);
+                               }
+                               len = 0;
+                               break;
+                       } else {
+                               webkit_dom_node_insert_before (
+                                       webkit_dom_node_get_parent_node (node),
+                                       WEBKIT_DOM_NODE (element),
+                                       node,
+                                       NULL);
+                       }
+                       length_left = webkit_dom_character_data_get_length (
+                               WEBKIT_DOM_CHARACTER_DATA (node));
+
+                       len = 0;
+               }
+               len += length_left - offset;
+ next_node:
+               if (WEBKIT_DOM_IS_HTML_LI_ELEMENT (node))
+                       len = 0;
+
+               /* Move to next node */
+               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 {
+                       if (webkit_dom_node_is_equal_node (node, start_node))
+                               break;
+
+                       node = webkit_dom_node_get_parent_node (node);
+                       if (node)
+                               node = webkit_dom_node_get_next_sibling (node);
+               }
+       }
+
+       if (has_selection) {
+               gchar *html;
+
+               /* Create a wrapper DIV and put the processed content into it */
+               element = webkit_dom_document_create_element (document, "DIV", NULL);
+               element_add_class (element, "-x-evo-paragraph");
+               webkit_dom_node_append_child (
+                       WEBKIT_DOM_NODE (element),
+                       WEBKIT_DOM_NODE (start_node),
+                       NULL);
+
+               webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
+               /* Get HTML code of the processed content */
+               html = webkit_dom_html_element_get_inner_html (WEBKIT_DOM_HTML_ELEMENT (element));
+
+               /* Overwrite the current selection be the processed content */
+               e_html_editor_selection_insert_html (selection, html);
+
+               g_free (html);
+
+               return NULL;
+       } else {
+               webkit_dom_node_normalize (paragraph_clone);
+
+               node = webkit_dom_node_get_parent_node (paragraph);
+               if (node) {
+                       /* Replace paragraph with wrapped one */
+                       webkit_dom_node_replace_child (
+                               node, paragraph_clone, paragraph, NULL);
+               }
+
+               return WEBKIT_DOM_ELEMENT (paragraph_clone);
+       }
+}
+
+static WebKitDOMElement *
+e_html_editor_selection_get_paragraph_element (WebKitDOMDocument *document,
+                                               gint width,
+                                               gint offset)
+{
+       WebKitDOMElement *element;
+
+       element = webkit_dom_document_create_element (document, "DIV", NULL);
+       e_html_editor_selection_dom_set_paragraph_style (document, element, width, offset, "");
+
+       return element;
+}
+
+static WebKitDOMElement *
+e_html_editor_selection_put_node_into_paragraph (WebKitDOMDocument *document,
+                                                 WebKitDOMNode *node,
+                                                 WebKitDOMNode *caret_position)
+{
+       WebKitDOMRange *range;
+       WebKitDOMElement *container;
+
+       range = webkit_dom_document_create_range (document);
+       container = e_html_editor_selection_get_paragraph_element (document, -1, 0);
+       webkit_dom_range_select_node (range, node, NULL);
+       webkit_dom_range_surround_contents (range, WEBKIT_DOM_NODE (container), NULL);
+       /* We have to move caret position inside this container */
+       webkit_dom_node_append_child (WEBKIT_DOM_NODE (container), caret_position, NULL);
+
+       return container;
+}
+
+/**
+ * e_html_editor_selection_wrap_lines:
+ * @selection: an #EHTMLEditorSelection
+ *
+ * Wraps all lines in current selection to be 71 characters long.
+ */
+#if 0
+void
+e_html_editor_selection_wrap_lines (WebKitDOMDocument *document)
+{
+       WebKitDOMRange *range;
+       WebKitDOMElement *active_paragraph, *caret;
+
+       caret = e_html_editor_selection_dom_save_caret_position (document);
+       if (e_html_editor_selection_is_collapsed (selection)) {
+               WebKitDOMNode *end_container;
+               WebKitDOMNode *parent;
+               WebKitDOMNode *paragraph;
+               gchar *text_content;
+
+               /* We need to save caret position and restore it after
+                * wrapping the selection, but we need to save it before we
+                * start to modify selection */
+               range = html_editor_selection_get_current_range (selection);
+               if (!range)
+                       return;
+
+               end_container = webkit_dom_range_get_common_ancestor_container (range, NULL);
+
+               /* Wrap only text surrounded in DIV and P tags */
+               parent = webkit_dom_node_get_parent_node(end_container);
+               if (WEBKIT_DOM_IS_HTML_DIV_ELEMENT (parent) ||
+                   WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT (parent)) {
+                       element_add_class (
+                               WEBKIT_DOM_ELEMENT (parent), "-x-evo-paragraph");
+                       paragraph = parent;
+               } else {
+                       WebKitDOMElement *parent_div =
+                               e_html_editor_dom_node_find_parent_element (parent, "DIV");
+
+                       if (element_has_class (parent_div, "-x-evo-paragraph")) {
+                               paragraph = WEBKIT_DOM_NODE (parent_div);
+                       } else {
+                               if (!caret)
+                                       return;
+
+                               /* We try to select previous sibling */
+                               paragraph = webkit_dom_node_get_previous_sibling (
+                                       WEBKIT_DOM_NODE (caret));
+                               if (paragraph) {
+                                       /* When there is just text without container
+                                        * we have to surround it with paragraph div */
+                                       if (WEBKIT_DOM_IS_TEXT (paragraph))
+                                               paragraph = WEBKIT_DOM_NODE (
+                                                       e_html_editor_selection_put_node_into_paragraph (
+                                                               selection, document, paragraph,
+                                                               WEBKIT_DOM_NODE (caret)));
+                               } else {
+                                       /* When some weird element is selected, return */
+                                       e_html_editor_selection_clear_caret_position_marker (selection);
+                                       return;
+                               }
+                       }
+               }
+
+               if (!paragraph)
+                       return;
+
+               webkit_dom_element_remove_attribute (
+                       WEBKIT_DOM_ELEMENT (paragraph), "style");
+               webkit_dom_element_set_id (
+                       WEBKIT_DOM_ELEMENT (paragraph), "-x-evo-active-paragraph");
+
+               text_content = webkit_dom_node_get_text_content (paragraph);
+               /* If there is hidden space character in the beginning we remove it */
+               if (strstr (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+                       if (g_str_has_prefix (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+                               WebKitDOMNode *node;
+
+                               node = webkit_dom_node_get_first_child (paragraph);
+
+                               webkit_dom_character_data_delete_data (
+                                       WEBKIT_DOM_CHARACTER_DATA (node),
+                                       0,
+                                       1,
+                                       NULL);
+                       }
+                       if (g_str_has_suffix (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
+                               WebKitDOMNode *node;
+
+                               node = webkit_dom_node_get_last_child (paragraph);
+
+                               webkit_dom_character_data_delete_data (
+                                       WEBKIT_DOM_CHARACTER_DATA (node),
+                                       g_utf8_strlen (text_content, -1) -1,
+                                       1,
+                                       NULL);
+                       }
+               }
+               g_free (text_content);
+
+               wrap_lines (
+                       NULL, paragraph, document, FALSE,
+                       selection->priv->word_wrap_length);
+
+       } else {
+               e_html_editor_selection_save_caret_position (selection);
+               /* If we have selection -> wrap it */
+               wrap_lines (
+                       selection, NULL, document, FALSE,
+                       selection->priv->word_wrap_length);
+       }
+
+       active_paragraph = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-active-paragraph");
+       /* We have to move caret on position where it was before modifying the text */
+       e_html_editor_selection_restore_caret_position (selection);
+
+       /* Set paragraph as non-active */
+       if (active_paragraph)
+               webkit_dom_element_remove_attribute (
+                       WEBKIT_DOM_ELEMENT (active_paragraph), "id");
+}
+#endif
+static WebKitDOMElement *
+e_html_editor_selection_wrap_paragraph_length (WebKitDOMDocument *document,
+                                               WebKitDOMElement *paragraph,
+                                               gint length)
+{
+       g_return_val_if_fail (WEBKIT_DOM_IS_ELEMENT (paragraph), NULL);
+       g_return_val_if_fail (length >= MINIMAL_PARAGRAPH_WIDTH, NULL);
+
+       return wrap_lines (WEBKIT_DOM_NODE (paragraph), document, FALSE, length);
+}
+
+static gint
+get_citation_level (WebKitDOMNode *node)
+{
+       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
+       gint level = 0;
+
+       while (parent && !WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
+               if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
+                   webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (parent), "type"))
+                       level++;
+
+               parent = webkit_dom_node_get_parent_node (parent);
+       }
+
+       return level;
+}
+
+static void
+e_html_editor_selection_wrap_paragraphs_in_document (WebKitDOMDocument *document)
+{
+       WebKitDOMNodeList *list;
+       gint ii, length;
+
+       list = webkit_dom_document_query_selector_all (
+               document, "div.-x-evo-paragraph:not(#-x-evo-input-start)", NULL);
+
+       length = webkit_dom_node_list_get_length (list);
+
+       for (ii = 0; ii < length; ii++) {
+               gint quote, citation_level;
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+
+               citation_level = get_citation_level (node);
+               quote = citation_level ? citation_level * 2 : 0;
+
+               if (node_is_list (node)) {
+                       WebKitDOMNode *item = webkit_dom_node_get_first_child (node);
+
+                       while (item && WEBKIT_DOM_IS_HTML_LI_ELEMENT (item)) {
+                               e_html_editor_selection_wrap_paragraph_length (
+                                       document, WEBKIT_DOM_ELEMENT (item), WORD_WRAP_LENGTH - quote);
+                               item = webkit_dom_node_get_next_sibling (item);
+                       }
+               } else {
+                       e_html_editor_selection_wrap_paragraph_length (
+                               document, WEBKIT_DOM_ELEMENT (node), WORD_WRAP_LENGTH - quote);
+               }
+       }
+       g_object_unref (list);
+}
+
+static WebKitDOMElement *
+e_html_editor_selection_wrap_paragraph (WebKitDOMDocument *document,
+                                        WebKitDOMElement *paragraph)
+{
+       gint indentation_level, citation_level, quote;
+       gint final_width, offset = 0;
+
+       g_return_val_if_fail (WEBKIT_DOM_IS_ELEMENT (paragraph), NULL);
+
+       indentation_level = get_indentation_level (paragraph);
+       citation_level = get_citation_level (WEBKIT_DOM_NODE (paragraph));
+
+       if (node_is_list_or_item (WEBKIT_DOM_NODE (paragraph))) {
+               gint list_level = get_list_level (WEBKIT_DOM_NODE (paragraph));
+               indentation_level = 0;
+
+               if (list_level > 0)
+                       offset = list_level * -SPACES_PER_LIST_LEVEL;
+               else
+                       offset = -SPACES_PER_LIST_LEVEL;
+       }
+
+       quote = citation_level ? citation_level * 2 : 0;
+
+       final_width = WORD_WRAP_LENGTH - quote + offset;
+       final_width -= SPACES_PER_INDENTATION * indentation_level;
+
+       return e_html_editor_selection_wrap_paragraph_length (
+               document, WEBKIT_DOM_ELEMENT (paragraph), final_width);
+}
+
+void
+e_html_editor_selection_dom_scroll_to_caret (WebKitDOMDocument *document)
+{
+       glong element_top, element_left;
+       glong window_top, window_left, window_right, window_bottom;
+       WebKitDOMDOMWindow *window;
+       WebKitDOMElement *selection_start_marker;
+
+       e_html_editor_selection_dom_save (document);
+
+       selection_start_marker = webkit_dom_document_get_element_by_id (
+               document, "-x-evo-selection-start-marker");
+       if (!selection_start_marker)
+               return;
+
+       window = webkit_dom_document_get_default_view (document);
+
+       window_top = webkit_dom_dom_window_get_scroll_y (window);
+       window_left = webkit_dom_dom_window_get_scroll_x (window);
+       window_bottom = window_top + webkit_dom_dom_window_get_inner_height (window);
+       window_right = window_left + webkit_dom_dom_window_get_inner_width (window);
+
+       element_left = webkit_dom_element_get_offset_left (selection_start_marker);
+       element_top = webkit_dom_element_get_offset_top (selection_start_marker);
+
+       /* Check if caret is inside viewport, if not move to it */
+       if (!(element_top >= window_top && element_top <= window_bottom &&
+            element_left >= window_left && element_left <= window_right)) {
+               webkit_dom_element_scroll_into_view (selection_start_marker, TRUE);
+       }
+
+       e_html_editor_selection_dom_restore (selection);
+}
+
+/**
+ * e_html_editor_selection_insert_html:
+ * @selection: an #EHTMLEditorSelection
+ * @html_text: an HTML code to insert
+ *
+ * Insert @html_text into document at current cursor position. When a text range
+ * is selected, it will be replaced by @html_text.
+ */
+void
+e_html_editor_selection_insert_html (WebKitDOMDocument *document,
+                                     const gchar *html_text)
+{
+       g_return_if_fail (html_text != NULL);
+
+       command = E_HTML_EDITOR_VIEW_COMMAND_INSERT_HTML;
+       if (is_in_html_mode (document)) {
+               e_html_editor_view_dom_exec_command (document, command, html_text);
+               e_html_editor_view_check_magic_links (view, FALSE);
+               e_html_editor_view_force_spell_check (view);
+
+               e_html_editor_selection_dom_scroll_to_caret (selection);
+       } else
+               e_html_editor_view_convert_and_insert_html_to_plain_text (
+                       view, html_text);
+}
+
diff --git a/e-util/e-html-editor-selection-dom-functions.h b/e-util/e-html-editor-selection-dom-functions.h
index 4dfafc9..1ead76a 100644
--- a/e-util/e-html-editor-selection-dom-functions.h
+++ b/e-util/e-html-editor-selection-dom-functions.h
@@ -60,6 +60,12 @@ void         e_html_editor_selection_dom_create_link
                                                (WebKitDOMDocument *document,
                                                 const gchar *uri);
 
+void           e_html_editor_selection_dom_save
+                                               (WebKitDOMDocument *document);
+
+void           e_html_editor_selection_dom_restore
+                                               (WebKitDOMDocument *document);
+
 G_END_DECLS
 
 #endif /* E_HTML_EDITOR_SELECTION_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-selection.c b/e-util/e-html-editor-selection.c
index eaab241..d3a3e73 100644
--- a/e-util/e-html-editor-selection.c
+++ b/e-util/e-html-editor-selection.c
@@ -990,28 +990,6 @@ e_html_editor_selection_replace_caret_word (EHTMLEditorSelection *selection,
 }
 
 /**
- * e_html_editor_selection_is_collapsed:
- * @selection: an #EHTMLEditorSelection
- *
- * Returns if selection is collapsed.
- *
- * Returns: Whether the selection is collapsed (just caret) or not (someting is selected).
- */
-gboolean
-e_html_editor_selection_is_collapsed (EHTMLEditorSelection *selection)
-{
-       WebKitDOMRange *range;
-
-       g_return_val_if_fail (E_IS_HTML_EDITOR_SELECTION (selection), TRUE);
-
-       range = html_editor_selection_get_current_range (selection);
-       if (!range)
-               return TRUE;
-
-       return webkit_dom_range_get_collapsed (range, NULL);
-}
-
-/**
  * e_html_editor_selection_get_string:
  * @selection: an #EHTMLEditorSelection
  *
@@ -1082,38 +1060,6 @@ e_html_editor_selection_get_list_alignment_from_node (WebKitDOMNode *node)
        return E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
 }
 
-static EHTMLEditorSelectionAlignment
-e_html_editor_selection_get_alignment_from_node (WebKitDOMNode *node)
-{
-       EHTMLEditorSelectionAlignment alignment;
-       gchar *value;
-       WebKitDOMCSSStyleDeclaration *style;
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-
-       document = webkit_dom_node_get_owner_document (node);
-       window = webkit_dom_document_get_default_view (document);
-
-       style = webkit_dom_dom_window_get_computed_style (
-               window, WEBKIT_DOM_ELEMENT (node), NULL);
-       value = webkit_dom_css_style_declaration_get_property_value (style, "text-align");
-
-       if (!value || !*value ||
-           (g_ascii_strncasecmp (value, "left", 4) == 0)) {
-               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
-       } else if (g_ascii_strncasecmp (value, "center", 6) == 0) {
-               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_CENTER;
-       } else if (g_ascii_strncasecmp (value, "right", 5) == 0) {
-               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_RIGHT;
-       } else {
-               alignment = E_HTML_EDITOR_SELECTION_ALIGNMENT_LEFT;
-       }
-
-       g_free (value);
-
-       return alignment;
-}
-
 /**
  * e_html_editor_selection_get_alignment:
  * @selection: #an EHTMLEditorSelection
@@ -1284,27 +1230,6 @@ set_block_alignment (WebKitDOMElement *element,
        }
 }
 
-static WebKitDOMNode *
-get_parent_block_node_from_child (WebKitDOMNode *node)
-{
-       WebKitDOMElement *parent = WEBKIT_DOM_ELEMENT (
-               webkit_dom_node_get_parent_node (node));
-
-        if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (parent) ||
-            element_has_tag (parent, "b") ||
-            element_has_tag (parent, "i") ||
-            element_has_tag (parent, "u"))
-               parent = WEBKIT_DOM_ELEMENT (
-                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent)));
-
-       if (element_has_class (parent, "-x-evo-temp-text-wrapper") ||
-           element_has_class (parent, "-x-evo-signature"))
-               parent = WEBKIT_DOM_ELEMENT (
-                       webkit_dom_node_get_parent_node (WEBKIT_DOM_NODE (parent)));
-
-       return WEBKIT_DOM_NODE (parent);
-}
-
 /**
  * e_html_editor_selection_set_alignment:
  * @selection: an #EHTMLEditorSelection
@@ -1574,64 +1499,6 @@ e_html_editor_selection_get_block_format (EHTMLEditorSelection *selection)
        return result;
 }
 
-static gboolean
-is_selection_position_node (WebKitDOMNode *node)
-{
-       WebKitDOMElement *element;
-
-       if (!node || !WEBKIT_DOM_IS_ELEMENT (node))
-               return FALSE;
-
-       element = WEBKIT_DOM_ELEMENT (node);
-
-       return element_has_id (element, "-x-evo-caret-position") ||
-              element_has_id (element, "-x-evo-selection-start-marker") ||
-              element_has_id (element, "-x-evo-selection-end-marker");
-}
-
-static void
-merge_list_into_list (WebKitDOMNode *from,
-                      WebKitDOMNode *to,
-                      gboolean insert_before)
-{
-       WebKitDOMNode *item;
-
-       if (!(to && from))
-               return;
-
-       while ((item = webkit_dom_node_get_first_child (from)) != NULL) {
-               if (insert_before)
-                       webkit_dom_node_insert_before (
-                               to, item, webkit_dom_node_get_last_child (to), NULL);
-               else
-                       webkit_dom_node_append_child (to, item, NULL);
-       }
-
-       if (!webkit_dom_node_has_child_nodes (from))
-               remove_node (from);
-
-}
-
-static void
-merge_lists_if_possible (WebKitDOMNode *list)
-{
-       EHTMLEditorSelectionBlockFormat format, prev, next;
-       WebKitDOMNode *prev_sibling, *next_sibling;
-
-       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 = e_html_editor_selection_get_list_format_from_node (list),
-       prev = e_html_editor_selection_get_list_format_from_node (prev_sibling);
-       next = e_html_editor_selection_get_list_format_from_node (next_sibling);
-
-       if (format == prev && format != -1 && prev != -1)
-               merge_list_into_list (prev_sibling, list, TRUE);
-
-       if (format == next && format != -1 && next != -1)
-               merge_list_into_list (next_sibling, list, FALSE);
-}
-
 static void
 remove_wrapping_from_element (WebKitDOMElement *element)
 {
@@ -1690,23 +1557,6 @@ remove_quoting_from_element (WebKitDOMElement *element)
        webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
 }
 
-static gint
-get_citation_level (WebKitDOMNode *node)
-{
-       WebKitDOMNode *parent = webkit_dom_node_get_parent_node (node);
-       gint level = 0;
-
-       while (parent && !WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
-               if (WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (parent) &&
-                   webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (parent), "type"))
-                       level++;
-
-               parent = webkit_dom_node_get_parent_node (parent);
-       }
-
-       return level;
-}
-
 static gboolean
 is_citation_node (WebKitDOMNode *node)
 {
@@ -2592,37 +2442,6 @@ e_html_editor_selection_is_citation (EHTMLEditorSelection *selection)
        return ret_val;
 }
 
-static WebKitDOMNode *
-get_parent_indented_block (WebKitDOMNode *node)
-{
-       WebKitDOMNode *parent, *block = NULL;
-
-       parent = webkit_dom_node_get_parent_node (node);
-       if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented"))
-               block = parent;
-
-       while (parent && !WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
-               if (element_has_class (WEBKIT_DOM_ELEMENT (parent), "-x-evo-indented"))
-                       block = parent;
-               parent = webkit_dom_node_get_parent_node (parent);
-       }
-
-       return block;
-}
-
-static WebKitDOMElement*
-get_element_for_inspection (WebKitDOMRange *range)
-{
-       WebKitDOMNode *node;
-
-       node = webkit_dom_range_get_end_container (range, NULL);
-       /* No selection or whole body selected */
-       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (node))
-               return NULL;
-
-       return WEBKIT_DOM_ELEMENT (get_parent_indented_block (node));
-}
-
 /**
  * e_html_editor_selection_is_indented:
  * @selection: an #EHTMLEditorSelection
@@ -4301,1088 +4120,6 @@ e_html_editor_selection_restore_caret_position (EHTMLEditorSelection *selection)
        e_html_editor_selection_unblock_selection_changed (selection);
 }
 
-static gint
-find_where_to_break_line (WebKitDOMNode *node,
-                          gint max_len,
-                         gint word_wrap_length)
-{
-       gchar *str, *text_start;
-       gunichar uc;
-       gint pos;
-       gint last_space = 0;
-       gint length;
-       gint ret_val = 0;
-       gchar* position;
-
-       text_start =  webkit_dom_character_data_get_data (WEBKIT_DOM_CHARACTER_DATA (node));
-       length = g_utf8_strlen (text_start, -1);
-
-       pos = 1;
-       last_space = 0;
-       str = text_start;
-       do {
-               uc = g_utf8_get_char (str);
-               if (!uc) {
-                       g_free (text_start);
-                       if (pos <= max_len)
-                               return pos;
-                       else
-                               return last_space;
-               }
-
-               /* If last_space is zero then the word is longer than
-                * word_wrap_length characters, so continue until we find
-                * a space */
-               if ((pos > max_len) && (last_space > 0)) {
-                       if (last_space > word_wrap_length) {
-                               g_free (text_start);
-                               return last_space - 1;
-                       }
-
-                       if (last_space > max_len) {
-                               if (g_unichar_isspace (g_utf8_get_char (text_start)))
-                                       ret_val = 1;
-
-                               g_free (text_start);
-                               return ret_val;
-                       }
-
-                       if (last_space == max_len - 1) {
-                               uc = g_utf8_get_char (str);
-                               if (g_unichar_isspace (uc) || str[0] == '-')
-                                       last_space++;
-                       }
-
-                       g_free (text_start);
-                       return last_space;
-               }
-
-               if (g_unichar_isspace (uc) || str[0] == '-')
-                       last_space = pos;
-
-               pos += 1;
-               str = g_utf8_next_char (str);
-       } while (*str);
-
-       position = g_utf8_offset_to_pointer (text_start, max_len);
-
-       if (g_unichar_isspace (g_utf8_get_char (position))) {
-               ret_val = max_len + 1;
-       } else {
-               if (last_space == 0) {
-                       /* If word is longer than word_wrap_length, we cannot wrap it */
-                       ret_val = length;
-               } else if (last_space < max_len) {
-                       ret_val = last_space;
-               } else {
-                       if (length > word_wrap_length)
-                               ret_val = last_space;
-                       else
-                               ret_val = 0;
-               }
-       }
-
-       g_free (text_start);
-
-       return ret_val;
-}
-
-static WebKitDOMElement *
-wrap_lines (EHTMLEditorSelection *selection,
-           WebKitDOMNode *paragraph,
-           WebKitDOMDocument *document,
-           gboolean remove_all_br,
-           gint word_wrap_length)
-{
-       WebKitDOMNode *node, *start_node;
-       WebKitDOMNode *paragraph_clone;
-       WebKitDOMDocumentFragment *fragment;
-       WebKitDOMElement *element;
-       WebKitDOMNodeList *wrap_br;
-       gint len, ii, br_count;
-       gulong length_left;
-       glong paragraph_char_count;
-       gchar *text_content;
-
-       if (selection) {
-               paragraph_char_count = g_utf8_strlen (
-                       e_html_editor_selection_get_string (selection), -1);
-
-               fragment = webkit_dom_range_clone_contents (
-                       html_editor_selection_get_current_range (selection), NULL);
-
-               /* Select all BR elements or just ours that are used for wrapping.
-                * We are not removing user BR elements when this function is activated
-                * from Format->Wrap Lines action */
-               wrap_br = webkit_dom_document_fragment_query_selector_all (
-                       fragment,
-                       remove_all_br ? "br" : "br.-x-evo-wrap-br",
-                       NULL);
-               br_count = webkit_dom_node_list_get_length (wrap_br);
-               /* And remove them */
-               for (ii = 0; ii < br_count; ii++)
-                       remove_node (webkit_dom_node_list_item (wrap_br, ii));
-               g_object_unref (wrap_br);
-       } else {
-               if (!webkit_dom_node_has_child_nodes (paragraph))
-                       return WEBKIT_DOM_ELEMENT (paragraph);
-
-               paragraph_clone = webkit_dom_node_clone_node (paragraph, TRUE);
-               element = webkit_dom_element_query_selector (
-                       WEBKIT_DOM_ELEMENT (paragraph_clone),
-                       "span#-x-evo-caret-position",
-                       NULL);
-               text_content = webkit_dom_node_get_text_content (paragraph_clone);
-               paragraph_char_count = g_utf8_strlen (text_content, -1);
-               if (element)
-                       paragraph_char_count--;
-               g_free (text_content);
-
-               /* When we wrap, we are wrapping just the text after caret, text
-                * before the caret is already wrapped, so unwrap the text after
-                * the caret position */
-               element = webkit_dom_element_query_selector (
-                       WEBKIT_DOM_ELEMENT (paragraph_clone),
-                       "span#-x-evo-selection-end-marker",
-                       NULL);
-
-               if (element) {
-                       WebKitDOMNode *nd = WEBKIT_DOM_NODE (element);
-
-                       while (nd) {
-                               WebKitDOMNode *next_nd = webkit_dom_node_get_next_sibling (nd);
-                               if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) {
-                                       if (remove_all_br)
-                                               remove_node (nd);
-                                       else if (element_has_class (WEBKIT_DOM_ELEMENT (nd), 
"-x-evo-wrap-br"))
-                                               remove_node (nd);
-                               }
-                               nd = next_nd;
-                       }
-               }
-       }
-
-       if (selection) {
-               node = WEBKIT_DOM_NODE (fragment);
-               start_node = node;
-       } else {
-               webkit_dom_node_normalize (paragraph_clone);
-               node = webkit_dom_node_get_first_child (paragraph_clone);
-               if (node) {
-                       text_content = webkit_dom_node_get_text_content (node);
-                       if (g_strcmp0 ("\n", text_content) == 0)
-                               node = webkit_dom_node_get_next_sibling (node);
-                       g_free (text_content);
-               }
-
-               /* We have to start from the end of the last wrapped line */
-               element = webkit_dom_element_query_selector (
-                       WEBKIT_DOM_ELEMENT (paragraph_clone),
-                       "span#-x-evo-selection-start-marker",
-                       NULL);
-
-               if (element) {
-                       WebKitDOMNode *nd = WEBKIT_DOM_NODE (element);
-
-                       while ((nd = webkit_dom_node_get_previous_sibling (nd))) {
-                               if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (nd)) {
-                                       element = WEBKIT_DOM_ELEMENT (nd);
-                                       break;
-                               } else
-                                       element = NULL;
-                       }
-               }
-
-               if (element) {
-                       node = webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element));
-                       start_node = paragraph_clone;
-               } else
-                       start_node = node;
-       }
-
-       len = 0;
-       while (node) {
-               gint offset = 0;
-
-               if (WEBKIT_DOM_IS_TEXT (node)) {
-                       const gchar *newline;
-                       WebKitDOMNode *next_sibling;
-
-                       /* If there is temporary hidden space we remove it */
-                       text_content = webkit_dom_node_get_text_content (node);
-                       if (strstr (text_content, UNICODE_ZERO_WIDTH_SPACE)) {
-                               if (g_str_has_prefix (text_content, UNICODE_ZERO_WIDTH_SPACE))
-                                       webkit_dom_character_data_delete_data (
-                                               WEBKIT_DOM_CHARACTER_DATA (node),
-                                               0,
-                                               1,
-                                               NULL);
-                               if (g_str_has_suffix (text_content, UNICODE_ZERO_WIDTH_SPACE))
-                                       webkit_dom_character_data_delete_data (
-                                               WEBKIT_DOM_CHARACTER_DATA (node),
-                                               g_utf8_strlen (text_content, -1) - 1,
-                                               1,
-                                               NULL);
-                               g_free (text_content);
-                               text_content = webkit_dom_node_get_text_content (node);
-                       }
-                       newline = g_strstr_len (text_content, -1, "\n");
-
-                       next_sibling = node;
-                       while (newline) {
-                               next_sibling = WEBKIT_DOM_NODE (webkit_dom_text_split_text (
-                                       WEBKIT_DOM_TEXT (next_sibling),
-                                       g_utf8_pointer_to_offset (text_content, newline),
-                                       NULL));
-
-                               if (!next_sibling)
-                                       break;
-
-                               element = webkit_dom_document_create_element (
-                                       document, "BR", NULL);
-                               element_add_class (element, "-x-evo-temp-wrap-text-br");
-
-                               webkit_dom_node_insert_before (
-                                       webkit_dom_node_get_parent_node (next_sibling),
-                                       WEBKIT_DOM_NODE (element),
-                                       next_sibling,
-                                       NULL);
-
-                               g_free (text_content);
-
-                               text_content = webkit_dom_node_get_text_content (next_sibling);
-                               if (g_str_has_prefix (text_content, "\n")) {
-                                       webkit_dom_character_data_delete_data (
-                                               WEBKIT_DOM_CHARACTER_DATA (next_sibling), 0, 1, NULL);
-                                       g_free (text_content);
-                                       text_content =
-                                               webkit_dom_node_get_text_content (next_sibling);
-                               }
-                               newline = g_strstr_len (text_content, -1, "\n");
-                       }
-                       g_free (text_content);
-               } else {
-                       if (is_selection_position_node (node)) {
-                               node = webkit_dom_node_get_next_sibling (node);
-                               continue;
-                       }
-
-                       /* If element is ANCHOR we wrap it separately */
-                       if (WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT (node)) {
-                               glong anchor_length;
-
-                               text_content = webkit_dom_node_get_text_content (node);
-                               anchor_length = g_utf8_strlen (text_content, -1);
-                               if (len + anchor_length > word_wrap_length) {
-                                       if (webkit_dom_node_get_previous_sibling (node)) {
-                                               element = webkit_dom_document_create_element (
-                                                       document, "BR", NULL);
-                                               element_add_class (element, "-x-evo-wrap-br");
-                                               webkit_dom_node_insert_before (
-                                                       webkit_dom_node_get_parent_node (node),
-                                                       WEBKIT_DOM_NODE (element),
-                                                       node,
-                                                       NULL);
-                                       }
-                                       len = anchor_length;
-                               } else
-                                       len += anchor_length;
-
-                               g_free (text_content);
-                               /* If there is space after the anchor don't try to
-                                * wrap before it */
-                               node = webkit_dom_node_get_next_sibling (node);
-                               if (WEBKIT_DOM_IS_TEXT (node)) {
-                                       text_content = webkit_dom_node_get_text_content (node);
-                                       if (g_strcmp0 (text_content, " ") == 0) {
-                                               node = webkit_dom_node_get_next_sibling (node);
-                                               len++;
-                                       }
-                                       g_free (text_content);
-                               }
-                               continue;
-                       }
-
-                       /* When we are not removing user-entered BR elements (lines wrapped by user),
-                        * we need to skip those elements */
-                       if (!remove_all_br && WEBKIT_DOM_IS_HTMLBR_ELEMENT (node)) {
-                               if (!element_has_class (WEBKIT_DOM_ELEMENT (node), "-x-evo-wrap-br")) {
-                                       len = 0;
-                                       node = webkit_dom_node_get_next_sibling (node);
-                                       continue;
-                               }
-                       }
-                       goto next_node;
-               }
-
-               /* If length of this node + what we already have is still less
-                * then word_wrap_length characters, then just join it and continue to next
-                * node */
-               length_left = webkit_dom_character_data_get_length (
-                       WEBKIT_DOM_CHARACTER_DATA (node));
-
-               if ((length_left + len) < word_wrap_length) {
-                       len += length_left;
-                       goto next_node;
-               }
-
-               /* wrap until we have something */
-               while ((length_left + len) > word_wrap_length) {
-                       gint max_length;
-
-                       max_length = word_wrap_length - len;
-                       if (max_length < 0)
-                               max_length = word_wrap_length;
-                       /* Find where we can line-break the node so that it
-                        * effectively fills the rest of current row */
-                       offset = find_where_to_break_line (
-                               node, max_length, word_wrap_length);
-
-                       element = webkit_dom_document_create_element (document, "BR", NULL);
-                       element_add_class (element, "-x-evo-wrap-br");
-
-                       if (offset > 0 && offset <= word_wrap_length) {
-                               if (offset != length_left)
-                                       webkit_dom_text_split_text (
-                                               WEBKIT_DOM_TEXT (node), offset, NULL);
-
-                               if (webkit_dom_node_get_next_sibling (node)) {
-                                       gchar *nd_content;
-                                       WebKitDOMNode *nd = webkit_dom_node_get_next_sibling (node);
-
-                                       nd = webkit_dom_node_get_next_sibling (node);
-                                       nd_content = webkit_dom_node_get_text_content (nd);
-                                       if (nd_content && *nd_content) {
-                                               if (g_str_has_prefix (nd_content, " "))
-                                                       webkit_dom_character_data_replace_data (
-                                                               WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "", 
NULL);
-                                               g_free (nd_content);
-                                               nd_content = webkit_dom_node_get_text_content (nd);
-                                               if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
-                                                       remove_node (nd);
-                                               g_free (nd_content);
-                                       }
-
-                                       webkit_dom_node_insert_before (
-                                               webkit_dom_node_get_parent_node (node),
-                                               WEBKIT_DOM_NODE (element),
-                                               nd,
-                                               NULL);
-                               } else {
-                                       webkit_dom_node_append_child (
-                                               webkit_dom_node_get_parent_node (node),
-                                               WEBKIT_DOM_NODE (element),
-                                               NULL);
-                               }
-                       } else if (offset > word_wrap_length) {
-                               if (offset != length_left)
-                                       webkit_dom_text_split_text (
-                                               WEBKIT_DOM_TEXT (node), offset + 1, NULL);
-
-                               if (webkit_dom_node_get_next_sibling (node)) {
-                                       gchar *nd_content;
-                                       WebKitDOMNode *nd = webkit_dom_node_get_next_sibling (node);
-
-                                       nd = webkit_dom_node_get_next_sibling (node);
-                                       nd_content = webkit_dom_node_get_text_content (nd);
-                                       if (nd_content && *nd_content) {
-                                               if (g_str_has_prefix (nd_content, " "))
-                                                       webkit_dom_character_data_replace_data (
-                                                               WEBKIT_DOM_CHARACTER_DATA (nd), 0, 1, "", 
NULL);
-                                               g_free (nd_content);
-                                               nd_content = webkit_dom_node_get_text_content (nd);
-                                               if (g_strcmp0 (nd_content, UNICODE_NBSP) == 0)
-                                                       remove_node (nd);
-                                               g_free (nd_content);
-                                       }
-
-                                       webkit_dom_node_insert_before (
-                                               webkit_dom_node_get_parent_node (node),
-                                               WEBKIT_DOM_NODE (element),
-                                               nd,
-                                               NULL);
-                               } else {
-                                       webkit_dom_node_append_child (
-                                               webkit_dom_node_get_parent_node (node),
-                                               WEBKIT_DOM_NODE (element),
-                                               NULL);
-                               }
-                               len = 0;
-                               break;
-                       } else {
-                               webkit_dom_node_insert_before (
-                                       webkit_dom_node_get_parent_node (node),
-                                       WEBKIT_DOM_NODE (element),
-                                       node,
-                                       NULL);
-                       }
-                       length_left = webkit_dom_character_data_get_length (
-                               WEBKIT_DOM_CHARACTER_DATA (node));
-
-                       len = 0;
-               }
-               len += length_left - offset;
- next_node:
-               if (WEBKIT_DOM_IS_HTMLLI_ELEMENT (node))
-                       len = 0;
-
-               /* Move to next node */
-               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 {
-                       if (webkit_dom_node_is_equal_node (node, start_node))
-                               break;
-
-                       node = webkit_dom_node_get_parent_node (node);
-                       if (node)
-                               node = webkit_dom_node_get_next_sibling (node);
-               }
-       }
-
-       if (selection) {
-               gchar *html;
-
-               /* Create a wrapper DIV and put the processed content into it */
-               element = webkit_dom_document_create_element (document, "DIV", NULL);
-               element_add_class (element, "-x-evo-paragraph");
-               webkit_dom_node_append_child (
-                       WEBKIT_DOM_NODE (element),
-                       WEBKIT_DOM_NODE (start_node),
-                       NULL);
-
-               webkit_dom_node_normalize (WEBKIT_DOM_NODE (element));
-               /* Get HTML code of the processed content */
-               html = webkit_dom_html_element_get_inner_html (WEBKIT_DOM_HTML_ELEMENT (element));
-
-               /* Overwrite the current selection be the processed content */
-               e_html_editor_selection_insert_html (selection, html);
-
-               g_free (html);
-
-               return NULL;
-       } else {
-               webkit_dom_node_normalize (paragraph_clone);
-
-               node = webkit_dom_node_get_parent_node (paragraph);
-               if (node) {
-                       /* Replace paragraph with wrapped one */
-                       webkit_dom_node_replace_child (
-                               node, paragraph_clone, paragraph, NULL);
-               }
-
-               return WEBKIT_DOM_ELEMENT (paragraph_clone);
-       }
-}
-
-static WebKitDOMElement *
-e_html_editor_selection_get_paragraph_element (EHTMLEditorSelection *selection,
-                                               WebKitDOMDocument *document,
-                                               gint width,
-                                               gint offset)
-{
-       WebKitDOMElement *element;
-
-       element = webkit_dom_document_create_element (document, "DIV", NULL);
-       e_html_editor_selection_set_paragraph_style (selection, element, width, offset, "");
-
-       return element;
-}
-
-static WebKitDOMElement *
-e_html_editor_selection_put_node_into_paragraph (EHTMLEditorSelection *selection,
-                                                 WebKitDOMDocument *document,
-                                                 WebKitDOMNode *node,
-                                                 WebKitDOMNode *caret_position)
-{
-       WebKitDOMRange *range;
-       WebKitDOMElement *container;
-
-       range = webkit_dom_document_create_range (document);
-       container = e_html_editor_selection_get_paragraph_element (selection, document, -1, 0);
-       webkit_dom_range_select_node (range, node, NULL);
-       webkit_dom_range_surround_contents (range, WEBKIT_DOM_NODE (container), NULL);
-       /* We have to move caret position inside this container */
-       webkit_dom_node_append_child (WEBKIT_DOM_NODE (container), caret_position, NULL);
-
-       return container;
-}
-
-/**
- * e_html_editor_selection_wrap_lines:
- * @selection: an #EHTMLEditorSelection
- *
- * Wraps all lines in current selection to be 71 characters long.
- */
-void
-e_html_editor_selection_wrap_lines (EHTMLEditorSelection *selection)
-{
-       EHTMLEditorView *view;
-       gboolean after_selection_end = FALSE, html_mode;
-       WebKitDOMDocument *document;
-       WebKitDOMElement *selection_start_marker, *selection_end_marker;
-       WebKitDOMNode *block, *next_block;
-
-       g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
-
-       view = e_html_editor_selection_ref_html_editor_view (selection);
-       g_return_if_fail (view != NULL);
-
-       document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-       g_object_unref (view);
-
-       e_html_editor_selection_save (selection);
-       selection_start_marker = webkit_dom_document_query_selector (
-               document, "span#-x-evo-selection-start-marker", NULL);
-       selection_end_marker = webkit_dom_document_query_selector (
-               document, "span#-x-evo-selection-end-marker", NULL);
-
-       /* If the selection was not saved, move it into the first child of body */
-       if (!selection_start_marker || !selection_end_marker) {
-               WebKitDOMHTMLElement *body;
-               WebKitDOMNode *child;
-
-               body = webkit_dom_document_get_body (document);
-               child = webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body));
-
-               add_selection_markers_into_element_start (
-                       document,
-                       WEBKIT_DOM_ELEMENT (child),
-                       &selection_start_marker,
-                       &selection_end_marker);
-       }
-
-       block = get_parent_block_node_from_child (
-               WEBKIT_DOM_NODE (selection_start_marker));
-
-       html_mode = e_html_editor_view_get_html_mode (view);
-
-       /* Process all blocks that are in the selection one by one */
-       while (block && !after_selection_end) {
-               gboolean quoted = FALSE;
-               gint citation_level, quote;
-               WebKitDOMElement *wrapped_paragraph;
-
-               if (webkit_dom_element_query_selector (
-                       WEBKIT_DOM_ELEMENT (block), "span.-x-evo-quoted", NULL)) {
-                       quoted = TRUE;
-                       remove_quoting_from_element (WEBKIT_DOM_ELEMENT (block));
-               }
-
-               if (!html_mode)
-                       remove_wrapping_from_element (WEBKIT_DOM_ELEMENT (block));
-
-               after_selection_end = webkit_dom_node_contains (
-                       block, WEBKIT_DOM_NODE (selection_end_marker));
-
-               next_block = webkit_dom_node_get_next_sibling (block);
-
-               citation_level = get_citation_level (block);
-               quote = citation_level ? citation_level * 2 : 0;
-
-               wrapped_paragraph = e_html_editor_selection_wrap_paragraph_length (
-                       selection, WEBKIT_DOM_ELEMENT (block), selection->priv->word_wrap_length - quote);
-
-               if (quoted && !html_mode)
-                       e_html_editor_view_quote_plain_text_element (view, wrapped_paragraph);
-
-               block = next_block;
-       }
-
-       e_html_editor_selection_restore (selection);
-
-       e_html_editor_view_force_spell_check_for_current_paragraph (view);
-}
-
-static WebKitDOMElement *
-e_html_editor_selection_wrap_paragraph_length (EHTMLEditorSelection *selection,
-                                               WebKitDOMElement *paragraph,
-                                               gint length)
-{
-       WebKitDOMDocument *document;
-
-       g_return_val_if_fail (E_IS_HTML_EDITOR_SELECTION (selection), NULL);
-       g_return_val_if_fail (WEBKIT_DOM_IS_ELEMENT (paragraph), NULL);
-       g_return_val_if_fail (length >= MINIMAL_PARAGRAPH_WIDTH, NULL);
-
-       document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (paragraph));
-
-       return wrap_lines (
-               NULL, WEBKIT_DOM_NODE (paragraph), document, FALSE, length);
-}
-
-static void
-e_html_editor_selection_wrap_paragraphs_in_document (EHTMLEditorSelection *selection,
-                                                     WebKitDOMDocument *document)
-{
-       WebKitDOMNodeList *list;
-       gint ii, length;
-
-       g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
-
-       /* Only wrap paragraphs that are inside the quoted content, others are
-        * wrapped by CSS. */
-       list = webkit_dom_document_query_selector_all (
-               document,
-               "blockquote[type=cite] > div.-x-evo-paragraph:not(#-x-evo-input-start)",
-               NULL);
-
-       length = webkit_dom_node_list_get_length (list);
-
-       for (ii = 0; ii < length; ii++) {
-               gint quote, citation_level;
-               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
-
-               citation_level = get_citation_level (node);
-               quote = citation_level ? citation_level * 2 : 0;
-
-               if (node_is_list (node)) {
-                       WebKitDOMNode *item = webkit_dom_node_get_first_child (node);
-
-                       while (item && WEBKIT_DOM_IS_HTMLLI_ELEMENT (item)) {
-                               e_html_editor_selection_wrap_paragraph_length (
-                                       selection,
-                                       WEBKIT_DOM_ELEMENT (item),
-                                       selection->priv->word_wrap_length - quote);
-                               item = webkit_dom_node_get_next_sibling (item);
-                       }
-               } else {
-                       e_html_editor_selection_wrap_paragraph_length (
-                               selection,
-                               WEBKIT_DOM_ELEMENT (node),
-                               selection->priv->word_wrap_length - quote);
-               }
-       }
-       g_object_unref (list);
-}
-
-static WebKitDOMElement *
-e_html_editor_selection_wrap_paragraph (EHTMLEditorSelection *selection,
-                                        WebKitDOMElement *paragraph)
-{
-       gint indentation_level, citation_level, quote;
-       gint final_width, word_wrap_length, offset = 0;
-
-       g_return_val_if_fail (E_IS_HTML_EDITOR_SELECTION (selection), NULL);
-       g_return_val_if_fail (WEBKIT_DOM_IS_ELEMENT (paragraph), NULL);
-
-       word_wrap_length = selection->priv->word_wrap_length;
-       indentation_level = get_indentation_level (paragraph);
-       citation_level = get_citation_level (WEBKIT_DOM_NODE (paragraph));
-
-       if (node_is_list_or_item (WEBKIT_DOM_NODE (paragraph))) {
-               gint list_level = get_list_level (WEBKIT_DOM_NODE (paragraph));
-               indentation_level = 0;
-
-               if (list_level > 0)
-                       offset = list_level * -SPACES_PER_LIST_LEVEL;
-               else
-                       offset = -SPACES_PER_LIST_LEVEL;
-       }
-
-       quote = citation_level ? citation_level * 2 : 0;
-
-       final_width = word_wrap_length - quote + offset;
-       final_width -= SPACES_PER_INDENTATION * indentation_level;
-
-       return e_html_editor_selection_wrap_paragraph_length (
-               selection, WEBKIT_DOM_ELEMENT (paragraph), final_width);
-}
-
-static WebKitDOMNode *
-in_empty_block_in_quoted_content (WebKitDOMNode *element)
-{
-       WebKitDOMNode *first_child, *next_sibling;
-
-       first_child = webkit_dom_node_get_first_child (element);
-       if (!WEBKIT_DOM_IS_ELEMENT (first_child))
-               return NULL;
-
-       if (!element_has_class (WEBKIT_DOM_ELEMENT (first_child), "-x-evo-quoted"))
-               return NULL;
-
-       next_sibling = webkit_dom_node_get_next_sibling (first_child);
-       if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (next_sibling))
-               return next_sibling;
-
-       if (!WEBKIT_DOM_IS_ELEMENT (next_sibling))
-               return NULL;
-
-       if (!element_has_id (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-selection-start-marker"))
-               return NULL;
-
-       next_sibling = webkit_dom_node_get_next_sibling (next_sibling);
-       if (WEBKIT_DOM_IS_HTMLBR_ELEMENT (next_sibling))
-               return next_sibling;
-
-       return NULL;
-}
-
-/**
- * e_html_editor_selection_save:
- * @selection: an #EHTMLEditorSelection
- *
- * Saves current cursor position or current selection range. The selection can
- * be later restored by calling e_html_editor_selection_restore().
- *
- * Note that calling e_html_editor_selection_save() overwrites previously saved
- * position.
- *
- * Note that this method inserts special markings into the HTML code that are
- * used to later restore the selection. It can happen that by deleting some
- * segments of the document some of the markings are deleted too. In that case
- * restoring the selection by e_html_editor_selection_restore() can fail. Also by
- * moving text segments (Cut & Paste) can result in moving the markings
- * elsewhere, thus e_html_editor_selection_restore() will restore the selection
- * incorrectly.
- *
- * It is recommended to use this method only when you are not planning to make
- * bigger changes to content or structure of the document (formatting changes
- * are usually OK).
- */
-void
-e_html_editor_selection_save (EHTMLEditorSelection *selection)
-{
-       glong offset;
-       EHTMLEditorView *view;
-       WebKitWebView *web_view;
-       WebKitDOMDocument *document;
-       WebKitDOMRange *range;
-       WebKitDOMNode *container, *next_sibling, *marker_node;
-       WebKitDOMNode *split_node, *parent_node;
-       WebKitDOMElement *marker;
-
-       g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
-
-       view = e_html_editor_selection_ref_html_editor_view (selection);
-       g_return_if_fail (view != NULL);
-
-       web_view = WEBKIT_WEB_VIEW (view);
-
-       document = webkit_web_view_get_dom_document (web_view);
-       g_object_unref (view);
-
-       /* First remove all markers (if present) */
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-start-marker");
-       if (marker != NULL)
-               remove_node (WEBKIT_DOM_NODE (marker));
-
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-end-marker");
-       if (marker != NULL)
-               remove_node (WEBKIT_DOM_NODE (marker));
-
-       range = html_editor_selection_get_current_range (selection);
-
-       if (!range)
-               return;
-
-       marker = webkit_dom_document_create_element (document, "SPAN", NULL);
-       webkit_dom_element_set_id (marker, "-x-evo-selection-start-marker");
-
-       container = webkit_dom_range_get_start_container (range, NULL);
-       offset = webkit_dom_range_get_start_offset (range, NULL);
-       parent_node = webkit_dom_node_get_parent_node (container);
-
-       if (element_has_class (WEBKIT_DOM_ELEMENT (parent_node), "-x-evo-quote-character")) {
-               WebKitDOMNode *node;
-
-               node = webkit_dom_node_get_parent_node (
-                       webkit_dom_node_get_parent_node (parent_node));
-
-               if ((next_sibling = in_empty_block_in_quoted_content (node))) {
-                       webkit_dom_node_insert_before (
-                               webkit_dom_node_get_parent_node (next_sibling),
-                               WEBKIT_DOM_NODE (marker),
-                               next_sibling,
-                               NULL);
-                       goto end_marker;
-               }
-       }
-
-       if (WEBKIT_DOM_IS_TEXT (container)) {
-               if (offset != 0) {
-                       WebKitDOMText *split_text;
-
-                       split_text = webkit_dom_text_split_text (
-                               WEBKIT_DOM_TEXT (container), offset, NULL);
-                       split_node = WEBKIT_DOM_NODE (split_text);
-               } else {
-                       marker_node = webkit_dom_node_insert_before (
-                               parent_node,
-                               WEBKIT_DOM_NODE (marker),
-                               container,
-                               NULL);
-                       goto end_marker;
-               }
-       } else if (WEBKIT_DOM_IS_HTMLLI_ELEMENT (container)) {
-               marker_node = webkit_dom_node_insert_before (
-                       container,
-                       WEBKIT_DOM_NODE (marker),
-                       webkit_dom_node_get_first_child (container),
-                       NULL);
-               goto end_marker;
-       } else {
-               /* Insert the selection marker on the right position in
-                * an empty paragraph in the quoted content */
-               if ((next_sibling = in_empty_block_in_quoted_content (container))) {
-                       marker_node = webkit_dom_node_insert_before (
-                               container,
-                               WEBKIT_DOM_NODE (marker),
-                               next_sibling,
-                               NULL);
-                       goto end_marker;
-               }
-               if (!webkit_dom_node_get_previous_sibling (container)) {
-                       marker_node = webkit_dom_node_insert_before (
-                               container,
-                               WEBKIT_DOM_NODE (marker),
-                               webkit_dom_node_get_first_child (container),
-                               NULL);
-                       goto end_marker;
-               } else if (!webkit_dom_node_get_next_sibling (container)) {
-                       marker_node = webkit_dom_node_append_child (
-                               container,
-                               WEBKIT_DOM_NODE (marker),
-                               NULL);
-                       goto end_marker;
-               } else {
-                       if (webkit_dom_node_get_first_child (container)) {
-                               marker_node = webkit_dom_node_insert_before (
-                                       container,
-                                       WEBKIT_DOM_NODE (marker),
-                                       webkit_dom_node_get_first_child (container),
-                                       NULL);
-                               goto end_marker;
-                       }
-                       split_node = container;
-               }
-       }
-
-       /* Don't save selection straight into body */
-       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node))
-               return;
-
-       if (!split_node) {
-               marker_node = webkit_dom_node_insert_before (
-                       container,
-                       WEBKIT_DOM_NODE (marker),
-                       webkit_dom_node_get_first_child (
-                               WEBKIT_DOM_NODE (container)),
-                       NULL);
-       } else {
-               marker_node = WEBKIT_DOM_NODE (marker);
-               parent_node = webkit_dom_node_get_parent_node (split_node);
-
-               webkit_dom_node_insert_before (
-                       parent_node, marker_node, split_node, NULL);
-       }
-
- end_marker:
-       marker = webkit_dom_document_create_element (document, "SPAN", NULL);
-       webkit_dom_element_set_id (marker, "-x-evo-selection-end-marker");
-
-       if (webkit_dom_range_get_collapsed (range, NULL)) {
-               webkit_dom_node_insert_before (
-                       /* Selection start marker */
-                       webkit_dom_node_get_parent_node (marker_node),
-                       WEBKIT_DOM_NODE (marker),
-                       webkit_dom_node_get_next_sibling (marker_node),
-                       NULL);
-               return;
-       }
-
-       container = webkit_dom_range_get_end_container (range, NULL);
-       offset = webkit_dom_range_get_end_offset (range, NULL);
-       parent_node = webkit_dom_node_get_parent_node (container);
-
-       if (element_has_class (WEBKIT_DOM_ELEMENT (parent_node), "-x-evo-quote-character")) {
-               WebKitDOMNode *node;
-
-               node = webkit_dom_node_get_parent_node (
-                       webkit_dom_node_get_parent_node (parent_node));
-
-               printf ("%s\n", webkit_dom_html_element_get_outer_html (WEBKIT_DOM_HTML_ELEMENT (node)));
-               if ((next_sibling = in_empty_block_in_quoted_content (node))) {
-                       webkit_dom_node_insert_before (
-                               webkit_dom_node_get_parent_node (next_sibling),
-                               WEBKIT_DOM_NODE (marker),
-                               next_sibling,
-                               NULL);
-                       return;
-               }
-       }
-
-       if (WEBKIT_DOM_IS_TEXT (container)) {
-               if (offset != 0) {
-                       WebKitDOMText *split_text;
-
-                       split_text = webkit_dom_text_split_text (
-                               WEBKIT_DOM_TEXT (container), offset, NULL);
-                       split_node = WEBKIT_DOM_NODE (split_text);
-               } else {
-                       marker_node = webkit_dom_node_insert_before (
-                               parent_node, WEBKIT_DOM_NODE (marker), container, NULL);
-                       goto check;
-
-               }
-       } else if (WEBKIT_DOM_IS_HTMLLI_ELEMENT (container)) {
-               webkit_dom_node_append_child (
-                       container, WEBKIT_DOM_NODE (marker), NULL);
-               return;
-       } else {
-               /* Insert the selection marker on the right position in
-                * an empty paragraph in the quoted content */
-               if ((next_sibling = in_empty_block_in_quoted_content (container))) {
-                       webkit_dom_node_insert_before (
-                               container,
-                               WEBKIT_DOM_NODE (marker),
-                               next_sibling,
-                               NULL);
-                       return;
-               }
-               if (!webkit_dom_node_get_previous_sibling (container)) {
-                       split_node = parent_node;
-               } else if (!webkit_dom_node_get_next_sibling (container)) {
-                       split_node = parent_node;
-                       split_node = webkit_dom_node_get_next_sibling (split_node);
-               } else
-                       split_node = container;
-       }
-
-       /* Don't save selection straight into body */
-       if (WEBKIT_DOM_IS_HTML_BODY_ELEMENT (split_node)) {
-               marker = webkit_dom_document_get_element_by_id (
-                       document, "-x-evo-selection-start-marker");
-               remove_node (WEBKIT_DOM_NODE (marker));
-               return;
-       }
-
-       marker_node = WEBKIT_DOM_NODE (marker);
-
-       if (split_node) {
-               parent_node = webkit_dom_node_get_parent_node (split_node);
-
-               webkit_dom_node_insert_before (
-                       parent_node, marker_node, split_node, NULL);
-       } else
-               webkit_dom_node_append_child (
-                       WEBKIT_DOM_NODE (container), marker_node, NULL);
-
- check:
-       if ((next_sibling = webkit_dom_node_get_next_sibling (marker_node))) {
-               if (!WEBKIT_DOM_IS_ELEMENT (next_sibling))
-                       next_sibling = webkit_dom_node_get_next_sibling (next_sibling);
-               /* If the selection is collapsed ensure that the selection start marker
-                * is before the end marker */
-               if (next_sibling && WEBKIT_DOM_IS_ELEMENT (next_sibling) &&
-                   element_has_id (WEBKIT_DOM_ELEMENT (next_sibling), "-x-evo-selection-start-marker")) {
-                       webkit_dom_node_insert_before (
-                               webkit_dom_node_get_parent_node (marker_node),
-                               next_sibling,
-                               marker_node,
-                               NULL);
-               }
-       }
-}
-
-/**
- * e_html_editor_selection_restore:
- * @selection: an #EHTMLEditorSelection
- *
- * Restores cursor position or selection range that was saved by
- * e_html_editor_selection_save().
- *
- * Note that calling this function without calling e_html_editor_selection_save()
- * before is a programming error and the behavior is undefined.
- */
-void
-e_html_editor_selection_restore (EHTMLEditorSelection *selection)
-{
-       EHTMLEditorView *view;
-       WebKitWebView *web_view;
-       WebKitDOMDocument *document;
-       WebKitDOMElement *marker;
-       WebKitDOMNode *selection_start_marker, *selection_end_marker;
-       WebKitDOMRange *range;
-       WebKitDOMDOMSelection *dom_selection;
-       WebKitDOMDOMWindow *window;
-
-       g_return_if_fail (E_IS_HTML_EDITOR_SELECTION (selection));
-
-       view = e_html_editor_selection_ref_html_editor_view (selection);
-       g_return_if_fail (view != NULL);
-
-       web_view = WEBKIT_WEB_VIEW (view);
-
-       document = webkit_web_view_get_dom_document (web_view);
-       g_object_unref (view);
-       window = webkit_dom_document_get_default_view (document);
-       dom_selection = webkit_dom_dom_window_get_selection (window);
-       range = webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
-       if (!range)
-               return;
-
-       selection_start_marker = webkit_dom_range_get_start_container (range, NULL);
-       if (selection_start_marker) {
-               gboolean ok = FALSE;
-               selection_start_marker =
-                       webkit_dom_node_get_next_sibling (selection_start_marker);
-
-               ok = is_selection_position_node (selection_start_marker);
-
-               if (ok) {
-                       ok = FALSE;
-                       if (webkit_dom_range_get_collapsed (range, NULL)) {
-                               selection_end_marker = webkit_dom_node_get_next_sibling (
-                                       selection_start_marker);
-
-                               ok = is_selection_position_node (selection_end_marker);
-                               if (ok) {
-                                       remove_node (selection_start_marker);
-                                       remove_node (selection_end_marker);
-
-                                       return;
-                               }
-                       }
-               }
-       }
-
-       range = webkit_dom_document_create_range (document);
-       if (!range)
-               return;
-
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-start-marker");
-       if (!marker) {
-               marker = webkit_dom_document_get_element_by_id (
-                       document, "-x-evo-selection-end-marker");
-               if (marker)
-                       remove_node (WEBKIT_DOM_NODE (marker));
-               return;
-       }
-
-       webkit_dom_range_set_start_after (range, WEBKIT_DOM_NODE (marker), NULL);
-       remove_node (WEBKIT_DOM_NODE (marker));
-
-       marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-end-marker");
-       if (!marker) {
-               marker = webkit_dom_document_get_element_by_id (
-                       document, "-x-evo-selection-start-marker");
-               if (marker)
-                       remove_node (WEBKIT_DOM_NODE (marker));
-               return;
-       }
-
-       webkit_dom_range_set_end_before (range, WEBKIT_DOM_NODE (marker), NULL);
-       remove_node (WEBKIT_DOM_NODE (marker));
-
-       webkit_dom_dom_selection_remove_all_ranges (dom_selection);
-       webkit_dom_dom_selection_add_range (dom_selection, range);
-}
 
 static void
 html_editor_selection_modify (EHTMLEditorSelection *selection,
@@ -5457,42 +4194,3 @@ e_html_editor_selection_move (EHTMLEditorSelection *selection,
        html_editor_selection_modify (selection, "move", forward, granularity);
 }
 
-void
-e_html_editor_selection_scroll_to_caret (EHTMLEditorSelection *selection)
-{
-       glong element_top, element_left;
-       glong window_top, window_left, window_right, window_bottom;
-       EHTMLEditorView *view;
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMElement *selection_start_marker;
-
-       e_html_editor_selection_save (selection);
-
-       view = e_html_editor_selection_ref_html_editor_view (selection);
-       document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-       g_object_unref (view);
-
-       selection_start_marker = webkit_dom_document_get_element_by_id (
-               document, "-x-evo-selection-start-marker");
-       if (!selection_start_marker)
-               return;
-
-       window = webkit_dom_document_get_default_view (document);
-
-       window_top = webkit_dom_dom_window_get_scroll_y (window);
-       window_left = webkit_dom_dom_window_get_scroll_x (window);
-       window_bottom = window_top + webkit_dom_dom_window_get_inner_height (window);
-       window_right = window_left + webkit_dom_dom_window_get_inner_width (window);
-
-       element_left = webkit_dom_element_get_offset_left (selection_start_marker);
-       element_top = webkit_dom_element_get_offset_top (selection_start_marker);
-
-       /* Check if caret is inside viewport, if not move to it */
-       if (!(element_top >= window_top && element_top <= window_bottom &&
-            element_left >= window_left && element_left <= window_right)) {
-               webkit_dom_element_scroll_into_view (selection_start_marker, TRUE);
-       }
-
-       e_html_editor_selection_restore (selection);
-}
diff --git a/e-util/e-html-editor-table-dialog-dom-functions.c 
b/e-util/e-html-editor-table-dialog-dom-functions.c
index cc3325d..200cd71 100644
--- a/e-util/e-html-editor-table-dialog-dom-functions.c
+++ b/e-util/e-html-editor-table-dialog-dom-functions.c
@@ -20,66 +20,16 @@
 
 #include "e-dom-utils.h"
 
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMDOMSelection.h>
+#include <webkitdom/WebKitDOMDOMWindowUnstable.h>
+
 static WebKitDOMElement *
 get_current_table_element (WebKitDOMDocument *document)
 {
        return webkit_dom_document_get_element_by_id (document, "-x-evo-current-table");
 }
 
-static WebKitDOMElement *
-e_html_editor_table_dialog_create_table (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table, *br, *caret, *parent, *element;
-       gint i;
-
-       /* Default 3x3 table */
-       table = webkit_dom_document_create_element (document, "TABLE", NULL);
-       for (i = 0; i < 3; i++) {
-               WebKitDOMHTMLElement *row;
-               gint j;
-
-               row = webkit_dom_html_table_element_insert_row (
-                       WEBKIT_DOM_HTML_TABLE_ELEMENT (table), -1, NULL);
-
-               for (j = 0; j < 3; j++) {
-                       webkit_dom_html_table_row_element_insert_cell (
-                               WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row), -1, NULL);
-               }
-       }
-
-       caret = e_html_editor_selection_dom_save_caret_position (document);
-
-       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
-       element = caret;
-
-       while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
-               element = parent;
-               parent = webkit_dom_node_get_parent_element (
-                       WEBKIT_DOM_NODE (parent));
-       }
-
-       br = webkit_dom_document_create_element (document, "BR", NULL);
-       webkit_dom_node_insert_before (
-               WEBKIT_DOM_NODE (parent),
-               WEBKIT_DOM_NODE (br),
-               webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
-               NULL);
-
-       /* Insert the table into body below the caret */
-       webkit_dom_node_insert_before (
-               WEBKIT_DOM_NODE (parent),
-               WEBKIT_DOM_NODE (table),
-               webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
-               NULL);
-
-       e_html_editor_selection_dom_clear_caret_position_marker (document);
-
-       /* FIXME WK2
-       e_html_editor_view_set_changed (view, TRUE);*/
-
-       return table;
-}
-
 void
 e_html_editor_table_dialog_set_row_count (WebKitDOMDocument *document,
                                           gulong expected_count)
@@ -183,152 +133,86 @@ e_html_editor_table_dialog_get_column_count (WebKitDOMDocument *document)
        return webkit_dom_html_collection_get_length (columns);
 }
 
-void
-e_html_editor_table_dialog_set_width (WebKitDOMDocument *document,
-                                      const gchar *width)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
-
-       webkit_dom_html_table_element_set_width (table_element, width);
-}
-
-gchar *
-e_html_editor_table_dialog_get_width (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
-
-       return webkit_dom_html_table_element_get_width (table_element);
-}
-
-void
-e_html_editor_table_dialog_set_alignment (WebKitDOMDocument *document.
-                                          const gchar *value)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
-
-       webkit_dom_html_table_element_set_align (table_element, value);
-}
-
-gchar *
-e_html_editor_table_dialog_get_alignment (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
-
-       return webkit_dom_html_table_element_get_align (table_element);
-}
-
-void
-e_html_editor_table_dialog_set_padding (WebKitDOMDocument *document.
-                                        const gchar *value)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
-
-       webkit_dom_html_table_element_set_cell_padding (table_element, value);
-}
-
-gchar *
-e_html_editor_table_dialog_get_padding (WebKitDOMDocument *document)
+static
+create_table (WebKitDOMDocument *document)
 {
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
-
-       return webkit_dom_html_table_element_get_cell_padding (table_element);
-}
+       WebKitDOMElement *table, *br, *caret, *parent, *element;
+       gint i;
 
-void
-e_html_editor_table_dialog_set_spacing (WebKitDOMDocument *document.
-                                        const gchar *value)
-{
-       WebKitDOMElement *table_element;
+       /* Default 3x3 table */
+       table = webkit_dom_document_create_element (document, "TABLE", NULL);
+       for (i = 0; i < 3; i++) {
+               WebKitDOMHTMLElement *row;
+               gint j;
 
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
+               row = webkit_dom_html_table_element_insert_row (
+                       WEBKIT_DOM_HTML_TABLE_ELEMENT (table), -1, NULL);
 
-       webkit_dom_html_table_element_set_cell_spacing (table_element, value);
-}
+               for (j = 0; j < 3; j++) {
+                       webkit_dom_html_table_row_element_insert_cell (
+                               WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT (row), -1, NULL);
+               }
+       }
 
-gchar *
-e_html_editor_table_dialog_get_spacing (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table_element;
+       webkit_dom_element_set_id (table, "-x-evo-current-table");
 
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
+       caret = e_html_editor_selection_dom_save_caret_position (document);
 
-       return webkit_dom_html_table_element_get_cell_spacing (table_element);
-}
+       parent = webkit_dom_node_get_parent_element (WEBKIT_DOM_NODE (caret));
+       element = caret;
 
-void
-e_html_editor_table_dialog_set_border (WebKitDOMDocument *document.
-                                       const gchar *value)
-{
-       WebKitDOMElement *table_element;
+       while (!WEBKIT_DOM_IS_HTML_BODY_ELEMENT (parent)) {
+               element = parent;
+               parent = webkit_dom_node_get_parent_element (
+                       WEBKIT_DOM_NODE (parent));
+       }
 
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
+       br = webkit_dom_document_create_element (document, "BR", NULL);
+       webkit_dom_node_insert_before (
+               WEBKIT_DOM_NODE (parent),
+               WEBKIT_DOM_NODE (br),
+               webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
+               NULL);
 
-       webkit_dom_html_table_element_set_border (table_element, value);
-}
+       /* Insert the table into body below the caret */
+       webkit_dom_node_insert_before (
+               WEBKIT_DOM_NODE (parent),
+               WEBKIT_DOM_NODE (table),
+               webkit_dom_node_get_next_sibling (WEBKIT_DOM_NODE (element)),
+               NULL);
 
-gchar *
-e_html_editor_table_dialog_get_border (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table_element;
+       e_html_editor_selection_dom_clear_caret_position_marker (document);
 
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
+       /* FIXME WK2
+       e_html_editor_view_set_changed (view, TRUE);*/
 
-       return webkit_dom_html_table_element_get_border (table_element);
+       return table;
 }
 
-void
-e_html_editor_table_dialog_set_bg_color (WebKitDOMDocument *document.
-                                         const gchar *value)
+gboolean
+e_html_editor_table_dialog_show (WebKitDOMDocument *document)
 {
-       WebKitDOMElement *table_element;
+       WebKitDOMDOMWindow *window;
+       WebKitDOMDOMSelection *selection;
 
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return;
+       window = webkit_dom_document_get_default_view (document);
+       selection = webkit_dom_dom_window_get_selection (window);
+       if (selection && (webkit_dom_dom_selection_get_range_count (selection) > 0)) {
+               WebKitDOMElement *table;
+               WebKitDOMRange *range;
 
-       webkit_dom_html_table_element_set_bg_color (table_element, value);
-}
+               range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
+               table = e_html_editor_dom_node_find_parent_element (
+                       webkit_dom_range_get_start_container (range, NULL), "TABLE");
 
-gchar *
-e_html_editor_table_dialog_get_bg_color (WebKitDOMDocument *document)
-{
-       WebKitDOMElement *table_element;
-
-       table_element = get_current_table_element (document);
-       if (!table_element)
-               return NULL;
+               if (table) {
+                       webkit_dom_element_set_id (table, "-x-evo-current-table");
+                       return FALSE;
+               } else {
+                       create_table (document);
+                       return TRUE;
+               }
+       }
 
-       return webkit_dom_html_table_element_get_bg_color (table_element);
+       return FALSE;
 }
diff --git a/e-util/e-html-editor-table-dialog-dom-functions.h 
b/e-util/e-html-editor-table-dialog-dom-functions.h
index c27e506..d1c70d5 100644
--- a/e-util/e-html-editor-table-dialog-dom-functions.h
+++ b/e-util/e-html-editor-table-dialog-dom-functions.h
@@ -1,5 +1,5 @@
 /*
- * e-html-editor-actions-dom-functions.h
+ * e-html-editor-table-dialog-dom-functions.h
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,57 +16,29 @@
  *
  */
 
-#ifndef E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H
-#define E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H
+#ifndef E_HTML_TABLE_DIALOG_DOM_FUNCTIONS_H
+#define E_HTML_TABLE_DIALOG_DOM_FUNCTIONS_H
 
 #include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS
 
-void           e_html_editor_cell_dialog_mark_current_cell_element
+void           e_html_editor_table_dialog_set_row_count
                                                (WebKitDOMDocument *document,
-                                                const gchar *id);
+                                                gulong expected_count);
 
-void           e_html_editor_cell_dialog_set_element_v_align
-                                               (WebKitDOMDocument *document,
-                                                const gchar *v_align,
-                                                guint scope);
-
-void           e_html_editor_cell_dialog_set_element_align
-                                               (WebKitDOMDocument *document,
-                                                const gchar *align,
-                                                guint scope);
+gulong         e_html_editor_table_dialog_get_row_count
+                                               (WebKitDOMDocument *document);
 
-void           e_html_editor_cell_dialog_set_element_no_wrap
+void           e_html_editor_table_dialog_set_column_count
                                                (WebKitDOMDocument *document,
-                                                gboolean wrap_text,
-                                                guint scope);
+                                                gulong expected_columns);
 
-void           e_html_editor_cell_dialog_set_element_header_style
-                                               (WebKitDOMDocument *document,
-                                                gboolean header_style,
-                                                guint scope);
-
-void           e_html_editor_cell_dialog_set_element_width
-                                               (WebKitDOMDocument *document,
-                                                const gchar *width,
-                                                guint scope);
+gulong         e_html_editor_table_dialog_get_column_count
+                                               (WebKitDOMDocument *document);
 
-void           e_html_editor_cell_dialog_set_element_col_span
-                                               (WebKitDOMDocument *document,
-                                                glong span,
-                                                guint scope);
-
-void           e_html_editor_cell_dialog_set_element_row_span
-                                               (WebKitDOMDocument *document,
-                                                glong span,
-                                                guint scope);
-
-void           e_html_editor_cell_dialog_set_element_bg_color
-                                               (WebKitDOMDocument *document,
-                                                const gchar *color,
-                                                guint scope);
+gboolean       e_html_editor_table_dialog_show (WebKitDOMDocument *document);
 
 G_END_DECLS
 
-#endif /* E_HTML_EDITOR_ACTIONS_DOM_FUNCTIONS_H */
+#endif /* E_HTML_EDITOR_TABLE_DIALOG_DOM_FUNCTIONS_H */
diff --git a/e-util/e-html-editor-table-dialog.c b/e-util/e-html-editor-table-dialog.c
index 91953cd..782d89d 100644
--- a/e-util/e-html-editor-table-dialog.c
+++ b/e-util/e-html-editor-table-dialog.c
@@ -28,7 +28,6 @@
 
 #include "e-color-combo.h"
 #include "e-dialog-widgets.h"
-#include "e-html-editor-utils.h"
 #include "e-image-chooser-dialog.h"
 #include "e-misc-utils.h"
 
@@ -55,8 +54,6 @@ struct _EHTMLEditorTableDialogPrivate {
        GtkWidget *image_chooser_dialog;
 
        GtkWidget *remove_image_button;
-
-       WebKitDOMHTMLTableElement *table_element;
 };
 
 static GdkRGBA transparent = { 0, 0, 0, 0 };
@@ -81,7 +78,7 @@ html_editor_table_dialog_set_row_count (EHTMLEditorTableDialog *dialog)
 
        g_dbus_proxy_call (
                web_extension,
-               "EHTMLEditorCellDialogSetRowCount",
+               "EHTMLEditorTableDialogSetRowCount",
                g_variant_new (
                        "(tu)",
                        webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -144,7 +141,7 @@ html_editor_table_dialog_set_column_count (EHTMLEditorTableDialog *dialog)
 
        g_dbus_proxy_call (
                web_extension,
-               "EHTMLEditorCellDialogSetColumnCount",
+               "EHTMLEditorTableDialogSetColumnCount",
                g_variant_new (
                        "(tu)",
                        webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
@@ -173,7 +170,7 @@ html_editor_table_dialog_get_column_count (EHTMLEditorTableDialog *dialog)
 
        result = g_dbus_proxy_call_sync (
                web_extension,
-               "EHTMLEditorTableDialogGetColumnsCount",
+               "EHTMLEditorTableDialogGetColumnCount",
                g_variant_new (
                        "(t)",
                        webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
@@ -197,14 +194,10 @@ html_editor_table_dialog_set_width (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        gchar *width;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        if (gtk_toggle_button_get_active (
                        GTK_TOGGLE_BUTTON (dialog->priv->width_check))) {
@@ -228,18 +221,8 @@ html_editor_table_dialog_set_width (EHTMLEditorTableDialog *dialog)
                gtk_widget_set_sensitive (dialog->priv->width_units, FALSE);
        }
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetWidth",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       width),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "width", width);
 
        g_free (width);
 }
@@ -249,26 +232,14 @@ html_editor_table_dialog_get_width (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
        const gchar *width;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "EHTMLEditorTableDialogGetWidth",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "width");
 
        if (!result)
                return;
@@ -303,27 +274,17 @@ html_editor_table_dialog_set_alignment (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
+       const gchar *value;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetAlignment",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       gtk_combo_box_get_active_id (
-                               GTK_COMBO_BOX (dialog->priv->alignment_combo))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       value = gtk_combo_box_get_active_id (
+               GTK_COMBO_BOX (dialog->priv->alignment_combo));
+
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "alignment", value);
+
 }
 
 static void
@@ -331,28 +292,16 @@ html_editor_table_dialog_get_alignment (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "EHTMLEditorTableDialogGetAlignment",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "align");
 
        if (result) {
-               gchar *value;
+               const gchar *value;
 
                g_variant_get (result, "(&s)", &value);
                gtk_combo_box_set_active_id (
@@ -366,32 +315,18 @@ html_editor_table_dialog_set_padding (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        gchar *padding;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        padding = g_strdup_printf (
                "%d",
                gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->padding_edit)));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetPadding",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       padding).
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "cellpadding", padding);
 
        g_free (padding);
 }
@@ -401,35 +336,23 @@ html_editor_table_dialog_get_padding (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "EHTMLEditorTableDialogGetPadding",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "cellpadding");
 
        if (result) {
-               gchar *value;
+               const gchar *value;
                gint value_int;
 
                g_variant_get (result, "(&s)", &value);
-               if (!value || !*value)
-                       value_int = 0;
-               else
+               if (value && *value)
                        value_int = atoi (value);
+               else
+                       value_int = 0;
                gtk_spin_button_set_value (
                        GTK_SPIN_BUTTON (dialog->priv->padding_edit), value_int);
                g_variant_unref (result);
@@ -441,32 +364,18 @@ html_editor_table_dialog_set_spacing (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        gchar *spacing;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        spacing = g_strdup_printf (
                "%d",
                gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->spacing_edit)));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetSpacing",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       spacing).
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "cellspacing", spacing);
 
        g_free (spacing);
 }
@@ -476,35 +385,23 @@ html_editor_table_dialog_get_spacing (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "EHTMLEditorTableDialogGetSpacing",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "cellspacing");
 
        if (result) {
-               gchar *value;
+               const gchar *value;
                gint value_int;
 
                g_variant_get (result, "(&s)", &value);
-               if (!value || !*value)
-                       value_int = 0;
-               else
+               if (value && *value)
                        value_int = atoi (value);
+               else
+                       value_int = 0;
                gtk_spin_button_set_value (
                        GTK_SPIN_BUTTON (dialog->priv->spacing_edit), value_int);
                g_variant_unref (result);
@@ -516,32 +413,18 @@ html_editor_table_dialog_set_border (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        gchar *border;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        border = g_strdup_printf (
                "%d",
                gtk_spin_button_get_value_as_int (
                        GTK_SPIN_BUTTON (dialog->priv->border_edit)));
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetBorder",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       border).
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "border", border);
 
        g_free (border);
 }
@@ -551,35 +434,23 @@ html_editor_table_dialog_get_border (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
        GVariant *result;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
-       result = g_dbus_proxy_call_sync (
-               web_extension,
-               "EHTMLEditorTableDialogGetBorder",
-               g_variant_new (
-                       "(t)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "border");
 
        if (result) {
-               gchar *value;
+               const gchar *value;
                gint value_int;
 
                g_variant_get (result, "(&s)", &value);
-               if (!value || !*value)
-                       value_int = 0;
-               else
+               if (value && *value)
                        value_int = atoi (value);
+               else
+                       value_int = 0;
                gtk_spin_button_set_value (
                        GTK_SPIN_BUTTON (dialog->priv->border_edit), value_int);
                g_variant_unref (result);
@@ -591,15 +462,11 @@ html_editor_table_dialog_set_background_color (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       GDBusProxy *web_extension;
-       gchar *color
+       gchar *color;
        GdkRGBA rgba;
 
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
-       web_extension = e_html_editor_view_get_web_extension_proxy (view);
-       if (!web_extension)
-               return;
 
        e_color_combo_get_current_color (
                E_COLOR_COMBO (dialog->priv->background_color_button), &rgba);
@@ -608,18 +475,8 @@ html_editor_table_dialog_set_background_color (EHTMLEditorTableDialog *dialog)
        else
                color = g_strdup ("");
 
-       g_dbus_proxy_call (
-               web_extension,
-               "EHTMLEditorCellDialogSetBgColor",
-               g_variant_new (
-                       "(ts)",
-                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
-                       color).
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
+       e_html_editor_view_set_element_attribute (
+               view, "#-x-evo-current-table", "bgcolor", color);
 
        g_free (color);
 }
@@ -627,25 +484,38 @@ html_editor_table_dialog_set_background_color (EHTMLEditorTableDialog *dialog)
 static void
 html_editor_table_dialog_get_background_color (EHTMLEditorTableDialog *dialog)
 {
-       gchar *color;
-       GdkRGBA rgba;
+       EHTMLEditor *editor;
+       EHTMLEditorView *view;
+       GVariant *result;
 
-       g_return_if_fail (dialog->priv->table_element);
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       view = e_html_editor_get_view (editor);
 
-       color = webkit_dom_html_table_element_get_bg_color (
-                       dialog->priv->table_element);
+       result = e_html_editor_view_get_element_attribute (
+               view, "#-x-evo-current-table", "bgcolor");
 
-       if (color && *color) {
-               gdk_rgba_parse (&rgba, color);
+       if (result) {
+               const gchar *value;
 
-               e_color_combo_set_current_color (
-                       E_COLOR_COMBO (dialog->priv->background_color_button), &rgba);
-       } else {
-               e_color_combo_set_current_color (
-                       E_COLOR_COMBO (dialog->priv->background_color_button), &transparent);
-       }
+               g_variant_get (result, "(&s)", &value);
+               if (value && *value) {
+                       GdkRGBA rgba;
+
+                       if (gdk_rgba_parse (&rgba, value))
+                               e_color_combo_set_current_color (
+                                       E_COLOR_COMBO (dialog->priv->background_color_button),
+                                       &rgba);
+                       else
+                               e_color_combo_set_current_color (
+                                       E_COLOR_COMBO (dialog->priv->background_color_button),
+                                       &transparent);
+               } else
+                       e_color_combo_set_current_color (
+                               E_COLOR_COMBO (dialog->priv->background_color_button),
+                               &transparent);
 
-       g_free (color);
+               g_variant_unref (result);
+       }
 }
 
 static void
@@ -653,12 +523,14 @@ html_editor_table_dialog_set_background_image (EHTMLEditorTableDialog *dialog)
 {
        EHTMLEditor *editor;
        EHTMLEditorView *view;
+       GDBusProxy *web_extension;
        gchar *uri;
 
-       g_return_if_fail (dialog->priv->table_element);
-
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
+       web_extension = e_html_editor_view_get_web_extension_proxy (view);
+       if (!web_extension)
+               return;
 
        uri = gtk_file_chooser_get_uri (
                GTK_FILE_CHOOSER (dialog->priv->background_image_button));
@@ -666,11 +538,21 @@ html_editor_table_dialog_set_background_image (EHTMLEditorTableDialog *dialog)
        if (uri && *uri)
                e_html_editor_selection_replace_image_src (
                        e_html_editor_view_get_selection (view),
-                       WEBKIT_DOM_ELEMENT (dialog->priv->table_element),
+                       "#-x-evo-current-table",
                        uri);
        else
-               remove_image_attributes_from_element (
-                       WEBKIT_DOM_ELEMENT (dialog->priv->table_element));
+               g_dbus_proxy_call (
+                       web_extension,
+                       "RemoveImageAttributesFromElementBySelector",
+                       g_variant_new (
+                               "(ts)",
+                               webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                               "#-x-evo-current-table"),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       NULL,
+                       NULL);
 
        gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
 
@@ -680,26 +562,57 @@ html_editor_table_dialog_set_background_image (EHTMLEditorTableDialog *dialog)
 static void
 html_editor_table_dialog_get_background_image (EHTMLEditorTableDialog *dialog)
 {
-       g_return_if_fail (dialog->priv->table_element);
+       EHTMLEditor *editor;
+       EHTMLEditorView *view;
+       GDBusProxy *web_extension;
+       GVariant *result;
 
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       view = e_html_editor_get_view (editor);
+       web_extension = e_html_editor_view_get_web_extension_proxy (view);
+       if (!web_extension)
+               return;
+
+       result = g_dbus_proxy_call_sync (
+               web_extension,
+               "ElementHasAttribute",
+               g_variant_new (
+                       "(tss)",
+                       webkit_web_view_get_page_id (
+                               WEBKIT_WEB_VIEW (view)),
+                       "-x-evo-current-table",
+                       "background"),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL);
 
-       if (!webkit_dom_element_has_attribute (
-               WEBKIT_DOM_ELEMENT (dialog->priv->table_element), "background")) {
+       if (result) {
+               gboolean has_background;
 
-               gtk_file_chooser_unselect_all (
-                       GTK_FILE_CHOOSER (dialog->priv->background_image_button));
-               return;
-       } else {
-               gchar *value;
+               g_variant_get (result, "(b)", &has_background);
+               if (has_background) {
+                       g_variant_unref (result);
 
-               value = webkit_dom_element_get_attribute (
-                       WEBKIT_DOM_ELEMENT (dialog->priv->table_element), "data-uri");
+                       result = e_html_editor_view_get_element_attribute (
+                               view, "#-x-evo-current-table", "data-uri");
 
-               gtk_file_chooser_set_uri (
-                       GTK_FILE_CHOOSER (dialog->priv->background_image_button),
-                       value);
+                       if (result) {
+                               const gchar *value;
 
-               g_free (value);
+                               g_variant_get (result, "(&s)", &value);
+
+                               gtk_file_chooser_set_uri (
+                                       GTK_FILE_CHOOSER (dialog->priv->background_image_button),
+                                       value);
+
+                               g_variant_unref (result);
+                       }
+               } else {
+                       gtk_file_chooser_unselect_all (
+                               GTK_FILE_CHOOSER (dialog->priv->background_image_button));
+                       g_variant_unref (result);
+               }
        }
 }
 
@@ -764,34 +677,37 @@ html_editor_table_dialog_show (GtkWidget *widget)
        EHTMLEditorTableDialog *dialog;
        EHTMLEditor *editor;
        EHTMLEditorView *view;
-       WebKitDOMDocument *document;
-       WebKitDOMDOMWindow *window;
-       WebKitDOMDOMSelection *selection;
+       GDBusProxy *web_extension;
+       GVariant *result;
 
        dialog = E_HTML_EDITOR_TABLE_DIALOG (widget);
        editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
        view = e_html_editor_get_view (editor);
+       web_extension = e_html_editor_view_get_web_extension_proxy (view);
+       if (!web_extension)
+               return;
 
-       document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
-       window = webkit_dom_document_get_default_view (document);
-       selection = webkit_dom_dom_window_get_selection (window);
-       if (selection && (webkit_dom_dom_selection_get_range_count (selection) > 0)) {
-               WebKitDOMElement *table;
-               WebKitDOMRange *range;
+       result = g_dbus_proxy_call_sync (
+               web_extension,
+               "EHTMLEditorTableDialogShow",
+               g_variant_new (
+                       "(t)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view))),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL);
 
-               range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
-               table = e_html_editor_dom_node_find_parent_element (
-                       webkit_dom_range_get_start_container (range, NULL), "TABLE");
+       if (result) {
+               gboolean created;
 
-               if (!table) {
-                       dialog->priv->table_element = WEBKIT_DOM_HTML_TABLE_ELEMENT (
-                               html_editor_table_dialog_create_table (dialog));
+               g_variant_get (result, "(b)", &created);
+               if (created)
                        html_editor_table_dialog_reset_values (dialog);
-               } else {
-                       dialog->priv->table_element =
-                               WEBKIT_DOM_HTML_TABLE_ELEMENT (table);
+               else
                        html_editor_table_dialog_get_values (dialog);
-               }
+
+               g_variant_unref (result);
        }
 
        /* Chain up to parent implementation */
@@ -801,8 +717,28 @@ html_editor_table_dialog_show (GtkWidget *widget)
 static void
 html_editor_table_dialog_remove_image (EHTMLEditorTableDialog *dialog)
 {
-       remove_image_attributes_from_element (
-               WEBKIT_DOM_ELEMENT (dialog->priv->table_element));
+       EHTMLEditor *editor;
+       EHTMLEditorView *view;
+       GDBusProxy *web_extension;
+
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       view = e_html_editor_get_view (editor);
+       web_extension = e_html_editor_view_get_web_extension_proxy (view);
+       if (!web_extension)
+               return;
+
+       g_dbus_proxy_call (
+               web_extension,
+               "RemoveImageAttributesFromElementBySelector",
+               g_variant_new (
+                       "(ts)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       "#-x-evo-current-table"),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
 
        gtk_file_chooser_unselect_all (
                GTK_FILE_CHOOSER (dialog->priv->background_image_button));
@@ -813,11 +749,16 @@ html_editor_table_dialog_remove_image (EHTMLEditorTableDialog *dialog)
 static void
 html_editor_table_dialog_hide (GtkWidget *widget)
 {
-       EHTMLEditorTableDialogPrivate *priv;
+       EHTMLEditorTableDialog *dialog;
+       EHTMLEditor *editor;
+       EHTMLEditorView *view;
 
-       priv = E_HTML_EDITOR_TABLE_DIALOG_GET_PRIVATE (widget);
+       dialog = E_HTML_EDITOR_TABLE_DIALOG (widget);
+       editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
+       view = e_html_editor_get_view (editor);
 
-       priv->table_element = NULL;
+       e_html_editor_view_remove_element_attribute (
+               view, "#-x-evo-current-table", "id");
 
        GTK_WIDGET_CLASS (e_html_editor_table_dialog_parent_class)->hide (widget);
 }
@@ -1075,4 +1016,3 @@ e_html_editor_table_dialog_new (EHTMLEditor *editor)
                        "title", N_("Table Properties"),
                        NULL));
 }
-
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index dd9fef1..0f56207 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -3080,6 +3080,77 @@ e_html_editor_view_get_web_extension_proxy (EHTMLEditorView *view)
        return view->priv->web_extension;
 }
 
+GVariant *
+e_html_editor_view_get_element_attribute (EHTMLEditorView *view,
+                                          const gchar *selector,
+                                          const gchar *attribute)
+{
+       if (!view->priv->web_extension)
+               return;
+
+       return g_dbus_proxy_call_sync (
+               view->priv->web_extension,
+               "ElementGetAttributeBySelector",
+               g_variant_new (
+                       "(tss)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       selector,
+                       attribute),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
+}
+
+void
+e_html_editor_view_set_element_attribute (EHTMLEditorView *view,
+                                          const gchar *selector,
+                                          const gchar *attribute,
+                                         const gchar *value)
+{
+       if (!view->priv->web_extension)
+               return;
+
+       g_dbus_proxy_call (
+               view->priv->web_extension,
+               "ElementSetAttributeBySelector",
+               g_variant_new (
+                       "(tsss)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       selector,
+                       attribute,
+                       value),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
+}
+
+void
+e_html_editor_view_remove_element_attribute (EHTMLEditorView *view,
+                                             const gchar *selector,
+                                             const gchar *attribute)
+{
+       if (!view->priv->web_extension)
+               return;
+
+       g_dbus_proxy_call (
+               view->priv->web_extension,
+               "ElementRemoveAttributeBySelector",
+               g_variant_new (
+                       "(tss)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)),
+                       selector,
+                       attribute),
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               NULL,
+               NULL);
+}
+
 static GObjectConstructParam*
 find_property(guint n_properties,
               GObjectConstructParam* properties,
@@ -6276,15 +6347,6 @@ remove_wrapping_from_view (EHTMLEditorView *view)
        g_object_unref (list);
 }
 
-void
-remove_image_attributes_from_element (WebKitDOMElement *element)
-{
-       webkit_dom_element_remove_attribute (element, "background");
-       webkit_dom_element_remove_attribute (element, "data-uri");
-       webkit_dom_element_remove_attribute (element, "data-inline");
-       webkit_dom_element_remove_attribute (element, "data-name");
-}
-
 static void
 remove_background_images_in_document (WebKitDOMDocument *document)
 {
diff --git a/e-util/e-html-editor-view.h b/e-util/e-html-editor-view.h
index 1491152..5fe5382 100644
--- a/e-util/e-html-editor-view.h
+++ b/e-util/e-html-editor-view.h
@@ -81,6 +81,19 @@ EHTMLEditorView *
 GDBusProxy *
                e_html_editor_view_get_web_extension_proxy
                                                (EHTMLEditorView *view);
+GVariant *     e_html_editor_view_get_element_attribute
+                                               (EHTMLEditorView *view,
+                                                const gchar *selector,
+                                                const gchar *attribute);
+void           e_html_editor_view_set_element_attribute
+                                               (EHTMLEditorView *view,
+                                                const gchar *selector,
+                                                const gchar *attribute,
+                                                const gchar *value);
+void           e_html_editor_view_remove_element_attribute
+                                               (EHTMLEditorView *view,
+                                                const gchar *selector,
+                                                const gchar *attribute);
 EHTMLEditorSelection *
                e_html_editor_view_get_selection
                                                (EHTMLEditorView *view);
diff --git a/e-util/e-html-editor.c b/e-util/e-html-editor.c
index 2d9485c..ee17cc0 100644
--- a/e-util/e-html-editor.c
+++ b/e-util/e-html-editor.c
@@ -30,6 +30,7 @@
 #include "e-alert-bar.h"
 #include "e-alert-dialog.h"
 #include "e-alert-sink.h"
+#include "e-html-editor-defines.h"
 #include "e-html-editor-private.h"
 #include "e-html-editor-selection.h"
 
@@ -310,7 +311,6 @@ html_editor_update_actions (EHTMLEditor *editor,
        WebKitSpellChecker *checker;
        WebKitHitTestResult *hit_test;
        WebKitHitTestResultContext context;
-       WebKitDOMNode *node;
        EHTMLEditorSelection *selection;
        EHTMLEditorView *view;
        ESpellChecker *spell_checker;
@@ -480,7 +480,6 @@ html_editor_context_menu_cb (WebKitWebView *webkit_web_view,
                              WebKitHitTestResult *hit_test_result,
                              EHTMLEditor *editor)
 {
-       WebKitHitTestResultContext context;
        GtkWidget *menu;
        guint flags = 0;
 
@@ -497,7 +496,7 @@ html_editor_context_menu_cb (WebKitWebView *webkit_web_view,
        if (event)
                gtk_menu_popup (
                        GTK_MENU (menu), NULL, NULL, NULL,
-                       GTK_WIDGET (webkit_web_view), event->button, event->time);
+                       GTK_WIDGET (webkit_web_view), ((GdkEventButton*) event)->button, event->time);
        else
                gtk_menu_popup (
                        GTK_MENU (menu), NULL, NULL, NULL,
diff --git a/e-util/web-extensions/e-html-editor-web-extension.c 
b/e-util/web-extensions/e-html-editor-web-extension.c
index 7c2091e..5487aaa 100644
--- a/e-util/web-extensions/e-html-editor-web-extension.c
+++ b/e-util/web-extensions/e-html-editor-web-extension.c
@@ -25,9 +25,15 @@
 #include <string.h>
 
 #include <e-util/e-dom-utils.h>
+#include <e-util/e-html-editor-actions-dom-functions.h>
 #include <e-util/e-html-editor-cell-dialog-dom-functions.h>
+#include <e-util/e-html-editor-dom-functions.h>
+#include <e-util/e-html-editor-hrule-dialog-dom-functions.h>
 #include <e-util/e-html-editor-image-dialog-dom-functions.h>
 #include <e-util/e-html-editor-link-dialog-dom-functions.h>
+#include <e-util/e-html-editor-selection-dom-functions.h>
+#include <e-util/e-html-editor-table-dialog-dom-functions.h>
+#include <e-util/e-html-editor-view-dom-functions.h>
 
 /* FIXME Clean it */
 static GDBusConnection *dbus_connection;
@@ -94,65 +100,117 @@ static const char introspection_xml[] =
 "      <arg type='s' name='attribute' direction='in'/>"
 "      <arg type='s' name='value' direction='out'/>"
 "    </method>"
+"    <method name='ElementGetAttributeBySelector'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='selector' direction='in'/>"
+"      <arg type='s' name='attribute' direction='in'/>"
+"      <arg type='s' name='value' direction='out'/>"
+"    </method>"
 "    <method name='ElementRemoveAttribute'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='s' name='attribute' direction='in'/>"
 "    </method>"
+"    <method name='ElementRemoveAttributeBySelector'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='selector' direction='in'/>"
+"      <arg type='s' name='attribute' direction='in'/>"
+"    </method>"
 "    <method name='ElementSetAttribute'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='s' name='attribute' direction='in'/>"
 "      <arg type='s' name='value' direction='in'/>"
 "    </method>"
+"    <method name='ElementSetAttributeBySelector'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='selector' direction='in'/>"
+"      <arg type='s' name='attribute' direction='in'/>"
+"      <arg type='s' name='value' direction='in'/>"
+"    </method>"
 "    <method name='ElementGetTagName'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='s' name='tag_name' direction='out'/>"
 "    </method>"
-"    <method name='TableCellElementGetAlign'>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are specific to composer               -->"
+"<!-- ********************************************************* -->"
+"    <method name='RemoveImageAttributesFromElementBySelector'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='align' direction='out'/>"
+"      <arg type='s' name='selector' direction='in'/>"
 "    </method>"
-"    <method name='TableCellElementGetVAlign'>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are used in EHTMLEditorCellDialog      -->"
+"<!-- ********************************************************* -->"
+"    <method name='EHTMLEditorCellDialogMarkCurrentCellElement'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='v_align' direction='out'/>"
 "    </method>"
-"    <method name='TableCellElementGetNoWrap'>"
+"    <method name='EHTMLEditorCellDialogSetElementVAlign'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='b' name='no_wrap' direction='out'/>"
+"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
 "    </method>"
-"    <method name='TableCellElementGetWidth'>"
+"    <method name='EHTMLEditorCellDialogSetElementAlign'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='width' direction='out'/>"
+"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
 "    </method>"
-"    <method name='TableCellElementGetRowSpan'>"
+"    <method name='EHTMLEditorCellDialogSetElementNoWrap'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='i' name='row_span' direction='out'/>"
+"      <arg type='b' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
 "    </method>"
-"    <method name='TableCellElementGetColSpan'>"
+"    <method name='EHTMLEditorCellDialogSetElementHeaderStyle'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='i' name='col_span' direction='out'/>"
+"      <arg type='b' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
+"    </method>"
+"    <method name='EHTMLEditorCellDialogSetElementWidth'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
+"    <method name='EHTMLEditorCellDialogSetElementColSpan'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='i' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
+"    </method>"
+"    <method name='EHTMLEditorCellDialogSetElementRowSpan'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='i' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
 "    </method>"
-"    <method name='TableCellElementGetBgColor'>"
+"    <method name='EHTMLEditorCellDialogSetElementBgColor'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='scope' direction='in'/>"
+"    </method>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are used in EHTMLEditorHRuleDialog      -->"
+"<!-- ********************************************************* -->"
+"    <method name='EHTMLEditorHRuleDialogFindHRule'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"    </method>"
+"    <method name='HRElementSetNoShade'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='color' direction='out'/>"
+"      <arg type='b' name='value' direction='in'/>"
 "    </method>"
-"    <method name='ImageElementSetAlt'>"
+"    <method name='HRElementGetNoShade'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
+"      <arg type='b' name='value' direction='out'/>"
+"    </method>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are used in EHTMLEditorImageDialog     -->"
+"<!-- ********************************************************* -->"
+"    <method name='EHTMLEditorImageDialogSetElementUrl'>"
+"      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='value' direction='in'/>"
 "    </method>"
-"    <method name='ImageElementGetAlt'>"
+"    <method name='EHTMLEditorImageDialogGetElementUrl'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='s' name='value' direction='out'/>"
 "    </method>"
 "    <method name='ImageElementSetWidth'>"
@@ -185,11 +243,6 @@ static const char introspection_xml[] =
 "      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='i' name='value' direction='out'/>"
 "    </method>"
-"    <method name='ImageElementSetAlign'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
 "    <method name='ImageElementSetHSpace'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
@@ -210,148 +263,51 @@ static const char introspection_xml[] =
 "      <arg type='s' name='element_id' direction='in'/>"
 "      <arg type='i' name='value' direction='out'/>"
 "    </method>"
-"    <method name='ImageElementSetBorder'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
-"    <method name='ImageElementGetBorder'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"    <method name='BodySetTextColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
-"    <method name='BodyGetTextColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"    <method name='BodySetLinkColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
-"    <method name='BodyGetLinkColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"    <method name='BodySetBgColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
-"    <method name='BodyGetBgColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"    <method name='BodyGetBackground'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"    <method name='HRElementSetAlign'>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are used in EHTMLEditorLinkDialog      -->"
+"<!-- ********************************************************* -->"
+"    <method name='EHTMLEditorLinkDialogOk'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='s' name='url' direction='in'/>"
+"      <arg type='s' name='inner_text' direction='in'/>"
 "    </method>"
-"    <method name='HRElementGetAlign'>"
+"<!-- ********************************************************* -->"
+"<!--     Functions that are used in EHTMLEditorTableDialog     -->"
+"<!-- ********************************************************* -->"
+"    <method name='EHTMLEditorTableDialogSetRowCount'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
+"      <arg type='u' name='value' direction='in'/>"
 "    </method>"
-"    <method name='HRElementSetSize'>"
+"    <method name='EHTMLEditorTableDialogGetRowCount'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='value' direction='out'/>"
 "    </method>"
-"    <method name='HRElementGetSize'>"
+"    <method name='EHTMLEditorTableDialogSetColumnCount'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
+"      <arg type='u' name='value' direction='in'/>"
 "    </method>"
-"    <method name='HRElementSetWidth'>"
+"    <method name='EHTMLEditorTableDialogGetColumnCount'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
+"      <arg type='u' name='value' direction='out'/>"
 "    </method>"
-"    <method name='HRElementGetWidth'>"
+"    <method name='EHTMLEditorTableDialogShow'>"
 "      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
+"      <arg type='b' name='created_new_table' direction='out'/>"
 "    </method>"
-"    <method name='HRElementSetNoShade'>"
+"    <method name='TableCellElementGetNoWrap'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='b' name='value' direction='in'/>"
+"      <arg type='b' name='no_wrap' direction='out'/>"
 "    </method>"
-"    <method name='HRElementGetNoShade'>"
+"    <method name='TableCellElementGetRowSpan'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
-"      <arg type='b' name='value' direction='out'/>"
+"      <arg type='i' name='row_span' direction='out'/>"
 "    </method>"
-"<!-- ********************************************************* -->"
-"<!--     Functions that are used in EHTMLEditorCellDialog      -->"
-"<!-- ********************************************************* -->"
-"    <method name='EHTMLEditorCellDialogMarkCurrentCellElement'>"
+"    <method name='TableCellElementGetColSpan'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='s' name='element_id' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementVAlign'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementAlign'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementNoWrap'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='b' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementHeaderStyle'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='b' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementWidth'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    <method name='EHTMLEditorCellDialogSetElementColSpan'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='i' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementRowSpan'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='i' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorCellDialogSetElementBgColor'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"      <arg type='u' name='scope' direction='in'/>"
-"    </method>"
-"<!-- ********************************************************* -->"
-"<!--     Functions that are used in EHTMLEditorImageDialog     -->"
-"<!-- ********************************************************* -->"
-"    <method name='EHTMLEditorImageDialogSetElementUrl'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='in'/>"
-"    </method>"
-"    <method name='EHTMLEditorImageDialogGetElementUrl'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='value' direction='out'/>"
-"    </method>"
-"<!-- ********************************************************* -->"
-"<!--     Functions that are used in EHTMLEditorLinkDialog      -->"
-"<!-- ********************************************************* -->"
-"    <method name='EHTMLEditorLinkDialogOk'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='s' name='url' direction='in'/>"
-"      <arg type='s' name='inner_text' direction='in'/>"
+"      <arg type='i' name='col_span' direction='out'/>"
 "    </method>"
 "  </interface>"
 "</node>";
@@ -429,12 +385,13 @@ handle_method_call (GDBusConnection *connection,
                g_dbus_method_invocation_return_value (
                        invocation,
                        value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "ElementRemoveAttribute") == 0) {
-               const gchar *element_id, *attribute;
+       } else if (g_strcmp0 (method_name, "ElementGetAttributeBySelector") == 0) {
+               const gchar *attribute, *selector;
+               gchar *value = NULL;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters, "(t&s&s)", &page_id, &element_id, &attribute);
+                       parameters, "(t&s&s)", &page_id, &selector, &attribute);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -442,19 +399,19 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
+               element = webkit_dom_document_query_selector (document, selector, NULL);
                if (element)
-                       webkit_dom_element_remove_attribute (element, attribute);
+                       value = webkit_dom_element_get_attribute (element, attribute);
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ElementSetAttribute") == 0) {
-               const gchar *element_id, *attribute, *value;
+               g_dbus_method_invocation_return_value (
+                       invocation,
+                       value ? g_variant_new_take_string (value) : NULL);
+       } else if (g_strcmp0 (method_name, "ElementRemoveAttribute") == 0) {
+               const gchar *element_id, *attribute;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters,
-                       "(t&s&s&s)",
-                       &page_id, &element_id, &attribute, &value);
+                       parameters, "(t&s&s)", &page_id, &element_id, &attribute);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -464,16 +421,15 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_element_set_attribute (
-                               element, attribute, value, NULL);
+                       webkit_dom_element_remove_attribute (element, attribute);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ElementGetTagName") == 0) {
-               const gchar *element_id;
-               gchar *value = NULL;
+       } else if (g_strcmp0 (method_name, "ElementRemoveAttributeBySelector") == 0) {
+               const gchar *attribute, *selector;
                WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (
+                       parameters, "(t&s&s)", &page_id, &selector, &attribute);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -481,19 +437,19 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
+               element = webkit_dom_document_query_selector (document, selector, NULL);
                if (element)
-                       value = webkit_dom_element_get_tag_name (element);
+                       webkit_dom_element_remove_attribute (element, attribute);
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "TableCellElementGetAlign") == 0) {
-               const gchar *element_id;
-               gchar *value = NULL;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "ElementSetAttribute") == 0) {
+               const gchar *element_id, *attribute, *value;
                WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (
+                       parameters,
+                       "(t&s&s&s)",
+                       &page_id, &element_id, &attribute, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -503,18 +459,16 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_table_cell_element_get_align (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+                       webkit_dom_element_set_attribute (
+                               element, attribute, value, NULL);
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "TableCellElementGetVAlign") == 0) {
-               const gchar *element_id;
-               gchar *value = NULL;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "ElementSetAttributeBySelector") == 0) {
+               const gchar *attribute, *selector, *value;
                WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (
+                       parameters, "(t&s&s)", &page_id, &selector, &attribute, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -522,17 +476,15 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
+               element = webkit_dom_document_query_selector (document, selector, NULL);
                if (element)
-                       value = webkit_dom_html_table_cell_element_get_v_align (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+                       webkit_dom_element_set_attribute (
+                               element, attribute, value, NULL);
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "TableCellElementGetNoWrap") == 0) {
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "ElementGetTagName") == 0) {
                const gchar *element_id;
-               gboolean value = FALSE;
+               gchar *value = NULL;
                WebKitDOMElement *element;
 
                g_variant_get (parameters, "(t&s)", &page_id, &element_id);
@@ -545,17 +497,17 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_table_cell_element_get_no_wrap (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+                       value = webkit_dom_element_get_tag_name (element);
 
                g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_boolean (value));
-       } else if (g_strcmp0 (method_name, "TableCellElementGetWidth") == 0) {
-               const gchar *element_id;
-               gchar *value = NULL;
+                       invocation,
+                       value ? g_variant_new_take_string (value) : NULL);
+       } else if (g_strcmp0 (method_name, "RemoveImageAttributesFromElementBySelector") == 0) {
+               const gchar *selector;
                WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (
+                       parameters, "(t&s)", &selector);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -563,18 +515,17 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_table_cell_element_get_width (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+               element = webkit_dom_document_query_selector (document, selector, NULL);
+               if (element) {
+                       webkit_dom_element_remove_attribute (element, "background");
+                       webkit_dom_element_remove_attribute (element, "data-uri");
+                       webkit_dom_element_remove_attribute (element, "data-inline");
+                       webkit_dom_element_remove_attribute (element, "data-name");
+               }
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "TableCellElementGetRowSpan") == 0) {
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogMarkCurrentCellElement") == 0) {
                const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
 
                g_variant_get (parameters, "(t&s)", &page_id, &element_id);
 
@@ -584,19 +535,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_table_cell_element_get_row_span (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+               e_html_editor_cell_dialog_mark_current_cell_element (document, element_id);
 
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "TableCellElementGetColSpan") == 0) {
-               const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementVAlign") == 0) {
+               const gchar *value;
+               guint scope;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -604,19 +550,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_table_cell_element_get_col_span (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+               e_html_editor_cell_dialog_set_element_v_align (document, value, scope);
 
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "TableCellElementGetBgColor") == 0) {
-               const gchar *element_id;
-               gchar *value = NULL;
-               WebKitDOMElement *element;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementAlign") == 0) {
+               const gchar *value;
+               guint scope;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -624,21 +565,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_table_cell_element_get_bg_color (
-                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
+               e_html_editor_cell_dialog_set_element_align (document, value, scope);
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetAlt") == 0) {
-               const gchar *element_id, *value;
-               gchar *value = NULL;
-               WebKitDOMElement *element;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementNoWrap") == 0) {
+               gboolean value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -646,20 +580,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_image_element_get_alt (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
+               e_html_editor_cell_dialog_set_element_no_wrap (document, value, scope);
 
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementSetAlt") == 0) {
-               const gchar *element_id, *value;
-               WebKitDOMElement *element;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementHeaderStyle") == 0) {
+               gboolean value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&s&s)", &page_id, &element_id, &value);
+               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -667,19 +595,15 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_image_element_set_alt (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
+               e_html_editor_cell_dialog_set_element_header_style (
+                       document, value, scope);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementSetWidth") == 0) {
-               const gchar *element_id;
-               glong value;
-               WebKitDOMElement *element;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementWidth") == 0) {
+               const gchar *value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&si)", &page_id, &element_id, &value);
+               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -687,19 +611,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_image_element_set_width (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
+               e_html_editor_cell_dialog_set_element_width (document, value, scope);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetWidth") == 0) {
-               const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementColSpan") == 0) {
+               glong value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -707,20 +626,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_image_element_get_width (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
+               e_html_editor_cell_dialog_set_element_col_span (document, value, scope);
 
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "ImageElementSetHeight") == 0) {
-               const gchar *element_id;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementRowSpan") == 0) {
                glong value;
-               WebKitDOMElement *element;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&si)", &page_id, &element_id, &value);
+               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -728,19 +641,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_image_element_set_width (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
+               e_html_editor_cell_dialog_set_element_row_span (document, value, scope);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetHeight") == 0) {
-               const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementBgColor") == 0) {
+               const gchar *value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -748,20 +656,11 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_image_element_get_height (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
-
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "ImageElementGetNaturalWidth") == 0) {
-               const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
+               e_html_editor_cell_dialog_set_element_bg_color (document, value, scope);
 
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorHRuleDialogFindHRule") == 0) {
+               g_variant_get (parameters, "(t)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -769,20 +668,16 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_image_element_get_natural_width (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
+               e_html_editor_hrule_dialog_find_hrule (document);
 
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "ImageElementGetNaturalHeight") == 0) {
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "HRElementSetNoShade") == 0) {
+               gboolean value = FALSE;
                const gchar *element_id;
-               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+                       parameters, "(t&sb)", &page_id, &element_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -792,17 +687,17 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_image_element_get_natural_height (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
+                       webkit_dom_html_hr_element_set_no_shade (
+                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
 
-               g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value));
-       } else if (g_strcmp0 (method_name, "ImageElementSetAlign") == 0) {
-               const gchar *element_id, *value;
+               g_dbus_method_invocation_return_value (invocation, NULL);
+       } else if (g_strcmp0 (method_name, "HRElementGetNoShade") == 0) {
+               gboolean *value = FALSE;
+               const gchar *element_id;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters, "(t&ss)", &page_id, &element_id, &value);
+                       parameters, "(t&s)", &page_id, &element_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -812,17 +707,16 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_html_image_element_set_align (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
+                       value = webkit_dom_html_hr_element_get_no_shade (
+                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementSetHSpace") == 0) {
-               const gchar *element_id;
-               glong value;
-               WebKitDOMElement *element;
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_boolean (value));
+       } else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogSetElementUrl") == 0) {
+               const gchar *value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&si)", &page_id, &element_id, &value);
+               g_variant_get (parameters, "(t&s)", &page_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -830,19 +724,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_image_element_set_hspace (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
+               e_html_editor_image_dialog_set_element_url (document, value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetHSpace") == 0) {
-               const gchar *element_id;
-               glong value = 0;
-               WebKitDOMElement *element;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogGetElementUrl") == 0) {
+               gchar *value;
+               guint scope;
 
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &element_id);
+               g_variant_get (parameters, "(t)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -850,14 +739,12 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       value = webkit_dom_html_image_element_get_hspace (
-                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
+               value = e_html_editor_image_dialog_get_element_url (document);
 
                g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value);
-       } else if (g_strcmp0 (method_name, "ImageElementSetVSpace") == 0) {
+                       invocation,
+                       value ? g_variant_new_take_string (value) : NULL);
+       } else if (g_strcmp0 (method_name, "ImageElementSetWidth") == 0) {
                const gchar *element_id;
                glong value;
                WebKitDOMElement *element;
@@ -873,11 +760,11 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_html_image_element_set_vspace (
+                       webkit_dom_html_image_element_set_width (
                                WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetVSpace") == 0) {
+       } else if (g_strcmp0 (method_name, "ImageElementGetWidth") == 0) {
                const gchar *element_id;
                glong value = 0;
                WebKitDOMElement *element;
@@ -893,13 +780,14 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_image_element_get_vspace (
+                       value = webkit_dom_html_image_element_get_width (
                                WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_int32 (value);
-       } else if (g_strcmp0 (method_name, "ImageElementSetBorder") == 0) {
-               const gchar *element_id, *value;
+                       invocation, g_variant_new_int32 (value));
+       } else if (g_strcmp0 (method_name, "ImageElementSetHeight") == 0) {
+               const gchar *element_id;
+               glong value;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -913,13 +801,13 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_html_image_element_set_border (
+                       webkit_dom_html_image_element_set_width (
                                WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "ImageElementGetBorder") == 0) {
+       } else if (g_strcmp0 (method_name, "ImageElementGetHeight") == 0) {
                const gchar *element_id;
-               gchar *value = NULL;
+               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -933,150 +821,14 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_image_element_get_border (
+                       value = webkit_dom_html_image_element_get_height (
                                WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "BodySetTextColor") == 0) {
-               const gchar *value;
-
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &value);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               webkit_dom_html_body_element_set_text (
-                       webkit_dom_document_get_body (document), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "BodyGetTextColor") == 0) {
-               gchar *value = NULL;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               value = webkit_dom_html_body_element_get_text (
-                       webkit_dom_document_get_body (document));
-
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "BodySetLinkColor") == 0) {
-               const gchar *value;
-
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &value);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               webkit_dom_html_body_element_set_link (
-                       webkit_dom_document_get_body (document), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "BodyGetLinkColor") == 0) {
-               gchar *value = NULL;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               value = webkit_dom_html_body_element_get_link (
-                       webkit_dom_document_get_body (document));
-
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "BodySetBgColor") == 0) {
-               const gchar *value;
-
-               g_variant_get (
-                       parameters, "(t&s)", &page_id, &value);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               webkit_dom_html_body_element_set_bg_color (
-                       webkit_dom_document_get_body (document), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "BodyGetBgColor") == 0) {
-               gchar *value = NULL;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               value = webkit_dom_html_body_element_get_bg_color (
-                       webkit_dom_document_get_body (document));
-
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "BodyGetBackground") == 0) {
-               gchar *value = NULL;
-
-               g_variant_get (parameters, "(t)", &page_id);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               value = webkit_dom_html_body_element_get_background (
-                       webkit_dom_document_get_body (document));
-
-               g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "HRElementSetAlign") == 0) {
-               const gchar *element_id, *value;
-               WebKitDOMElement *element;
-
-               g_variant_get (
-                       parameters, "(t&s&s)", &page_id, &element_id, &value);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_hr_element_set_align (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementGetAlign") == 0) {
+                       invocation, g_variant_new_int32 (value));
+       } else if (g_strcmp0 (method_name, "ImageElementGetNaturalWidth") == 0) {
                const gchar *element_id;
-               gchar *value = NULL;
+               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -1090,34 +842,14 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_hr_element_get_align (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
+                       value = webkit_dom_html_image_element_get_natural_width (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "HRElementSetSize") == 0) {
-               const gchar *element_id, *value;
-               WebKitDOMElement *element;
-
-               g_variant_get (
-                       parameters, "(t&s&s)", &page_id, &element_id, &value);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               element = webkit_dom_document_get_element_by_id (document, element_id);
-               if (element)
-                       webkit_dom_html_hr_element_set_size (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementGetSize") == 0) {
+                       invocation, g_variant_new_int32 (value));
+       } else if (g_strcmp0 (method_name, "ImageElementGetNaturalHeight") == 0) {
                const gchar *element_id;
-               gchar *value = NULL;
+               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -1131,18 +863,18 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_hr_element_get_size (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
+                       value = webkit_dom_html_image_element_get_natural_height (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "HRElementSetWidth") == 0) {
-               const gchar *element_id, *value;
+                       invocation, g_variant_new_int32 (value));
+       } else if (g_strcmp0 (method_name, "ImageElementSetHSpace") == 0) {
+               const gchar *element_id;
+               glong value;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters, "(t&s&s)", &page_id, &element_id, &value);
+                       parameters, "(t&si)", &page_id, &element_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1152,13 +884,13 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_html_hr_element_set_width (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
+                       webkit_dom_html_image_element_set_hspace (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementGetSize") == 0) {
+       } else if (g_strcmp0 (method_name, "ImageElementGetHSpace") == 0) {
                const gchar *element_id;
-               gchar *value = NULL;
+               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -1172,19 +904,18 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_hr_element_get_width (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
+                       value = webkit_dom_html_image_element_get_hspace (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "HRElementSetNoShade") == 0) {
-               gboolean value = FALSE;
+                       invocation, g_variant_new_int32 (value);
+       } else if (g_strcmp0 (method_name, "ImageElementSetVSpace") == 0) {
                const gchar *element_id;
+               glong value;
                WebKitDOMElement *element;
 
                g_variant_get (
-                       parameters, "(t&sb)", &page_id, &element_id, &value);
+                       parameters, "(t&si)", &page_id, &element_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1194,13 +925,13 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       webkit_dom_html_hr_element_set_no_shade (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element), value);
+                       webkit_dom_html_image_element_set_vspace (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element), value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "HRElementGetNoShade") == 0) {
-               gboolean *value = FALSE;
+       } else if (g_strcmp0 (method_name, "ImageElementGetVSpace") == 0) {
                const gchar *element_id;
+               glong value = 0;
                WebKitDOMElement *element;
 
                g_variant_get (
@@ -1214,60 +945,15 @@ handle_method_call (GDBusConnection *connection,
                document = webkit_web_page_get_dom_document (web_page);
                element = webkit_dom_document_get_element_by_id (document, element_id);
                if (element)
-                       value = webkit_dom_html_hr_element_get_no_shade (
-                               WEBKIT_DOM_HTML_HR_ELEMENT (element));
+                       value = webkit_dom_html_image_element_get_vspace (
+                               WEBKIT_DOM_HTML_IMAGE_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation, g_variant_new_boolean (value));
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogMarkCurrentCellElement") == 0) {
-               const gchar *element_id;
-
-               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_mark_current_cell_element (document, element_id);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementVAlign") == 0) {
-               const gchar *value;
-               guint scope;
-
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_v_align (document, value, scope);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementAlign") == 0) {
-               const gchar *value;
-               guint scope;
-
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
-
-               web_page = get_webkit_web_page_or_return_dbus_error (
-                       invocation, web_extension, page_id);
-               if (!web_page)
-                       return;
-
-               document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_align (document, value, scope);
-
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementNoWrap") == 0) {
-               gboolean value;
-               guint scope;
+                       invocation, g_variant_new_int32 (value);
+       } else if (g_strcmp0 (method_name, "EHTMLEditorLinkDialogOk") == 0) {
+               const gchar *url, *inner_text;
 
-               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t&s&s)", &page_id, &url, &inner_text);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1275,14 +961,13 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_no_wrap (document, value, scope);
+               e_html_editor_link_dialog_ok (document, url, inner_text);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementHeaderStyle") == 0) {
-               gboolean value;
-               guint scope;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogSetRowCount") == 0) {
+               gulong value;
 
-               g_variant_get (parameters, "(tbu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tu)", &page_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1290,15 +975,13 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_header_style (
-                       document, value, scope);
+               e_html_editor_table_dialog_set_row_count (document, value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementWidth") == 0) {
-               const gchar *value;
-               guint scope;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogGetRowCount") == 0) {
+               gulong value;
 
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1306,14 +989,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_width (document, value, scope);
+               value = e_html_editor_table_dialog_get_row_count (document);
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementColSpan") == 0) {
-               glong value;
-               guint scope;
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_uint32 (value));
+       } else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogSetColumnCount") == 0) {
+               gulong value;
 
-               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(tu)", &page_id, &value);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1321,14 +1004,13 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_col_span (document, value, scope);
+               e_html_editor_table_dialog_set_column_count (document, value);
 
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementRowSpan") == 0) {
-               glong value;
-               guint scope;
+       } else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogGetColumnCount") == 0) {
+               gulong value;
 
-               g_variant_get (parameters, "(tiu)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1336,14 +1018,14 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_row_span (document, value, scope);
+               value = e_html_editor_table_dialog_get_column_count (document);
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorCellDialogSetElementBgColor") == 0) {
-               const gchar *value;
-               guint scope;
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_uint32 (value));
+       } else if (g_strcmp0 (method_name, "EHTMLEditorTableDialogShow") == 0) {
+               gboolean created_new_table;
 
-               g_variant_get (parameters, "(t&su)", &page_id, &value, &scope);
+               g_variant_get (parameters, "(t)", &page_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1351,14 +1033,16 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_cell_dialog_set_element_bg_color (document, value, scope);
+               created_new_table = e_html_editor_table_dialog_show (document);
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogSetElementUrl") == 0) {
-               const gchar *value;
-               guint scope;
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_boolean (created_new_table));
+       } else if (g_strcmp0 (method_name, "TableCellElementGetNoWrap") == 0) {
+               const gchar *element_id;
+               gboolean value = FALSE;
+               WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s)", &page_id, &value);
+               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1366,14 +1050,19 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_image_dialog_set_element_url (document, value);
+               element = webkit_dom_document_get_element_by_id (document, element_id);
+               if (element)
+                       value = webkit_dom_html_table_cell_element_get_no_wrap (
+                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorImageDialogGetElementUrl") == 0) {
-               gchar *value;
-               guint scope;
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_boolean (value));
+       } else if (g_strcmp0 (method_name, "TableCellElementGetRowSpan") == 0) {
+               const gchar *element_id;
+               glong value = 0;
+               WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t)", &page_id);
+               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1381,15 +1070,19 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               value = e_html_editor_image_dialog_get_element_url (document);
+               element = webkit_dom_document_get_element_by_id (document, element_id);
+               if (element)
+                       value = webkit_dom_html_table_cell_element_get_row_span (
+                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
 
                g_dbus_method_invocation_return_value (
-                       invocation,
-                       value ? g_variant_new_take_string (value) : NULL);
-       } else if (g_strcmp0 (method_name, "EHTMLEditorLinkDialogOk") == 0) {
-               const gchar *url, *inner_text;
+                       invocation, g_variant_new_int32 (value));
+       } else if (g_strcmp0 (method_name, "TableCellElementGetColSpan") == 0) {
+               const gchar *element_id;
+               glong value = 0;
+               WebKitDOMElement *element;
 
-               g_variant_get (parameters, "(t&s&s)", &page_id, &url, &inner_text);
+               g_variant_get (parameters, "(t&s)", &page_id, &element_id);
 
                web_page = get_webkit_web_page_or_return_dbus_error (
                        invocation, web_extension, page_id);
@@ -1397,9 +1090,13 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
-               e_html_editor_link_dialog_ok (document, url, inner_text);
+               element = webkit_dom_document_get_element_by_id (document, element_id);
+               if (element)
+                       value = webkit_dom_html_table_cell_element_get_col_span (
+                               WEBKIT_DOM_HTML_TABLE_CELL_ELEMENT (element));
 
-               g_dbus_method_invocation_return_value (invocation, NULL);
+               g_dbus_method_invocation_return_value (
+                       invocation, g_variant_new_int32 (value));
        }
 }
 


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