diff options
-rw-r--r-- | addressbook/gui/widgets/eab-contact-formatter.c | 4 | ||||
-rw-r--r-- | calendar/gui/e-cal-component-preview.c | 10 | ||||
-rw-r--r-- | data/webview.css | 2 | ||||
-rw-r--r-- | e-util/e-web-view.c | 263 | ||||
-rw-r--r-- | e-util/e-web-view.h | 7 | ||||
-rw-r--r-- | em-format/e-mail-formatter-error.c | 14 | ||||
-rw-r--r-- | em-format/e-mail-formatter-headers.c | 20 | ||||
-rw-r--r-- | em-format/e-mail-formatter-message-rfc822.c | 10 | ||||
-rw-r--r-- | em-format/e-mail-formatter-source.c | 29 | ||||
-rw-r--r-- | em-format/e-mail-formatter-text-enriched.c | 14 | ||||
-rw-r--r-- | em-format/e-mail-formatter-text-html.c | 8 | ||||
-rw-r--r-- | em-format/e-mail-formatter-text-plain.c | 35 | ||||
-rw-r--r-- | em-format/e-mail-formatter.c | 33 | ||||
-rw-r--r-- | em-format/e-mail-formatter.h | 2 | ||||
-rw-r--r-- | mail/e-mail-display.c | 101 | ||||
-rw-r--r-- | modules/text-highlight/e-mail-formatter-text-highlight.c | 11 |
16 files changed, 398 insertions, 165 deletions
diff --git a/addressbook/gui/widgets/eab-contact-formatter.c b/addressbook/gui/widgets/eab-contact-formatter.c index 60beefa5c3..71f7275182 100644 --- a/addressbook/gui/widgets/eab-contact-formatter.c +++ b/addressbook/gui/widgets/eab-contact-formatter.c @@ -747,7 +747,7 @@ render_normal (EABContactFormatter *formatter, GString *buffer) { g_string_append (buffer, HTML_HEADER); - g_string_append (buffer, "<body bgcolor=\"white\">"); + g_string_append (buffer,"<body class=\"-e-web-view-background-color -e-web-view-text-color\">"); if (contact != NULL) { if (e_contact_get (contact, E_CONTACT_IS_LIST)) @@ -769,7 +769,7 @@ render_compact (EABContactFormatter *formatter, EContactPhoto *photo; g_string_append (buffer, HTML_HEADER); - g_string_append (buffer, "<body>\n"); + g_string_append (buffer,"<body class=\"-e-web-view-background-color -e-web-view-text-color\">"); if (contact == NULL) { g_string_append (buffer, "</body></html>"); diff --git a/calendar/gui/e-cal-component-preview.c b/calendar/gui/e-cal-component-preview.c index ffaba3f84b..c96e0641a2 100644 --- a/calendar/gui/e-cal-component-preview.c +++ b/calendar/gui/e-cal-component-preview.c @@ -205,8 +205,6 @@ cal_component_preview_write_html (ECalComponentPreview *preview, icalproperty_status status; const gchar *location; gint *priority_value; - GtkStyle *style; - GtkStateType state; client = preview->priv->client; comp = preview->priv->comp; @@ -216,14 +214,8 @@ cal_component_preview_write_html (ECalComponentPreview *preview, /* write document header */ e_cal_component_get_summary (comp, &text); - style = gtk_widget_get_style (GTK_WIDGET (preview)); - state = gtk_widget_get_state (GTK_WIDGET (preview)); - g_string_append (buffer, HTML_HEADER); - g_string_append_printf ( - buffer, "<body bgcolor=\"#%06x\" text=\"#%06x\">", - e_color_to_value (&style->base[state]), - e_color_to_value (&style->text[state])); + g_string_append (buffer, "<body class=\"-e-web-view-background-color -e-web-view-text-color\">"); if (text.value) g_string_append_printf (buffer, "<h2>%s</h2>", text.value); diff --git a/data/webview.css b/data/webview.css index f28ed3d668..9d381a8a68 100644 --- a/data/webview.css +++ b/data/webview.css @@ -14,7 +14,6 @@ body { th { text-align: left; - font-weight: normal; vertical-align: top; } @@ -50,7 +49,6 @@ img.navigable { .part-container { height: 100%; - background: #FFF; margin-top: 2px; margin-bottom: 3px; border-width: 1px; diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c index 4257152ca8..668b3952de 100644 --- a/e-util/e-web-view.c +++ b/e-util/e-web-view.c @@ -564,6 +564,59 @@ web_view_navigation_policy_decision_requested_cb (EWebView *web_view, } static void +style_updated_cb (EWebView *web_view) +{ + GdkRGBA color; + gchar *color_value; + gchar *style; + GtkStateFlags state_flags; + GtkStyleContext *style_context; + GtkWidgetPath *widget_path; + + state_flags = gtk_widget_get_state_flags (GTK_WIDGET (web_view)); + style_context = gtk_style_context_new (); + widget_path = gtk_widget_path_new (); + gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); + gtk_style_context_set_path (style_context, widget_path); + gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_ENTRY); + + gtk_style_context_get_background_color ( + style_context, + state_flags | GTK_STATE_FLAG_FOCUSED, + &color); + color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color)); + style = g_strconcat ("background-color: ", color_value, ";", NULL); + + e_web_view_add_css_rule_into_style_sheet ( + web_view, + "-e-web-view-css-sheet", + ".-e-web-view-background-color", + style); + + g_free (color_value); + g_free (style); + + gtk_style_context_get_color ( + style_context, + state_flags | GTK_STATE_FLAG_FOCUSED, + &color); + color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color)); + style = g_strconcat ("color: ", color_value, ";", NULL); + + e_web_view_add_css_rule_into_style_sheet ( + web_view, + "-e-web-view-css-sheet", + ".-e-web-view-text-color", + style); + + gtk_widget_path_free (widget_path); + g_object_unref (style_context); + + g_free (color_value); + g_free (style); +} + +static void web_view_load_status_changed_cb (WebKitWebView *webkit_web_view, GParamSpec *pspec, gpointer user_data) @@ -575,14 +628,17 @@ web_view_load_status_changed_cb (WebKitWebView *webkit_web_view, status = webkit_web_view_get_load_status (webkit_web_view); - if (status == WEBKIT_LOAD_FINISHED) { - web_view_update_document_highlights (web_view); + if (status != WEBKIT_LOAD_FINISHED) + return; - /* Workaround webkit bug: - * https://bugs.webkit.org/show_bug.cgi?id=89553 */ - e_web_view_zoom_in (web_view); - e_web_view_zoom_out (web_view); - } + style_updated_cb (web_view); + + web_view_update_document_highlights (web_view); + + /* Workaround webkit bug: + * https://bugs.webkit.org/show_bug.cgi?id=89553 */ + e_web_view_zoom_in (web_view); + e_web_view_zoom_out (web_view); } static void @@ -1579,6 +1635,14 @@ e_web_view_init (EWebView *web_view) web_view, "notify::load-status", G_CALLBACK (web_view_load_status_changed_cb), NULL); + g_signal_connect ( + web_view, "style-updated", + G_CALLBACK (style_updated_cb), NULL); + + g_signal_connect ( + web_view, "state-flags-changed", + G_CALLBACK (style_updated_cb), NULL); + ui_manager = gtk_ui_manager_new (); web_view->priv->ui_manager = ui_manager; @@ -1725,6 +1789,8 @@ e_web_view_init (EWebView *web_view) id = "org.gnome.evolution.webview"; e_plugin_ui_register_manager (ui_manager, id, web_view); e_plugin_ui_enable_manager (ui_manager, id); + + e_web_view_clear (E_WEB_VIEW (web_view)); } GtkWidget * @@ -1736,21 +1802,15 @@ e_web_view_new (void) void e_web_view_clear (EWebView *web_view) { - GtkStyle *style; - gchar *html; - g_return_if_fail (E_IS_WEB_VIEW (web_view)); - style = gtk_widget_get_style (GTK_WIDGET (web_view)); - - html = g_strdup_printf ( - "<html><head></head><body bgcolor=\"#%06x\"></body></html>", - e_color_to_value (&style->base[GTK_STATE_NORMAL])); - webkit_web_view_load_html_string ( - WEBKIT_WEB_VIEW (web_view), html, NULL); - - g_free (html); + WEBKIT_WEB_VIEW (web_view), + "<html> \ + <head></head> \ + <body class=\"-e-web-view-background-color -e-web-view-text-color\"></body> \ + </html>", + NULL); } void @@ -3234,3 +3294,168 @@ e_web_view_install_request_handler (EWebView *web_view, g_object_unref (feature); } +static void +create_and_add_css_style_sheet (WebKitDOMDocument *document, + const gchar *style_sheet_id) +{ + WebKitDOMElement *style_element; + + style_element = webkit_dom_document_get_element_by_id (document, style_sheet_id); + + if (!style_element) { + /* Create new <style> element */ + style_element = webkit_dom_document_create_element (document, "style", NULL); + webkit_dom_html_element_set_id ( + WEBKIT_DOM_HTML_ELEMENT (style_element), + style_sheet_id); + webkit_dom_html_style_element_set_media ( + WEBKIT_DOM_HTML_STYLE_ELEMENT (style_element), + "screen"); + webkit_dom_node_append_child ( + WEBKIT_DOM_NODE (style_element), + /* WebKit hack - we have to insert empty TextNode into style element */ + WEBKIT_DOM_NODE (webkit_dom_document_create_text_node (document, "")), + NULL); + + webkit_dom_node_append_child ( + WEBKIT_DOM_NODE (webkit_dom_document_get_head (document)), + WEBKIT_DOM_NODE (style_element), + NULL); + } +} + +static void +add_css_rule_into_style_sheet (WebKitDOMDocument *document, + const gchar *style_sheet_id, + const gchar *selector, + const gchar *style) +{ + WebKitDOMElement *style_element; + WebKitDOMStyleSheet *sheet; + WebKitDOMCSSRuleList *rules_list; + gint length, ii; + + style_element = webkit_dom_document_get_element_by_id (document, style_sheet_id); + + if (!style_element) { + create_and_add_css_style_sheet (document, style_sheet_id); + style_element = webkit_dom_document_get_element_by_id (document, style_sheet_id); + } + + /* Get sheet that is associated with style element */ + sheet = webkit_dom_html_style_element_get_sheet (WEBKIT_DOM_HTML_STYLE_ELEMENT (style_element)); + + rules_list = webkit_dom_css_style_sheet_get_css_rules (WEBKIT_DOM_CSS_STYLE_SHEET (sheet)); + length = webkit_dom_css_rule_list_get_length (rules_list); + + /* Check if rule exists */ + for (ii = 0; ii < length; ii++) { + WebKitDOMCSSRule *rule; + const gchar *rule_text; + gchar *rule_selector, *selector_end; + + rule = webkit_dom_css_rule_list_item (rules_list, ii); + + if (!WEBKIT_DOM_IS_CSS_RULE (rule)) + continue; + + rule_text = webkit_dom_css_rule_get_css_text (rule); + + /* Find the start of the style => end of the selector */ + selector_end = g_strstr_len (rule_text, -1, " {"); + if (!selector_end) + continue; + + rule_selector = + g_utf8_substring ( + rule_text, + 0, + g_utf8_pointer_to_offset (rule_text, selector_end)); + + if (g_strcmp0 (rule_selector, selector) == 0) { + /* If exists remove it */ + webkit_dom_css_style_sheet_remove_rule ( + WEBKIT_DOM_CSS_STYLE_SHEET (sheet), + ii, NULL); + } + + g_free (rule_selector); + } + + /* Insert the rule at the end, so it will override previously inserted */ + webkit_dom_css_style_sheet_add_rule ( + WEBKIT_DOM_CSS_STYLE_SHEET (sheet), + selector, + style, + webkit_dom_css_rule_list_get_length ( + webkit_dom_css_style_sheet_get_css_rules ( + WEBKIT_DOM_CSS_STYLE_SHEET (sheet))), /* Index */ + NULL); +} + +static void +add_css_rule_into_style_sheet_recursive (WebKitDOMDocument *document, + const gchar *style_sheet_id, + const gchar *selector, + const gchar *style) +{ + WebKitDOMNodeList *frames; + gint ii, length; + + /* Add rule to document */ + add_css_rule_into_style_sheet ( + document, + style_sheet_id, + selector, + style); + + frames = webkit_dom_document_query_selector_all (document, "iframe", NULL); + length = webkit_dom_node_list_get_length (frames); + + /* Add rules to every sub document */ + for (ii = 0; ii < length; ii++) { + WebKitDOMDocument *iframe_document; + WebKitDOMNode *node; + + node = webkit_dom_node_list_item (frames, ii); + iframe_document = webkit_dom_html_iframe_element_get_content_document ( + WEBKIT_DOM_HTML_IFRAME_ELEMENT (node)); + + add_css_rule_into_style_sheet_recursive ( + iframe_document, + style_sheet_id, + selector, + style); + } +} + +/** + * e_web_view_add_css_rule_into_style_sheet: + * @web_view: an #EWebView + * @style_sheet_id: CSS style sheet's id + * @selector: CSS selector + * @style: style for given selector + * + * Insert new CSS rule (defined with @selector and @style) into CSS style sheet + * with given @style_sheet_id. If style sheet doesn't exist, it's created. + * + * The rule is inserted to every DOM document that is in page. That means also into + * DOM documents inside iframe elements. + **/ +void +e_web_view_add_css_rule_into_style_sheet (EWebView *view, + const gchar *style_sheet_id, + const gchar *selector, + const gchar *style) +{ + g_return_if_fail (E_IS_WEB_VIEW (view)); + g_return_if_fail (style_sheet_id && *style_sheet_id); + g_return_if_fail (selector && *selector); + g_return_if_fail (style && *style); + + add_css_rule_into_style_sheet_recursive ( + webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view)), + style_sheet_id, + selector, + style); +} diff --git a/e-util/e-web-view.h b/e-util/e-web-view.h index 2f99b7a248..51826a7326 100644 --- a/e-util/e-web-view.h +++ b/e-util/e-web-view.h @@ -195,11 +195,14 @@ void e_web_view_request (EWebView *web_view, GInputStream * e_web_view_request_finish (EWebView *web_view, GAsyncResult *result, GError **error); - void e_web_view_install_request_handler (EWebView *web_view, GType handler_type); - +void e_web_view_add_css_rule_into_style_sheet + (EWebView *view, + const gchar *style_sheet_id, + const gchar *selector, + const gchar *style); G_END_DECLS #endif /* E_WEB_VIEW_H */ diff --git a/em-format/e-mail-formatter-error.c b/em-format/e-mail-formatter-error.c index 8669c11ced..f349283021 100644 --- a/em-format/e-mail-formatter-error.c +++ b/em-format/e-mail-formatter-error.c @@ -59,24 +59,14 @@ emfe_error_format (EMailFormatterExtension *extension, dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part)); html = g_strdup_printf ( - "<div class=\"part-container\" style=\"" - "border-color: #%06x;" - "background-color: #%06x; color: #%06x;\">" + "<div class=\"part-container -e-mail-formatter-frame-color " + "-e-mail-formatter-body-color -e-web-view-text-color\">" "<div class=\"part-container-inner-margin pre\">\n" "<table border=\"0\" cellspacing=\"10\" " "cellpadding=\"0\" width=\"100%%\">\n" "<tr valign=\"top\"><td width=50>" "<img src=\"gtk-stock://%s/?size=%d\" /></td>\n" "<td style=\"color: red;\">", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_TEXT)), GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG); camel_stream_write_string (stream, html, cancellable, NULL); diff --git a/em-format/e-mail-formatter-headers.c b/em-format/e-mail-formatter-headers.c index e9f88704c8..3117bec265 100644 --- a/em-format/e-mail-formatter-headers.c +++ b/em-format/e-mail-formatter-headers.c @@ -490,9 +490,6 @@ emfe_headers_format (EMailFormatterExtension *extension, { CamelMimePart *mime_part; GString *buffer; - const GdkRGBA white = { 1.0, 1.0, 1.0, 1.0 }; - const GdkRGBA *body_rgba = &white; - const GdkRGBA *header_rgba; const gchar *direction; gboolean is_collapsable; gboolean is_collapsed; @@ -524,22 +521,15 @@ emfe_headers_format (EMailFormatterExtension *extension, buffer = g_string_new (""); - if (context->mode != E_MAIL_FORMATTER_MODE_PRINTING) - body_rgba = e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY); - - header_rgba = e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_HEADER); - g_string_append_printf ( buffer, - "<div class=\"headers\" style=\"background: #%06x;\" id=\"%s\">" - "<table border=\"0\" width=\"100%%\" " - "style=\"color: #%06x; direction: %s\">" + "%s id=\"%s\"><table class=\"-e-mail-formatter-header-color\" border=\"0\" width=\"100%%\" " + "style=\"direction: %s\">" "<tr>", - e_rgba_to_value (body_rgba), + (context->mode != E_MAIL_FORMATTER_MODE_PRINTING) ? + "<div class=\"headers -e-mail-formatter-body-color\"" : + "<div class=\"headers\" style=\"background-color: #ffffff;\"", e_mail_part_get_id (part), - e_rgba_to_value (header_rgba), direction); if (is_collapsable) diff --git a/em-format/e-mail-formatter-message-rfc822.c b/em-format/e-mail-formatter-message-rfc822.c index 0477e61517..6b9f4eebb8 100644 --- a/em-format/e-mail-formatter-message-rfc822.c +++ b/em-format/e-mail-formatter-message-rfc822.c @@ -221,18 +221,12 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension, NULL); str = g_strdup_printf ( - "<div class=\"part-container\" style=\"border-color: #%06x; " - "background-color: #%06x;\">\n" + "<div class=\"part-container -e-mail-formatter-frame-color " + "-e-mail-formatter-body-color\">\n" "<iframe width=\"100%%\" height=\"10\"" " id=\"%s.iframe\" " " frameborder=\"0\" src=\"%s\" name=\"%s\"></iframe>" "</div>", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY)), part_id, uri, part_id); camel_stream_write_string (stream, str, cancellable, NULL); diff --git a/em-format/e-mail-formatter-source.c b/em-format/e-mail-formatter-source.c index 944f9a4c14..12eaa4ab7c 100644 --- a/em-format/e-mail-formatter-source.c +++ b/em-format/e-mail-formatter-source.c @@ -70,31 +70,16 @@ emfe_source_format (EMailFormatterExtension *extension, buffer = g_string_new (""); if (CAMEL_IS_MIME_MESSAGE (mime_part)) { - g_string_append_printf ( + g_string_append ( buffer, - "<div class=\"part-container\" " - "style=\"border: 0; background: #%06x; color: #%06x;\" >", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_TEXT))); + "<div class=\"part-container -e-mail-formatter-body-color " + "-e-web-view-text-color\" style=\"border: 0;\" >"); } else { - g_string_append_printf ( + g_string_append ( buffer, - "<div class=\"part-container\" " - "style=\"border-color: #%06x; background: #%06x; color: #%06x;\">" - "<div class=\"part-container-inner-margin pre\">\n", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_TEXT))); + "<div class=\"part-container -e-mail-formatter-body-color " + " -e-web-view-text-color -e-mail-formatter-frame-color\">" + "<div class=\"part-container-inner-margin pre\">\n"); } camel_stream_write_string ( diff --git a/em-format/e-mail-formatter-text-enriched.c b/em-format/e-mail-formatter-text-enriched.c index 6c3b033171..168522e6b6 100644 --- a/em-format/e-mail-formatter-text-enriched.c +++ b/em-format/e-mail-formatter-text-enriched.c @@ -73,17 +73,11 @@ emfe_text_enriched_format (EMailFormatterExtension *extension, buffer = g_string_new (""); - g_string_append_printf ( + g_string_append ( buffer, - "<div class=\"part-container\" style=\"border-color: #%06x; " - "background-color: #%06x; color: #%06x;\">" - "<div class=\"part-container-inner-margin\">\n", - e_rgba_to_value ( - e_mail_formatter_get_color (formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color (formatter, E_MAIL_FORMATTER_COLOR_CONTENT)), - e_rgba_to_value ( - e_mail_formatter_get_color (formatter, E_MAIL_FORMATTER_COLOR_TEXT))); + "<div class=\"part-container -e-mail-formatter-frame-color " + "-e-web-view-background-color -e-web-view-text-color\">" + "<div class=\"part-container-inner-margin\">\n"); camel_stream_write_string (stream, buffer->str, cancellable, NULL); g_string_free (buffer, TRUE); diff --git a/em-format/e-mail-formatter-text-html.c b/em-format/e-mail-formatter-text-html.c index 0a581117a6..17632fa03f 100644 --- a/em-format/e-mail-formatter-text-html.c +++ b/em-format/e-mail-formatter-text-html.c @@ -328,15 +328,13 @@ emfe_text_html_format (EMailFormatterExtension *extension, "<iframe width=\"100%%\" height=\"10\" " " frameborder=\"0\" src=\"%s\" " " id=\"%s.iframe\" name=\"%s\" " - " style=\"border: 1px solid #%06x; background-color: #ffffff;\">" + " class=\"-e-mail-formatter-frame-color\" " + " style=\"background-color: #ffffff; border: 1px solid;\">" "</iframe>" "</div>", uri, e_mail_part_get_id (part), - e_mail_part_get_id (part), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME))); + e_mail_part_get_id (part)); camel_stream_write_string (stream, str, cancellable, NULL); diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c index 638f0119a1..487dd34db0 100644 --- a/em-format/e-mail-formatter-text-plain.c +++ b/em-format/e-mail-formatter-text-plain.c @@ -70,10 +70,11 @@ emfe_text_plain_format (EMailFormatterExtension *extension, CamelDataWrapper *dw; if (context->mode == E_MAIL_FORMATTER_MODE_RAW) { - gchar *header; - header = e_mail_formatter_get_html_header (formatter); - camel_stream_write_string (stream, header, cancellable, NULL); - g_free (header); + camel_stream_write_string ( + stream, + e_mail_formatter_get_sub_html_header (formatter), + cancellable, + NULL); /* No need for body margins within <iframe> */ camel_stream_write_string ( @@ -107,16 +108,10 @@ emfe_text_plain_format (EMailFormatterExtension *extension, CAMEL_STREAM_FILTER (filtered_stream), html_filter); g_object_unref (html_filter); - content = g_strdup_printf ( - "<div class=\"part-container pre\" style=\"" - "border: none; padding: 8px; margin: 0; " - "background-color: #%06x; color: #%06x;\">\n", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_CONTENT)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_TEXT))); + content = g_strdup ( + "<div class=\"part-container pre " + "-e-web-view-background-color -e-web-view-text-color\" " + "style=\"border: none; padding: 8px; margin: 0;\">"); camel_stream_write_string (stream, content, cancellable, NULL); e_mail_formatter_format_text (formatter, part, filtered_stream, cancellable); @@ -166,18 +161,14 @@ emfe_text_plain_format (EMailFormatterExtension *extension, "<iframe width=\"100%%\" height=\"10\"" " id=\"%s.iframe\" name=\"%s\" " " frameborder=\"0\" src=\"%s\" " - " style=\"border: 1px solid #%06x; background-color: #%06x;\">" + " class=\"-e-mail-formatter-frame-color" + " -e-web-view-text-color\" " + " style=\"border: 1px solid;\">" "</iframe>" "</div>", e_mail_part_get_id (part), e_mail_part_get_id (part), - uri, - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_CONTENT))); + uri); camel_stream_write_string (stream, str, cancellable, NULL); diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c index f3f09670d4..0cbfaf2e52 100644 --- a/em-format/e-mail-formatter.c +++ b/em-format/e-mail-formatter.c @@ -1105,10 +1105,27 @@ e_mail_formatter_format_text (EMailFormatter *formatter, g_object_unref (mime_part); } +const gchar * +e_mail_formatter_get_sub_html_header (EMailFormatter *formatter) +{ + return "<!DOCTYPE HTML>\n" + "<html>\n" + "<head>\n" + "<meta name=\"generator\" content=\"Evolution Mail\"/>\n" + "<title>Evolution Mail Display</title>\n" + "<link type=\"text/css\" rel=\"stylesheet\" " + " href=\"" STYLESHEET_URI "\"/>\n" + "<style type=\"text/css\">\n" + " table th { font-weight: bold; }\n" + "</style>\n" + "</head>" + "<body class=\"-e-web-view-background-color -e-web-view-text-color\">"; +} + gchar * e_mail_formatter_get_html_header (EMailFormatter *formatter) { - return g_strdup_printf ( + return g_strdup ( "<!DOCTYPE HTML>\n" "<html>\n" "<head>\n" @@ -1117,19 +1134,11 @@ e_mail_formatter_get_html_header (EMailFormatter *formatter) "<link type=\"text/css\" rel=\"stylesheet\" " " href=\"" STYLESHEET_URI "\"/>\n" "<style type=\"text/css\">\n" - " table th { color: #%06x; font-weight: bold; }\n" + " table th { font-weight: bold; }\n" "</style>\n" "</head>" - "<body bgcolor=\"#%06x\" text=\"#%06x\">", - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_HEADER)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_BODY)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_TEXT))); + "<body class=\"-e-mail-formatter-body-color " + "-e-web-view-background-color -e-web-view-text-color\">"); } EMailExtensionRegistry * diff --git a/em-format/e-mail-formatter.h b/em-format/e-mail-formatter.h index 9405789b72..5c9d6ff958 100644 --- a/em-format/e-mail-formatter.h +++ b/em-format/e-mail-formatter.h @@ -125,6 +125,8 @@ void e_mail_formatter_format_text (EMailFormatter *formatter, EMailPart *part, CamelStream *stream, GCancellable *cancellable); +const gchar * e_mail_formatter_get_sub_html_header + (EMailFormatter *formatter); gchar * e_mail_formatter_get_html_header (EMailFormatter *formatter); EMailExtensionRegistry * diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c index 9343ac01ba..919ba681a6 100644 --- a/mail/e-mail-display.c +++ b/mail/e-mail-display.c @@ -832,6 +832,60 @@ toggle_address_visibility (WebKitDOMElement *button, } static void +add_color_css_rule_for_web_view (EWebView *view, + const char *color_name, + const char *color_value) +{ + gchar *selector; + gchar *style; + + selector = g_strconcat (".-e-mail-formatter-", color_name, NULL); + + if (g_strstr_len (color_name, -1, "header")) + style = g_strconcat ("color: ", color_value, " !important;", NULL); + else if (g_strstr_len (color_name, -1, "frame")) + style = g_strconcat ("border-color: ", color_value, " !important;", NULL); + else + style = g_strconcat ("background-color: ", color_value, " !important;", NULL); + + e_web_view_add_css_rule_into_style_sheet ( + view, + "-e-mail-formatter-style-sheet", + selector, + style); + + g_free (style); + g_free (selector); +} + +static void +initialize_web_view_colors (EMailDisplay *display) +{ + EMailFormatter *formatter; + const gchar *color_names [] = { "body-color", "citation-color", + "frame-color", "header-color", NULL }; + gint ii; + + formatter = e_mail_display_get_formatter (display); + + for (ii = 0; color_names[ii]; ii++) { + GdkRGBA *color = NULL; + gchar *color_value; + + g_object_get (formatter, color_names[ii], &color, NULL); + color_value = g_strdup_printf ("#%06x", e_rgba_to_value (color)); + + add_color_css_rule_for_web_view ( + E_WEB_VIEW (display), + color_names[ii], + color_value); + + gdk_rgba_free (color); + g_free (color_value); + } +} + +static void setup_dom_bindings (GObject *object, GParamSpec *pspec, gpointer user_data) @@ -914,6 +968,7 @@ mail_parts_bind_dom (GObject *object, if (display->priv->part_list == NULL) return; + initialize_web_view_colors (display); frame_name = webkit_web_frame_get_name (frame); if (frame_name == NULL || *frame_name == '\0') frame_name = ".message.headers"; @@ -1535,6 +1590,30 @@ e_mail_display_init (EMailDisplay *display) } } +static void +e_mail_display_update_colors (EMailDisplay *display, + GParamSpec *param_spec, + EMailFormatter *formatter) +{ + GdkRGBA *color = NULL; + gchar *color_value; + + g_return_if_fail (E_IS_MAIL_DISPLAY (display)); + g_return_if_fail (E_IS_MAIL_FORMATTER (formatter)); + + g_object_get (formatter, param_spec->name, &color, NULL); + + color_value = g_strdup_printf ("#%06x", e_rgba_to_value (color)); + + add_color_css_rule_for_web_view ( + E_WEB_VIEW (display), + param_spec->name, + color_value); + + gdk_rgba_free (color); + g_free (color_value); +} + GtkWidget * e_mail_display_new (void) { @@ -1592,18 +1671,14 @@ e_mail_display_set_mode (EMailDisplay *display, G_CALLBACK (e_mail_display_reload), display, "swapped-object-signal::notify::animate-images", G_CALLBACK (e_mail_display_reload), display, - "swapped-object-signal::notify::text-color", - G_CALLBACK (e_mail_display_reload), display, "swapped-object-signal::notify::body-color", - G_CALLBACK (e_mail_display_reload), display, + G_CALLBACK (e_mail_display_update_colors), display, "swapped-object-signal::notify::citation-color", - G_CALLBACK (e_mail_display_reload), display, - "swapped-object-signal::notify::content-color", - G_CALLBACK (e_mail_display_reload), display, + G_CALLBACK (e_mail_display_update_colors), display, "swapped-object-signal::notify::frame-color", - G_CALLBACK (e_mail_display_reload), display, + G_CALLBACK (e_mail_display_update_colors), display, "swapped-object-signal::notify::header-color", - G_CALLBACK (e_mail_display_reload), display, + G_CALLBACK (e_mail_display_update_colors), display, "swapped-object-signal::need-redraw", G_CALLBACK (e_mail_display_reload), display, NULL); @@ -1854,7 +1929,7 @@ e_mail_display_set_status (EMailDisplay *display, "<meta name=\"generator\" content=\"Evolution Mail\"/>\n" "<title>Evolution Mail Display</title>\n" "</head>\n" - "<body bgcolor=\"#%06x\" text=\"#%06x\">" + "<body class=\"-e-web-view-background-color e-web-view-text-color\">" " <style>html, body { height: 100%%; }</style>\n" " <table border=\"0\" width=\"100%%\" height=\"100%%\">\n" " <tr height=\"100%%\" valign=\"middle\">\n" @@ -1865,14 +1940,6 @@ e_mail_display_set_status (EMailDisplay *display, " </table>\n" "</body>\n" "</html>\n", - e_rgba_to_value ( - e_mail_formatter_get_color ( - display->priv->formatter, - E_MAIL_FORMATTER_COLOR_CONTENT)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - display->priv->formatter, - E_MAIL_FORMATTER_COLOR_TEXT)), status); e_web_view_load_string (E_WEB_VIEW (display), str); diff --git a/modules/text-highlight/e-mail-formatter-text-highlight.c b/modules/text-highlight/e-mail-formatter-text-highlight.c index de1d89b8e2..b387408573 100644 --- a/modules/text-highlight/e-mail-formatter-text-highlight.c +++ b/modules/text-highlight/e-mail-formatter-text-highlight.c @@ -333,19 +333,14 @@ emfe_text_highlight_format (EMailFormatterExtension *extension, "<div class=\"part-container-nostyle\" >" "<iframe width=\"100%%\" height=\"10\"" " id=\"%s\" name=\"%s\" " + " class=\"-e-mail-formatter-frame-color -e-web-view-background-color\" " " frameborder=\"0\" src=\"%s\" " - " style=\"border: 1px solid #%06x; background-color: #%06x;\">" + " style=\"border: 1px solid;\">" "</iframe>" "</div>", e_mail_part_get_id (part), e_mail_part_get_id (part), - uri, - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_FRAME)), - e_rgba_to_value ( - e_mail_formatter_get_color ( - formatter, E_MAIL_FORMATTER_COLOR_CONTENT))); + uri); camel_stream_write_string (stream, str, cancellable, NULL); |