[evolution/wip/webkit2] Remove the EContentEditorContentFlags enum



commit e153a15290b1af1571e25f0241a8ba6fda6f4447
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Jul 14 12:24:26 2016 +0200

    Remove the EContentEditorContentFlags enum
    
    Also rework how the determine whether the content needs to be converted or not
    when switching from HTML mode to the plain text one. Make it based on the current
    DOM elements and not the state of the content editor.

 composer/e-msg-composer.c                          |   58 +---------
 e-util/e-content-editor.c                          |   29 -----
 e-util/e-content-editor.h                          |   14 ---
 e-util/e-mail-signature-editor.c                   |    9 +-
 e-util/e-util-enums.h                              |   20 ----
 e-util/test-html-editor.c                          |    3 -
 mail/em-composer-utils.c                           |   26 ----
 modules/webkit-editor/e-webkit-editor.c            |   50 +-------
 .../web-extension/e-composer-dom-functions.c       |   58 +---------
 .../web-extension/e-editor-dom-functions.c         |  121 ++++++++++----------
 .../webkit-editor/web-extension/e-editor-page.c    |   20 ----
 .../webkit-editor/web-extension/e-editor-page.h    |    6 -
 .../web-extension/e-editor-web-extension.c         |   15 ---
 13 files changed, 76 insertions(+), 353 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 0dec505..323995e 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -2397,7 +2397,6 @@ msg_composer_constructed (GObject *object)
        EComposerHeaderTable *table;
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
-       EContentEditorContentFlags flags;
        GtkUIManager *ui_manager;
        GtkToggleAction *action;
        GtkTargetList *target_list;
@@ -2424,10 +2423,6 @@ msg_composer_constructed (GObject *object)
        attachment_view = e_msg_composer_get_attachment_view (composer);
        table = E_COMPOSER_HEADER_TABLE (composer->priv->header_table);
 
-       flags = e_content_editor_get_current_content_flags (cnt_editor);
-       flags |= E_CONTENT_EDITOR_MESSAGE_EDITTING;
-       e_content_editor_set_current_content_flags (cnt_editor, flags);
-
        gtk_window_set_title (GTK_WINDOW (composer), _("Compose Message"));
        gtk_window_set_icon_name (GTK_WINDOW (composer), "mail-message-new");
        gtk_window_set_default_size (GTK_WINDOW (composer), 600, 500);
@@ -3436,50 +3431,15 @@ handle_multipart (EMsgComposer *composer,
                        }
 
                } else if (depth == 0 && i == 0) {
-                       EHTMLEditor *editor;
-                       EContentEditor *cnt_editor;
-                       EContentEditorContentFlags flags;
-                       gboolean is_message_from_draft, is_html = FALSE;
                        gchar *html = NULL;
                        gssize length = 0;
 
-                       editor = e_msg_composer_get_editor (composer);
-                       cnt_editor = e_html_editor_get_content_editor (editor);
-
-                       flags = e_content_editor_get_current_content_flags (cnt_editor);
-                       is_message_from_draft = (flags & E_CONTENT_EDITOR_MESSAGE_DRAFT);
-                       is_html = camel_content_type_is (content_type, "text", "html");
-
                        /* Since the first part is not multipart/alternative,
                         * this must be the body. */
+                       html = emcu_part_to_html (
+                               composer, mime_part, &length, keep_signature, cancellable);
 
-                       /* If we are opening message from Drafts */
-                       if (is_message_from_draft) {
-                               /* Extract the body */
-                               CamelDataWrapper *dw;
-
-                               dw = camel_medium_get_content ((CamelMedium *) mime_part);
-                               if (dw) {
-                                       CamelStream *mem = camel_stream_mem_new ();
-                                       GByteArray *bytes;
-
-                                       camel_data_wrapper_decode_to_stream_sync (dw, mem, cancellable, NULL);
-                                       camel_stream_close (mem, cancellable, NULL);
-
-                                       bytes = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (mem));
-                                       if (bytes && bytes->len)
-                                               html = g_strndup ((const gchar *) bytes->data, bytes->len);
-
-                                       g_object_unref (mem);
-                               }
-                       } else {
-                               is_html = TRUE;
-                               html = emcu_part_to_html (
-                                       composer, mime_part, &length, keep_signature, cancellable);
-                       }
-
-                       if (html)
-                               e_msg_composer_set_pending_body (composer, html, length, is_html);
+                       e_msg_composer_set_pending_body (composer, html, length, TRUE);
 
                } else if (camel_mime_part_get_content_id (mime_part) ||
                           camel_mime_part_get_content_location (mime_part)) {
@@ -3599,7 +3559,6 @@ e_msg_composer_setup_with_message (EMsgComposer *composer,
        ESource *source = NULL;
        EHTMLEditor *editor;
        EContentEditor *cnt_editor;
-       EContentEditorContentFlags flags;
        GtkToggleAction *action;
        struct _camel_header_raw *xev;
        gchar *identity_uid;
@@ -3786,15 +3745,9 @@ e_msg_composer_setup_with_message (EMsgComposer *composer,
        composer_mode = camel_medium_get_header (
                CAMEL_MEDIUM (message), "X-Evolution-Composer-Mode");
 
-       flags = e_content_editor_get_current_content_flags (cnt_editor);
-
-       if (composer_mode && *composer_mode) {
+       if (composer_mode && *composer_mode)
                is_message_from_draft = TRUE;
 
-               flags |= E_CONTENT_EDITOR_MESSAGE_DRAFT;
-               e_content_editor_set_current_content_flags (cnt_editor, flags);
-       }
-
        if (format != NULL) {
                gchar **flags;
 
@@ -3942,9 +3895,6 @@ e_msg_composer_setup_with_message (EMsgComposer *composer,
                e_msg_composer_set_pending_body (composer, html, length, is_html);
        }
 
-       flags |= E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW;
-       e_content_editor_set_current_content_flags (cnt_editor, flags);
-
        priv->set_signature_from_message = TRUE;
 
        /* We wait until now to set the body text because we need to
diff --git a/e-util/e-content-editor.c b/e-util/e-content-editor.c
index f53b393..580c783 100644
--- a/e-util/e-content-editor.c
+++ b/e-util/e-content-editor.c
@@ -1405,35 +1405,6 @@ e_content_editor_insert_emoticon (EContentEditor *editor,
 }
 
 void
-e_content_editor_set_current_content_flags (EContentEditor *editor,
-                                            EContentEditorContentFlags flags)
-{
-       EContentEditorInterface *iface;
-
-       g_return_if_fail (E_IS_CONTENT_EDITOR (editor));
-
-       iface = E_CONTENT_EDITOR_GET_IFACE (editor);
-       g_return_if_fail (iface != NULL);
-       g_return_if_fail (iface->set_current_content_flags != NULL);
-
-       iface->set_current_content_flags (editor, flags);
-}
-
-EContentEditorContentFlags
-e_content_editor_get_current_content_flags (EContentEditor *editor)
-{
-       EContentEditorInterface *iface;
-
-       g_return_val_if_fail (E_IS_CONTENT_EDITOR (editor), 0);
-
-       iface = E_CONTENT_EDITOR_GET_IFACE (editor);
-       g_return_val_if_fail (iface != NULL, 0);
-       g_return_val_if_fail (iface->get_current_content_flags != NULL, 0);
-
-       return iface->get_current_content_flags (editor);
-}
-
-void
 e_content_editor_move_caret_on_coordinates (EContentEditor *editor,
                                             gint x,
                                             gint y,
diff --git a/e-util/e-content-editor.h b/e-util/e-content-editor.h
index 93194ff..e2c3256 100644
--- a/e-util/e-content-editor.h
+++ b/e-util/e-content-editor.h
@@ -70,12 +70,6 @@ struct _EContentEditorInterface {
        void            (*insert_emoticon)              (EContentEditor *editor,
                                                         EEmoticon *emoticon);
 
-       void            (*set_current_content_flags)    (EContentEditor *editor,
-                                                        EContentEditorContentFlags flags);
-
-       EContentEditorContentFlags
-                       (*get_current_content_flags)    (EContentEditor *editor);
-
        void            (*move_caret_on_coordinates)    (EContentEditor *editor,
                                                         gint x,
                                                         gint y,
@@ -542,14 +536,6 @@ void               e_content_editor_insert_emoticon
                                                (EContentEditor *editor,
                                                 EEmoticon *emoticon);
 
-void           e_content_editor_set_current_content_flags
-                                               (EContentEditor *editor,
-                                                EContentEditorContentFlags flags);
-
-EContentEditorContentFlags
-               e_content_editor_get_current_content_flags
-                                               (EContentEditor *editor);
-
 void           e_content_editor_move_caret_on_coordinates
                                                (EContentEditor *editor,
                                                 gint x,
diff --git a/e-util/e-mail-signature-editor.c b/e-util/e-mail-signature-editor.c
index c6afe5a..45c5f7a 100644
--- a/e-util/e-mail-signature-editor.c
+++ b/e-util/e-mail-signature-editor.c
@@ -149,14 +149,9 @@ mail_signature_editor_loaded_cb (GObject *object,
        e_content_editor_set_html_mode (cnt_editor, is_html);
 
        if (is_html) {
-               if (strstr (contents, "data-evo-signature-plain-text-mode")) {
-                       EContentEditorContentFlags flags;
+               if (strstr (contents, "data-evo-signature-plain-text-mode"))
+                       e_content_editor_set_html_mode (cnt_editor, FALSE);
 
-                       flags = e_content_editor_get_current_content_flags (cnt_editor);
-                       flags |= E_CONTENT_EDITOR_MESSAGE_DRAFT;
-
-                       e_content_editor_set_html_mode (cnt_editor, TRUE);
-               }
                e_content_editor_insert_content (
                        cnt_editor,
                        contents,
diff --git a/e-util/e-util-enums.h b/e-util/e-util-enums.h
index 55a6960..884c041 100644
--- a/e-util/e-util-enums.h
+++ b/e-util/e-util-enums.h
@@ -183,26 +183,6 @@ typedef enum {
 } EContentEditorGetContentFlags;
 
 /**
- * EContentEditorContentFlags:
- * @E_CONTENT_EDITOR_MESSAGE_NONE:
- * @E_CONTENT_EDITOR_MESSAGE_DRAFT:
- * @E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW:
- * @E_CONTENT_EDITOR_MESSAGE_EDITTING:
- * @E_CONTENT_EDITOR_MESSAGE_FROM_SELECTION:
- * @E_CONTENT_EDITOR_MESSAGE_NEW:
- *
- * Since: 3.22
- **/
-typedef enum {
-       E_CONTENT_EDITOR_MESSAGE_NONE           = 0,
-       E_CONTENT_EDITOR_MESSAGE_DRAFT          = 1 << 0,
-       E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW    = 1 << 1,
-       E_CONTENT_EDITOR_MESSAGE_EDITTING       = 1 << 2,
-       E_CONTENT_EDITOR_MESSAGE_FROM_SELECTION = 1 << 3,
-       E_CONTENT_EDITOR_MESSAGE_NEW            = 1 << 4
-} EContentEditorContentFlags;
-
-/**
  * EContentEditorNodeFlags:
  * @E_CONTENT_EDITOR_NODE_UNKNOWN: None from the below, aka when cannot determine.
  * @E_CONTENT_EDITOR_NODE_IS_ANCHOR:
diff --git a/e-util/test-html-editor.c b/e-util/test-html-editor.c
index b295abe..86502c4 100644
--- a/e-util/test-html-editor.c
+++ b/e-util/test-html-editor.c
@@ -463,9 +463,6 @@ create_new_editor_cb (GObject *source_object,
        editor = E_HTML_EDITOR (widget);
        cnt_editor = e_html_editor_get_content_editor (editor);
 
-       e_content_editor_set_current_content_flags (
-                 cnt_editor, E_CONTENT_EDITOR_MESSAGE_NEW);
-
        g_object_set (G_OBJECT (editor),
                "halign", GTK_ALIGN_FILL,
                "hexpand", TRUE,
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 915539d..3802d25 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -1353,10 +1353,6 @@ void
 em_utils_compose_new_message (EMsgComposer *composer,
                               CamelFolder *folder)
 {
-       EHTMLEditor *editor;
-       EContentEditor *cnt_editor;
-       EContentEditorContentFlags flags;
-
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
 
        if (folder != NULL)
@@ -1364,12 +1360,6 @@ em_utils_compose_new_message (EMsgComposer *composer,
 
        set_up_new_composer (composer, "", folder);
        composer_set_no_change (composer);
-       editor = e_msg_composer_get_editor (composer);
-       cnt_editor = e_html_editor_get_content_editor (editor);
-
-       flags = e_content_editor_get_current_content_flags (cnt_editor);
-       flags |= E_CONTENT_EDITOR_MESSAGE_NEW;
-       e_content_editor_set_current_content_flags (cnt_editor, flags);
 
        gtk_widget_show (GTK_WIDGET (composer));
 }
@@ -3316,7 +3306,6 @@ em_utils_reply_to_message (EMsgComposer *composer,
        ESourceMailCompositionReplyStyle prefer_reply_style = E_SOURCE_MAIL_COMPOSITION_REPLY_STYLE_DEFAULT;
        ESource *source;
        gchar *identity_uid = NULL;
-       const gchar *evo_source_header;
        guint32 flags;
 
        g_return_if_fail (E_IS_MSG_COMPOSER (composer));
@@ -3392,21 +3381,6 @@ em_utils_reply_to_message (EMsgComposer *composer,
        g_object_unref (to);
        g_object_unref (cc);
 
-       evo_source_header = camel_medium_get_header (
-               CAMEL_MEDIUM (message), "X-Evolution-Content-Source");
-       if (g_strcmp0 (evo_source_header, "selection") == 0) {
-               EHTMLEditor *editor;
-               EContentEditor *cnt_editor;
-               EContentEditorContentFlags flags;
-
-               editor = e_msg_composer_get_editor (composer);
-               cnt_editor = e_html_editor_get_content_editor (editor);
-
-               flags = e_content_editor_get_current_content_flags (cnt_editor);
-               flags |= E_CONTENT_EDITOR_MESSAGE_FROM_SELECTION;
-               e_content_editor_set_current_content_flags (cnt_editor, flags);
-       }
-
        /* If there was no send-account override */
        if (!identity_uid) {
                EComposerHeaderTable *header_table;
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 9e55540..b7d1c82 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -114,8 +114,6 @@ struct _EWebKitEditorPrivate {
 
        GHashTable *old_settings;
 
-       EContentEditorContentFlags content_flags;
-
        ESpellChecker *spell_checker;
        gboolean spell_check_enabled;
 
@@ -1379,7 +1377,8 @@ webkit_editor_insert_content (EContentEditor *editor,
                 * when the extension is ready */
                if (!((flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL) &&
                      (flags & E_CONTENT_EDITOR_INSERT_TEXT_HTML) &&
-                     (wk_editor->priv->content_flags & E_CONTENT_EDITOR_MESSAGE_DRAFT))) {
+                     (strstr (content, "data-evo-draft") ||
+                      strstr (content, "data-evo-signature-plain-text-mode")))) {
                        webkit_editor_queue_post_reload_operation (
                                wk_editor,
                                (PostReloadOperationFunc) webkit_editor_insert_content,
@@ -1410,14 +1409,14 @@ webkit_editor_insert_content (EContentEditor *editor,
                        NULL);
        } else if ((flags & E_CONTENT_EDITOR_INSERT_REPLACE_ALL) &&
                   (flags & E_CONTENT_EDITOR_INSERT_TEXT_HTML)) {
-               if (wk_editor->priv->content_flags & E_CONTENT_EDITOR_MESSAGE_DRAFT) {
+               if ((strstr (content, "data-evo-draft") ||
+                    strstr (content, "data-evo-signature-plain-text-mode"))) {
                        wk_editor->priv->reload_in_progress = TRUE;
                        webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), content, "file://");
                        return;
                }
 
-               if ((wk_editor->priv->content_flags & E_CONTENT_EDITOR_MESSAGE_DRAFT) &&
-                   !(wk_editor->priv->html_mode)) {
+               if (strstr (content, "data-evo-draft") && !(wk_editor->priv->html_mode)) {
                        if (content && *content)
                                set_convert_in_situ (wk_editor, TRUE);
                        wk_editor->priv->reload_in_progress = TRUE;
@@ -1787,42 +1786,6 @@ webkit_editor_insert_image_from_mime_part (EContentEditor *editor,
        g_object_unref (stream);
 }
 
-static EContentEditorContentFlags
-webkit_editor_get_current_content_flags (EContentEditor *editor)
-{
-       EWebKitEditor *wk_editor;
-
-       wk_editor = E_WEBKIT_EDITOR (editor);
-
-       return wk_editor->priv->content_flags;
-}
-
-static void
-webkit_editor_set_current_content_flags (EContentEditor *editor,
-                                         EContentEditorContentFlags flags)
-{
-       EWebKitEditor *wk_editor;
-
-       wk_editor = E_WEBKIT_EDITOR (editor);
-
-       wk_editor->priv->content_flags = flags;
-
-       if (!wk_editor->priv->web_extension) {
-               g_warning ("EHTMLEditorWebExtension not ready at %s!", G_STRFUNC);
-               return;
-       }
-
-       g_dbus_proxy_call (
-               wk_editor->priv->web_extension,
-               "SetCurrentContentFlags",
-               g_variant_new ("(ti)", current_page_id (wk_editor), (gint32) flags),
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               NULL,
-               NULL);
-}
-
 static void
 webkit_editor_select_all (EContentEditor *editor)
 {
@@ -6039,7 +6002,6 @@ e_webkit_editor_init (EWebKitEditor *wk_editor)
        wk_editor->priv->copy_paste_primary_in_view = FALSE;
        wk_editor->priv->copy_cut_actions_triggered = FALSE;
        wk_editor->priv->pasting_primary_clipboard = FALSE;
-       wk_editor->priv->content_flags = 0;
        wk_editor->priv->current_user_stylesheet = NULL;
        wk_editor->priv->emit_load_finished_when_extension_is_ready = FALSE;
 
@@ -6065,8 +6027,6 @@ e_webkit_editor_content_editor_init (EContentEditorInterface *iface)
        iface->insert_image = webkit_editor_insert_image;
        iface->insert_image_from_mime_part = webkit_editor_insert_image_from_mime_part;
        iface->insert_emoticon = webkit_editor_insert_emoticon;
-       iface->set_current_content_flags = webkit_editor_set_current_content_flags;
-       iface->get_current_content_flags = webkit_editor_get_current_content_flags;
        iface->move_caret_on_coordinates = webkit_editor_move_caret_on_coordinates;
        iface->cut = webkit_editor_cut;
        iface->copy = webkit_editor_copy;
diff --git a/modules/webkit-editor/web-extension/e-composer-dom-functions.c 
b/modules/webkit-editor/web-extension/e-composer-dom-functions.c
index 398cb38..6a33960 100644
--- a/modules/webkit-editor/web-extension/e-composer-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-composer-dom-functions.c
@@ -154,10 +154,6 @@ move_caret_after_signature_inserted (EEditorPage *editor_page)
        WebKitDOMElement *element, *signature;
        WebKitDOMHTMLElement *body;
        WebKitDOMNodeList *paragraphs;
-       EContentEditorContentFlags flags;
-       gboolean is_message_from_draft;
-       gboolean is_message_from_edit_as_new;
-       gboolean is_from_new_message;
        gboolean top_signature;
        gboolean start_bottom;
        gboolean has_paragraphs_in_body = TRUE;
@@ -165,48 +161,13 @@ move_caret_after_signature_inserted (EEditorPage *editor_page)
        g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
 
        document = e_editor_page_get_document (editor_page);
-       flags = e_editor_page_get_current_content_flags (editor_page);
-
-       is_message_from_draft = (flags & E_CONTENT_EDITOR_MESSAGE_DRAFT);
-       is_message_from_edit_as_new = (flags & E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW);
-       is_from_new_message = (flags & E_CONTENT_EDITOR_MESSAGE_NEW);
-
-       top_signature =
-               use_top_signature () &&
-               !is_message_from_edit_as_new &&
-               !is_from_new_message;
 
+       top_signature = use_top_signature ();
        start_bottom = start_typing_at_bottom ();
 
        body = webkit_dom_document_get_body (document);
-       webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (body), "data-message", "", NULL);
-
-       /* If editing message as new don't handle with caret */
-       if (is_message_from_edit_as_new || is_message_from_draft) {
-               if (is_message_from_edit_as_new)
-                       webkit_dom_element_set_attribute (
-                               WEBKIT_DOM_ELEMENT (body),
-                               "data-edit-as-new",
-                               "",
-                               NULL);
-
-               if (is_message_from_edit_as_new && !is_message_from_draft) {
-                       element = WEBKIT_DOM_ELEMENT (body);
-                       e_editor_page_block_selection_changed (editor_page);
-                       goto move_caret;
-               } else
-                       e_editor_dom_scroll_to_caret (editor_page);
-
-               return;
-       }
        e_editor_page_block_selection_changed (editor_page);
 
-       /* When the new message is written from the beginning - note it into body */
-       if (is_from_new_message)
-               webkit_dom_element_set_attribute (
-                       WEBKIT_DOM_ELEMENT (body), "data-new-message", "", NULL);
-
        paragraphs = webkit_dom_document_query_selector_all (document, "[data-evo-paragraph]", NULL);
        signature = webkit_dom_document_query_selector (document, ".-x-evo-signature-wrapper", NULL);
        /* Situation when wrapped paragraph is just in signature and not in message body */
@@ -360,11 +321,9 @@ e_composer_dom_insert_signature (EEditorPage *editor_page,
        WebKitDOMElement *element, *converted_signature = NULL;
        WebKitDOMHTMLElement *body;
        WebKitDOMHTMLCollection *signatures;
-       EContentEditorContentFlags flags;
        gchar *new_signature_id = NULL;
        gchar *signature_text = NULL;
-       gboolean top_signature, html_mode, is_message_from_edit_as_new;
-       gboolean is_message_from_draft, is_from_new_message;
+       gboolean top_signature, html_mode;
        gulong list_length, ii;
 
        g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), NULL);
@@ -373,18 +332,10 @@ e_composer_dom_insert_signature (EEditorPage *editor_page,
        g_return_val_if_fail (ignore_next_signature_change != NULL, NULL);
 
        document = e_editor_page_get_document (editor_page);
-       flags = e_editor_page_get_current_content_flags (editor_page);
-
-       is_message_from_draft = (flags & E_CONTENT_EDITOR_MESSAGE_DRAFT);
-       is_message_from_edit_as_new = (flags & E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW);
-       is_from_new_message = (flags & E_CONTENT_EDITOR_MESSAGE_NEW);
 
        /* "Edit as New Message" sets is_message_from_edit_as_new.
         * Always put the signature at the bottom for that case. */
-       top_signature =
-               use_top_signature () &&
-               !is_message_from_edit_as_new &&
-               !is_from_new_message;
+       top_signature = use_top_signature ();
 
        html_mode = e_editor_page_get_html_mode (editor_page);
 
@@ -507,8 +458,7 @@ insert:
                /* When we are editing a message with signature, we need to unset the
                 * active signature id as if the signature in the message was edited
                 * by the user we would discard these changes. */
-               if (*set_signature_from_message &&
-                   (is_message_from_edit_as_new || is_message_from_draft)) {
+               if (*set_signature_from_message) {
                        if (*check_if_signature_is_changed) {
                                /* Normalize the signature that we want to insert as the one in the
                                 * message already is normalized. */
diff --git a/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index d340567..c1df19b 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -5389,10 +5389,6 @@ parse_html_into_blocks (EEditorPage *editor_page,
                        child = webkit_dom_node_get_last_child (
                                WEBKIT_DOM_NODE (parent));
                        if (child) {
-                               EContentEditorContentFlags flags;
-
-                               flags = e_editor_page_get_current_content_flags (editor_page);
-
                                child = webkit_dom_node_get_first_child (child);
                                if (child && WEBKIT_DOM_IS_HTML_BR_ELEMENT (child)) {
                                        /* If the processed HTML contained just
@@ -5401,7 +5397,7 @@ parse_html_into_blocks (EEditorPage *editor_page,
                                                webkit_dom_element_set_id (
                                                        WEBKIT_DOM_ELEMENT (child),
                                                        "-x-evo-last-br");
-                               } else if (!(flags & E_CONTENT_EDITOR_MESSAGE_EDITTING))
+                               } else if (!webkit_dom_document_query_selector (document, 
".-x-evo-signature-wrapper", NULL))
                                        create_and_append_new_block (editor_page, parent, block_template, 
"<br>");
                        } else
                                create_and_append_new_block (editor_page, parent, block_template, "<br>");
@@ -5833,7 +5829,6 @@ e_editor_dom_convert_content (EEditorPage *editor_page,
        WebKitDOMNodeList *list;
        WebKitDOMNode *node;
        WebKitDOMDOMWindow *dom_window;
-       EContentEditorContentFlags flags;
        gboolean start_bottom, empty = FALSE;
        gchar *inner_html;
        gint ii, length;
@@ -5846,16 +5841,11 @@ e_editor_dom_convert_content (EEditorPage *editor_page,
        start_bottom = g_settings_get_boolean (settings, "composer-reply-start-bottom");
        g_object_unref (settings);
 
-       flags = e_editor_page_get_current_content_flags (editor_page);
-
        dom_window = webkit_dom_document_get_default_view (document);
        body = webkit_dom_document_get_body (document);
        /* Wrapper that will represent the new body. */
        wrapper = webkit_dom_document_create_element (document, "div", NULL);
 
-       webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (body), "data-converted", "", NULL);
-
        cite_body = webkit_dom_document_query_selector (
                document, "span.-x-evo-cite-body", NULL);
 
@@ -6057,9 +6047,7 @@ e_editor_dom_convert_content (EEditorPage *editor_page,
        /* If not editing a message, don't add any new block and just place
         * the caret in the beginning of content. We want to have the same
         * behaviour when editing message as new or we start replying on top. */
-       if ((flags & E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW) ||
-           !(flags & E_CONTENT_EDITOR_MESSAGE_EDITTING) ||
-            !start_bottom) {
+       if (!signature && !start_bottom) {
                WebKitDOMNode *child;
 
                remove_node (WEBKIT_DOM_NODE (paragraph));
@@ -8089,41 +8077,26 @@ process_content_to_plain_text_changing_composer_mode (EEditorPage *editor_page)
 gchar *
 e_editor_dom_process_content_to_plain_text_for_exporting (EEditorPage *editor_page)
 {
-       EContentEditorContentFlags flags;
        WebKitDOMDocument *document;
        WebKitDOMNode *body, *source;
        WebKitDOMNodeList *paragraphs;
-       gboolean wrap = FALSE, quote = FALSE;
-       gboolean converted, is_new_message, is_message_draft;
+       gboolean wrap = FALSE, quote = FALSE, remove_last_new_line = FALSE;
        gint length, ii;
        GString *plain_text;
 
        g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), NULL);
 
        document = e_editor_page_get_document (editor_page);
-       flags = e_editor_page_get_current_content_flags (editor_page);
        plain_text = g_string_sized_new (1024);
 
        body = WEBKIT_DOM_NODE (webkit_dom_document_get_body (document));
-       converted = webkit_dom_element_has_attribute (
-               WEBKIT_DOM_ELEMENT (body), "data-converted");
-       is_new_message = (flags & E_CONTENT_EDITOR_MESSAGE_NEW);
-       is_message_draft = (flags & E_CONTENT_EDITOR_MESSAGE_DRAFT);
-
        source = webkit_dom_node_clone_node_with_error (WEBKIT_DOM_NODE (body), TRUE, NULL);
 
        e_editor_dom_selection_save (editor_page);
 
        /* If composer is in HTML mode we have to move the content to plain version */
        if (e_editor_page_get_html_mode (editor_page)) {
-               if (converted || is_new_message || is_message_draft) {
-                       toggle_paragraphs_style_in_element (
-                               editor_page, WEBKIT_DOM_ELEMENT (source), FALSE);
-                       remove_images_in_element (
-                               WEBKIT_DOM_ELEMENT (source));
-                       remove_background_images_in_element (
-                               WEBKIT_DOM_ELEMENT (source));
-               } else {
+               if (e_editor_dom_check_if_conversion_needed (editor_page)) {
                        WebKitDOMElement *div;
                        WebKitDOMNode *child;
 
@@ -8155,6 +8128,15 @@ e_editor_dom_process_content_to_plain_text_for_exporting (EEditorPage *editor_pa
                                editor_page, div, &wrap, &quote);
 
                        source = WEBKIT_DOM_NODE (div);
+
+                       remove_last_new_line = TRUE;
+               } else {
+                       toggle_paragraphs_style_in_element (
+                               editor_page, WEBKIT_DOM_ELEMENT (source), FALSE);
+                       remove_images_in_element (
+                               WEBKIT_DOM_ELEMENT (source));
+                       remove_background_images_in_element (
+                               WEBKIT_DOM_ELEMENT (source));
                }
        }
 
@@ -8408,9 +8390,6 @@ e_editor_dom_convert_when_changing_composer_mode (EEditorPage *editor_page)
 
        clear_attributes (editor_page);
 
-       webkit_dom_element_set_attribute (
-               WEBKIT_DOM_ELEMENT (body), "data-converted", "", NULL);
-
        e_editor_dom_force_spell_check_in_viewport (editor_page);
        e_editor_dom_scroll_to_caret (editor_page);
 }
@@ -10442,12 +10421,51 @@ e_editor_dom_key_press_event_process_delete_or_backspace_key (EEditorPage *edito
 static gboolean
 contains_forbidden_elements (WebKitDOMDocument *document)
 {
-       WebKitDOMElement *element;
+       WebKitDOMElement *body, *element;
 
-       element = webkit_dom_document_query_selector (
-               document,
-               "b, i , u, table, hr, tt, font, sub, sup, h1, h2, h3, h4, h5, h6, "
-               "address, img:not([data-inline])",
+       body = WEBKIT_DOM_ELEMENT (webkit_dom_document_get_body (document));
+
+       /* Try to find disallowed elements in the plain text mode */
+       element = webkit_dom_element_query_selector (
+               body,
+               ":not("
+               /* Basic elements used as blocks allowed in the plain text mode */
+               "p[data-evo-paragraph], pre, ul, ol, li, blockquote[type=cite], "
+               /* Other elements */
+               "br, a, "
+               /* Indented elements */
+               ".-x-evo-indented, "
+               /* Signature */
+               ".-x-evo-signature-wrapper, .-x-evo-signature, "
+               /* Smileys */
+               ".-x-evo-smiley-wrapper, .-x-evo-smiley-img, .-x-evo-smiley-text, "
+               /* Selection markers */
+               "#-x-evo-selection-start-marker, #-x-evo-selection-end-marker"
+               ")",
+               NULL);
+
+       if (element)
+               return TRUE;
+
+       /* Try to find disallowed elements relationship in the plain text */
+       element = webkit_dom_element_query_selector (
+               body,
+               ":not("
+               /* Body descendants */
+               "body > :matches(blockquote[type=cite], .-x-evo-signature-wrapper), "
+               /* Main blocks and indented blocks */
+               ":matches(body, .-x-evo-indented) > :matches(pre, p, ul, ol, .-x-evo-indented), "
+               /* Blockquote descendants */
+               "blockquote[type=cite] > :matches(pre, p, blockquote[type=cite]), "
+               /* Block descendants */
+               ":matches(pre, p, li) > :matches(br, span, a), "
+               /* Lists */
+               ":matches(ul, ol) > :matches(ul, ol, li), "
+               /* Smileys */
+               ".-x-evo-smiley-wrapper > :matches(.-x-evo-smiley-img, .-x-evo-smiley-text), "
+               /* Signature */
+               ".-x-evo-signature-wrapper > .-x-evo-signature"
+               ")",
                NULL);
 
        return element ? TRUE : FALSE;
@@ -10456,35 +10474,18 @@ contains_forbidden_elements (WebKitDOMDocument *document)
 gboolean
 e_editor_dom_check_if_conversion_needed (EEditorPage *editor_page)
 {
-       EContentEditorContentFlags flags;
        WebKitDOMDocument *document;
-       WebKitDOMHTMLElement *body;
-       gboolean is_new_message, converted, edit_as_new, message, convert;
-       gboolean reply, hide, html_mode, message_from_draft;
+       gboolean html_mode, convert = FALSE;
 
        g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), FALSE);
 
        document = e_editor_page_get_document (editor_page);
        html_mode = e_editor_page_get_html_mode (editor_page);
 
-       flags = e_editor_page_get_current_content_flags (editor_page);
-       message_from_draft = (flags & E_CONTENT_EDITOR_MESSAGE_DRAFT);
-       is_new_message = (flags & E_CONTENT_EDITOR_MESSAGE_NEW);
-       edit_as_new = (flags & E_CONTENT_EDITOR_MESSAGE_EDIT_AS_NEW);
-       message = (flags & E_CONTENT_EDITOR_MESSAGE_EDITTING);
-
-       body = webkit_dom_document_get_body (document);
-       converted = webkit_dom_element_has_attribute (
-               WEBKIT_DOM_ELEMENT (body), "data-converted");
-
-       reply = !is_new_message && !edit_as_new && message;
-       hide = !reply && !converted;
-
-       convert = message && ((!hide && reply && !converted) || (edit_as_new && !converted));
-       convert = convert && !is_new_message;
+       if (html_mode)
+               convert = contains_forbidden_elements (document);
 
-       /* We need to count with the opposite value of html_mode as we are changing the mode. */
-       return html_mode && (contains_forbidden_elements (document) || (convert && !message_from_draft));
+       return convert;
 }
 
 void
diff --git a/modules/webkit-editor/web-extension/e-editor-page.c 
b/modules/webkit-editor/web-extension/e-editor-page.c
index 87ba8fc..0b639b3 100644
--- a/modules/webkit-editor/web-extension/e-editor-page.c
+++ b/modules/webkit-editor/web-extension/e-editor-page.c
@@ -69,8 +69,6 @@ struct _EEditorPagePrivate {
        WebKitDOMNode *node_under_mouse_click;
 
        GSettings *mail_settings;
-
-       EContentEditorContentFlags content_flags;
 };
 
 G_DEFINE_TYPE (EEditorPage, e_editor_page, G_TYPE_OBJECT)
@@ -256,7 +254,6 @@ e_editor_page_init (EEditorPage *editor_page)
        editor_page->priv->pasting_content_from_itself = FALSE;
        editor_page->priv->composition_in_progress = FALSE;
        editor_page->priv->renew_history_after_coordinates = TRUE;
-       editor_page->priv->content_flags = 0;
        editor_page->priv->spell_check_on_scroll_event_source_id = 0;
        editor_page->priv->mail_settings = e_util_ref_settings ("org.gnome.evolution.mail");
        editor_page->priv->word_wrap_length = g_settings_get_int (editor_page->priv->mail_settings, 
"composer-word-wrap-length");
@@ -549,23 +546,6 @@ e_editor_page_set_alignment (EEditorPage *editor_page,
        editor_page->priv->alignment = value;
 }
 
-EContentEditorContentFlags
-e_editor_page_get_current_content_flags (EEditorPage *editor_page)
-{
-       g_return_val_if_fail (E_IS_EDITOR_PAGE (editor_page), 0);
-
-       return editor_page->priv->content_flags;
-}
-
-void
-e_editor_page_set_current_content_flags (EEditorPage *editor_page,
-                                        guint flags)
-{
-       g_return_if_fail (E_IS_EDITOR_PAGE (editor_page));
-
-       editor_page->priv->content_flags = flags;
-}
-
 gboolean
 e_editor_page_get_return_key_pressed (EEditorPage *editor_page)
 {
diff --git a/modules/webkit-editor/web-extension/e-editor-page.h 
b/modules/webkit-editor/web-extension/e-editor-page.h
index 95f833c..160b9ae 100644
--- a/modules/webkit-editor/web-extension/e-editor-page.h
+++ b/modules/webkit-editor/web-extension/e-editor-page.h
@@ -112,12 +112,6 @@ void               e_editor_page_set_alignment     (EEditorPage *editor_page,
                                                 EContentEditorAlignment value);
 gint           e_editor_page_get_word_wrap_length
                                                (EEditorPage *editor_page);
-EContentEditorContentFlags
-               e_editor_page_get_current_content_flags
-                                               (EEditorPage *editor_page);
-void           e_editor_page_set_current_content_flags
-                                               (EEditorPage *editor_page,
-                                                guint flags);
 gboolean       e_editor_page_get_return_key_pressed
                                                (EEditorPage *editor_page);
 void           e_editor_page_set_return_key_pressed
diff --git a/modules/webkit-editor/web-extension/e-editor-web-extension.c 
b/modules/webkit-editor/web-extension/e-editor-web-extension.c
index 60ace08..ed87a5d 100644
--- a/modules/webkit-editor/web-extension/e-editor-web-extension.c
+++ b/modules/webkit-editor/web-extension/e-editor-web-extension.c
@@ -394,10 +394,6 @@ static const gchar *introspection_xml =
 "<!-- ********************************************************* -->"
 "<!--     Functions that are used in EEditorView            -->"
 "<!-- ********************************************************* -->"
-"    <method name='SetCurrentContentFlags'>"
-"      <arg type='t' name='page_id' direction='in'/>"
-"      <arg type='i' name='content_flags' direction='in'/>"
-"    </method>"
 "    <method name='SetPastingContentFromItself'>"
 "      <arg type='t' name='page_id' direction='in'/>"
 "      <arg type='b' name='value' direction='in'/>"
@@ -1710,17 +1706,6 @@ handle_method_call (GDBusConnection *connection,
 
                e_editor_dom_remove_embedded_style_sheet (editor_page);
                g_dbus_method_invocation_return_value (invocation, NULL);
-       } else if (g_strcmp0 (method_name, "SetCurrentContentFlags") == 0) {
-               guint content_flags = 0;
-
-               g_variant_get (parameters, "(ti)", &page_id, &content_flags);
-
-               editor_page = get_editor_page_or_return_dbus_error (invocation, extension, page_id);
-               if (!editor_page)
-                       goto error;
-
-               e_editor_page_set_current_content_flags (editor_page, content_flags);
-               g_dbus_method_invocation_return_value (invocation, NULL);
        } else if (g_strcmp0 (method_name, "SetPastingContentFromItself") == 0) {
                gboolean value = FALSE;
 


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