Hi,

When displaying HTML message content, colors that are not explicitly
defined in the message HTML code itself are taken from the GTK theme,
the rest are taken from the message. The combination may be unreadable,
e.g. white-on-white text. I've looked at libgtkhtml 4.4.4 and Evolution
3.4.4. If new versions already deal with this, please ignore the rest.

One way to deal with it might be to give the consumer of GtkHTML widget
the option to ignore any colors defined in the HTML code. This seems to
be what Firefox is doing (judging from experience and the checkbox:
'Allow pages to choose their own colors'). The
HTMLSettings.forceDefaults in libgtkhtml appears to be exactly this.
However, it ignores the colors in attributes but not in styles. I've
patched it to ignore both (attached) and am now happy with Xfce-darkness
theme*.

For a complete patch, I guess, the forceDefaults flag would need to be
exposed as a widget property, and then as a gconf setting in Evolution.
But, before sinking any more time into this, is this of any interest
(esp. given the move to WebKit)?

[*] https://github.com/vkuzel/Xfce-darkness
The theme had to be patched with:
GtkHTML {
    color: @fg_normal;
    background-color: @bg_normal;
}

-alexei
Index: gtkhtml4.0-4.4.4/gtkhtml/htmlsettings.c
===================================================================
--- gtkhtml4.0-4.4.4.orig/gtkhtml/htmlsettings.c	2014-06-21 23:28:01.485347916 -0700
+++ gtkhtml4.0-4.4.4/gtkhtml/htmlsettings.c	2014-06-21 23:47:06.256801677 -0700
@@ -39,7 +39,7 @@
 	s->fontBaseFace = g_strdup ("times");
 	s->fixedFontFace = g_strdup ("courier");
 	s->underlineLinks = TRUE;
-	s->forceDefault = FALSE;
+	s->forceDefault = TRUE;
 
 	html_settings_reset_font_sizes (s);
 
Index: gtkhtml4.0-4.4.4/gtkhtml/htmlengine.c
===================================================================
--- gtkhtml4.0-4.4.4.orig/gtkhtml/htmlengine.c	2014-06-21 23:57:11.593191568 -0700
+++ gtkhtml4.0-4.4.4/gtkhtml/htmlengine.c	2014-06-22 00:32:14.934748983 -0700
@@ -436,14 +436,16 @@
 
 	g_return_val_if_fail ( HTML_IS_ENGINE (e), NULL );
 
-	for (item = e->span_stack->list; item; item = item->next) {
-		span = item->data;
+	if (!e->defaultSettings->forceDefault) {
+		for (item = e->span_stack->list; item; item = item->next) {
+			span = item->data;
 
-		if (span->style->display >= DISPLAY_TABLE_CELL)
-			break;
+			if (span->style->display >= DISPLAY_TABLE_CELL)
+				break;
 
-		if (span->style && span->style->color)
-			return span->style->color;
+			if (span->style && span->style->color)
+				return span->style->color;
+		}
 	}
 
 	return html_colorset_get_color (e->settings->color_set, HTMLTextColor);
@@ -457,6 +459,9 @@
 
 	g_return_val_if_fail (HTML_IS_ENGINE (e), NULL);
 
+	if (e->defaultSettings->forceDefault)
+		return NULL;
+
 	for (item = e->span_stack->list; item; item = item->next) {
 		span = item->data;
 
@@ -482,6 +487,9 @@
 
 	g_return_val_if_fail (HTML_IS_ENGINE (e), NULL);
 
+	if (e->defaultSettings->forceDefault)
+		return NULL;
+
 	for (item = e->span_stack->list; item; item = item->next) {
 		span = item->data;
 		if (span->style->display == DISPLAY_TABLE_ROW)
@@ -999,6 +1007,28 @@
 static void block_end_cell (HTMLEngine *e, HTMLObject *clue, HTMLElement *elem);
 static void pop_element_by_type (HTMLEngine *e, HTMLDisplayType display);
 
+static void
+hide_colors_from_style (HTMLStyle *style,
+						HTMLColor **color, HTMLColor **bg_color)
+{
+	g_assert (color);
+	g_assert (bg_color);
+
+	*color = style->color;
+	*bg_color = style->bg_color;
+
+	style->color = NULL;
+	style->bg_color = NULL;
+}
+
+static void
+unhide_colors_from_style (HTMLStyle *style,
+					      HTMLColor *color, HTMLColor *bg_color)
+{
+	style->color = color;
+	style->bg_color = bg_color;
+}
+
 /* Block stack.  */
 static void
 html_element_push (HTMLElement *node,
@@ -1006,6 +1036,7 @@
                    HTMLObject *clue)
 {
 	HTMLObject *block_clue;
+	HTMLColor *st_color = NULL, *st_bg_color = NULL;
 
 	g_return_if_fail (HTML_IS_ENGINE (e));
 
@@ -1016,7 +1047,11 @@
 		update_flow_align (e, clue);
 		node->exitFunc = block_end_display_block;
 		block_clue = html_cluev_new (0, 0, 100);
+		if (e->defaultSettings->forceDefault)
+			hide_colors_from_style (node->style, &st_color, &st_bg_color);
 		html_cluev_set_style (HTML_CLUEV (block_clue), node->style);
+		if (e->defaultSettings->forceDefault)
+			unhide_colors_from_style (node->style, st_color, st_bg_color);
 		html_clue_append (HTML_CLUE (e->parser_clue), block_clue);
 		push_clue (e, block_clue);
 		html_stack_push (e->span_stack, node);
@@ -3492,7 +3527,7 @@
 		html_element_set_coreattr_to_object (element, HTML_OBJECT (table), e);
 		html_element_set_coreattr_to_object (element, HTML_OBJECT (table), e);
 
-		if (element->style->bg_color)
+		if (!e->defaultSettings->forceDefault && element->style->bg_color)
 			table->bgColor = gdk_color_copy ((GdkColor *) element->style->bg_color);
 
 		if (element->style->bg_image)
@@ -3516,7 +3551,7 @@
 						    len && len->type == HTML_LENGTH_TYPE_PERCENT ? len->val : 0,
 						    padding, spacing, border));
 
-		if (element->style->bg_color)
+		if (!e->defaultSettings->forceDefault && element->style->bg_color)
 			table->bgColor = gdk_color_copy ((GdkColor *) element->style->bg_color);
 
 		if (element->style->bg_image)
@@ -3691,6 +3726,7 @@
 	gchar *value;
 	HTMLLength *len;
 	HTMLDirection dir = HTML_DIRECTION_DERIVED;
+	HTMLColor *st_color = NULL, *st_bg_color = NULL;
 
 	element = html_element_new_parse (e, str);
 
@@ -3771,7 +3807,11 @@
 
 	html_element_set_coreattr_to_object (element, HTML_OBJECT (cell), e);
 	html_style_set_padding (element->style, table->padding);
+	if (e->defaultSettings->forceDefault)
+		hide_colors_from_style (element->style, &st_color, &st_bg_color);
 	html_cluev_set_style (HTML_CLUEV (cell), element->style);
+	if (e->defaultSettings->forceDefault)
+		unhide_colors_from_style (element->style, st_color, st_bg_color);
 
 	cell->no_wrap = no_wrap;
 	cell->heading = heading;
@@ -3780,7 +3820,10 @@
 	pop_element_by_type (e, DISPLAY_TABLE_CELL);
 	pop_element_by_type (e, DISPLAY_TABLE_CAPTION);
 
-	html_object_set_bg_color (HTML_OBJECT (cell), element->style->bg_color ? &element->style->bg_color->color : &current_row_bg_color (e)->color);
+	html_object_set_bg_color (HTML_OBJECT (cell),
+			!e->defaultSettings->forceDefault && element->style->bg_color ?
+				&element->style->bg_color->color :
+				&current_row_bg_color (e)->color);
 
 	image_url = element->style->bg_image ? element->style->bg_image : current_row_bg_image (e);
 	if (image_url) {
_______________________________________________
evolution-hackers mailing list
evolution-hackers@gnome.org
To change your list options or unsubscribe, visit ...
https://mail.gnome.org/mailman/listinfo/evolution-hackers

Reply via email to