Commit 13ebd784 authored by Milan Crha's avatar Milan Crha
Browse files

Bug 782470 - Style <blockquote> in HTML replies

parent f2717be2
......@@ -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")) {
......
......@@ -1043,6 +1043,58 @@ e_dom_utils_e_mail_display_bind_dom (WebKitDOMDocument *document,
e_dom_resize_document_content_to_preview_width (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)
{
......
......@@ -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,
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment