[evolution/wip/webkit2] EHTMLEditorView - Correct the situations when the 'Lose formatting' dialog is showed



commit cd5b5deeb788d027b3113a594b76d54c9989856e
Author: Tomas Popela <tpopela redhat com>
Date:   Thu Jun 30 11:48:36 2016 +0200

    EHTMLEditorView - Correct the situations when the 'Lose formatting' dialog is showed
    
    Don't show it when the message is a draft and show it when there are some of the
    HTML elements that does not belong to plain text mode.

 modules/webkit-editor/e-webkit-editor.c            |    2 +-
 .../web-extension/e-editor-dom-functions.c         |   22 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/modules/webkit-editor/e-webkit-editor.c b/modules/webkit-editor/e-webkit-editor.c
index 19865a8..02783f6 100644
--- a/modules/webkit-editor/e-webkit-editor.c
+++ b/modules/webkit-editor/e-webkit-editor.c
@@ -1255,7 +1255,7 @@ webkit_editor_set_html_mode (EWebKitEditor *wk_editor,
 
        /* If toggling from HTML to the plain text mode, ask the user first if
         * he wants to convert the content. */
-       if (convert && wk_editor->priv->html_mode && !html_mode)
+       if (convert)
                if (!show_lose_formatting_dialog (wk_editor))
                        return;
 
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 992384b..d51713b 100644
--- a/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -10348,17 +10348,35 @@ e_editor_dom_key_press_event_process_delete_or_backspace_key (EEditorPage *edito
        return TRUE;
 }
 
+static gboolean
+contains_forbidden_elements (WebKitDOMDocument *document)
+{
+       WebKitDOMElement *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])",
+               NULL);
+
+       return element ? TRUE : FALSE;
+}
+
 gboolean
 e_editor_dom_check_if_conversion_needed (EEditorPage *editor_page)
 {
+       EContentEditorContentFlags flags;
        WebKitDOMDocument *document;
        WebKitDOMHTMLElement *body;
        gboolean is_from_new_message, converted, edit_as_new, message, convert;
-       gboolean reply, hide;
+       gboolean reply, hide, html_mode, message_from_draft;
 
        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);
        body = webkit_dom_document_get_body (document);
 
        is_from_new_message = webkit_dom_element_has_attribute (
@@ -10376,7 +10394,7 @@ e_editor_dom_check_if_conversion_needed (EEditorPage *editor_page)
        convert = message && ((!hide && reply && !converted) || (edit_as_new && !converted));
        convert = convert && !is_from_new_message;
 
-       return convert;
+       return !html_mode && (contains_forbidden_elements (document) || (convert && !message_from_draft));
 }
 
 static void


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