[evolution/gnome-3-24] Bug 782470 - Style <blockquote> in HTML replies



commit 229e11d8d0d9aa10fb019146a764759d3676dc99
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 8 18:37:05 2017 +0200

    Bug 782470 - Style <blockquote> in HTML replies

 .../web-extension/e-editor-dom-functions.c         |   47 ++++++++++++++++--
 src/web-extensions/e-dom-utils.c                   |   52 ++++++++++++++++++++
 src/web-extensions/e-dom-utils.h                   |    4 ++
 src/web-extensions/e-web-extension.c               |    1 +
 4 files changed, 99 insertions(+), 5 deletions(-)
---
diff --git a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c 
b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
index 016ae3a..8b32b25 100644
--- a/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
+++ b/src/modules/webkit-editor/web-extension/e-editor-dom-functions.c
@@ -1400,10 +1400,10 @@ move_elements_to_body (EEditorPage *editor_page)
 }
 
 static void
-repair_gmail_blockquotes (WebKitDOMDocument *document)
+repair_blockquotes (WebKitDOMDocument *document)
 {
-       WebKitDOMHTMLCollection *collection = NULL;
-       gint ii;
+       WebKitDOMHTMLCollection *collection;
+       gulong ii;
 
        collection = webkit_dom_document_get_elements_by_class_name_as_html_collection (
                document, "gmail_quote");
@@ -1427,6 +1427,39 @@ repair_gmail_blockquotes (WebKitDOMDocument *document)
                                NULL);
        }
        g_clear_object (&collection);
+
+       collection = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "blockquote");
+       for (ii = webkit_dom_html_collection_get_length (collection); ii--;) {
+               WebKitDOMNode *node = webkit_dom_html_collection_item (collection, ii);
+
+               if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
+                       continue;
+
+               webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "class");
+               webkit_dom_element_remove_attribute (WEBKIT_DOM_ELEMENT (node), "style");
+               webkit_dom_element_set_attribute (WEBKIT_DOM_ELEMENT (node), "type", "cite", NULL);
+       }
+       g_clear_object (&collection);
+}
+
+static void
+style_blockquotes (WebKitDOMElement *element)
+{
+       WebKitDOMNodeList *list;
+       gulong ii;
+
+       g_return_if_fail (WEBKIT_DOM_IS_ELEMENT (element));
+
+       list = webkit_dom_element_query_selector_all (element, "blockquote", NULL);
+       for (ii = webkit_dom_node_list_get_length (list); ii--;) {
+               WebKitDOMNode *node = webkit_dom_node_list_item (list, ii);
+
+               if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
+                       continue;
+
+               webkit_dom_element_set_attribute (WEBKIT_DOM_ELEMENT (node), "style", 
E_EVOLUTION_BLOCKQUOTE_STYLE, NULL);
+       }
+       g_clear_object (&list);
 }
 
 static void
@@ -6112,7 +6145,7 @@ e_editor_dom_convert_content (EEditorPage *editor_page,
        }
        g_clear_object (&list);
 
-       repair_gmail_blockquotes (document);
+       repair_blockquotes (document);
        remove_thunderbird_signature (document);
        create_text_markers_for_citations_in_element (WEBKIT_DOM_ELEMENT (body));
 
@@ -8059,6 +8092,9 @@ e_editor_dom_process_content_for_draft (EEditorPage *editor_page,
        }
        g_clear_object (&list);
 
+       if (e_editor_page_get_html_mode (editor_page))
+               style_blockquotes (WEBKIT_DOM_ELEMENT (document_element_clone));
+
        if (only_inner_body) {
                WebKitDOMElement *body;
                WebKitDOMNode *first_child;
@@ -8522,6 +8558,7 @@ e_editor_dom_process_content_to_html_for_exporting (EEditorPage *editor_page)
        }
        g_clear_object (&list);
 
+       style_blockquotes (WEBKIT_DOM_ELEMENT (node));
        process_node_to_html_for_exporting (editor_page, node);
 
        html_content = webkit_dom_element_get_outer_html (
@@ -8754,7 +8791,7 @@ e_editor_dom_process_content_after_load (EEditorPage *editor_page)
        dom_set_links_active (document, FALSE);
        put_body_in_citation (document);
        move_elements_to_body (editor_page);
-       repair_gmail_blockquotes (document);
+       repair_blockquotes (document);
        remove_thunderbird_signature (document);
 
        if (webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (body), "data-evo-draft")) {
diff --git a/src/web-extensions/e-dom-utils.c b/src/web-extensions/e-dom-utils.c
index 3fdcadc..386fdcf 100644
--- a/src/web-extensions/e-dom-utils.c
+++ b/src/web-extensions/e-dom-utils.c
@@ -1044,6 +1044,58 @@ e_dom_utils_e_mail_display_bind_dom (WebKitDOMDocument *document,
 }
 
 void
+e_dom_utils_e_mail_display_unstyle_blockquotes (WebKitDOMDocument *document)
+{
+       WebKitDOMHTMLCollection *collection;
+       gulong ii;
+
+       g_return_if_fail (WEBKIT_DOM_IS_DOCUMENT (document));
+
+       collection = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "blockquote");
+       for (ii = webkit_dom_html_collection_get_length (collection); ii--;) {
+               WebKitDOMNode *node = webkit_dom_html_collection_item (collection, ii);
+               WebKitDOMElement *elem;
+               gchar *tmp;
+
+               if (!WEBKIT_DOM_IS_HTML_QUOTE_ELEMENT (node))
+                       continue;
+
+               elem = WEBKIT_DOM_ELEMENT (node);
+
+               if (!webkit_dom_element_has_attribute (elem, "type")) {
+                       webkit_dom_element_set_attribute (elem, "type", "cite", NULL);
+                       webkit_dom_element_remove_attribute (elem, "style");
+               } else {
+                       tmp = webkit_dom_element_get_attribute (elem, "type");
+                       if (g_strcmp0 (tmp, "cite") == 0)
+                               webkit_dom_element_remove_attribute (elem, "style");
+                       g_free (tmp);
+               }
+
+               tmp = webkit_dom_element_get_attribute (elem, "style");
+               if (g_strcmp0 (tmp, E_EVOLUTION_BLOCKQUOTE_STYLE) == 0)
+                       webkit_dom_element_remove_attribute (elem, "style");
+               g_free (tmp);
+       }
+       g_clear_object (&collection);
+
+       collection = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "iframe");
+       for (ii = webkit_dom_html_collection_get_length (collection); ii--;) {
+               WebKitDOMHTMLIFrameElement *iframe;
+               WebKitDOMDocument *content_document;
+
+               iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (webkit_dom_html_collection_item (collection, ii));
+
+               content_document = webkit_dom_html_iframe_element_get_content_document (iframe);
+               if (!content_document)
+                       continue;
+
+               e_dom_utils_e_mail_display_unstyle_blockquotes (content_document);
+       }
+       g_clear_object (&collection);
+}
+
+void
 e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
 {
        e_dom_utils_bind_dom (
diff --git a/src/web-extensions/e-dom-utils.h b/src/web-extensions/e-dom-utils.h
index 38bf3e2..09d76de 100644
--- a/src/web-extensions/e-dom-utils.h
+++ b/src/web-extensions/e-dom-utils.h
@@ -30,6 +30,8 @@
 #define UNICODE_ZERO_WIDTH_SPACE "\xe2\x80\x8b"
 #define UNICODE_NBSP "\xc2\xa0"
 
+#define E_EVOLUTION_BLOCKQUOTE_STYLE "margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"
+
 G_BEGIN_DECLS
 
 void           e_dom_utils_replace_local_image_links
@@ -65,6 +67,8 @@ void          e_dom_resize_document_content_to_preview_width
 void           e_dom_utils_e_mail_display_bind_dom
                                                (WebKitDOMDocument *document,
                                                 GDBusConnection *connection);
+void           e_dom_utils_e_mail_display_unstyle_blockquotes
+                                               (WebKitDOMDocument *document);
 WebKitDOMElement *
                e_dom_utils_find_element_by_selector
                                                (WebKitDOMDocument *document,
diff --git a/src/web-extensions/e-web-extension.c b/src/web-extensions/e-web-extension.c
index 681e83a..a4a7ce6 100644
--- a/src/web-extensions/e-web-extension.c
+++ b/src/web-extensions/e-web-extension.c
@@ -849,6 +849,7 @@ handle_method_call (GDBusConnection *connection,
                        return;
 
                document = webkit_web_page_get_dom_document (web_page);
+               e_dom_utils_e_mail_display_unstyle_blockquotes (document);
                e_dom_utils_e_mail_display_bind_dom (document, connection);
                e_web_extension_bind_focus_on_elements (extension, document);
 


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