Milan Crha c605da
From 5f197603700d0e0cbfc2dab7c4750fd04c41de25 Mon Sep 17 00:00:00 2001
Milan Crha c605da
From: Sebastian Keller <sebastian-keller@gmx.de>
Milan Crha c605da
Date: Mon, 23 Jun 2014 11:39:46 +0200
Milan Crha c605da
Subject: Bug 731872 - EWebView: Use named colors from themes
Milan Crha c605da
Milan Crha c605da
Milan Crha c605da
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
Milan Crha c605da
index 8703ee1..7615db4 100644
Milan Crha c605da
--- a/e-util/e-web-view.c
Milan Crha c605da
+++ b/e-util/e-web-view.c
Milan Crha c605da
@@ -574,20 +574,20 @@ style_updated_cb (EWebView *web_view)
Milan Crha c605da
 	gchar *style;
Milan Crha c605da
 	GtkStateFlags state_flags;
Milan Crha c605da
 	GtkStyleContext *style_context;
Milan Crha c605da
-	GtkWidgetPath *widget_path;
Milan Crha c605da
+	gboolean backdrop;
Milan Crha c605da
 
Milan Crha c605da
 	state_flags = gtk_widget_get_state_flags (GTK_WIDGET (web_view));
Milan Crha c605da
-	style_context = gtk_style_context_new ();
Milan Crha c605da
-	widget_path = gtk_widget_path_new ();
Milan Crha c605da
-	gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
Milan Crha c605da
-	gtk_style_context_set_path (style_context, widget_path);
Milan Crha c605da
-	gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_ENTRY);
Milan Crha c605da
-
Milan Crha c605da
-	gtk_style_context_get_background_color (
Milan Crha c605da
-		style_context,
Milan Crha c605da
-		state_flags | GTK_STATE_FLAG_FOCUSED,
Milan Crha c605da
-		&color;;
Milan Crha c605da
-	color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color));
Milan Crha c605da
+	style_context = gtk_widget_get_style_context (GTK_WIDGET (web_view));
Milan Crha c605da
+	backdrop = (state_flags & GTK_STATE_FLAG_BACKDROP) != 0;
Milan Crha c605da
+
Milan Crha c605da
+	if (gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_base_color" : "theme_base_color",
Milan Crha c605da
+			&color))
Milan Crha c605da
+		color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color));
Milan Crha c605da
+	else
Milan Crha c605da
+		color_value = g_strdup("#ffffff");
Milan Crha c605da
+
Milan Crha c605da
 	style = g_strconcat ("background-color: ", color_value, ";", NULL);
Milan Crha c605da
 
Milan Crha c605da
 	e_web_view_add_css_rule_into_style_sheet (
Milan Crha c605da
@@ -599,11 +599,14 @@ style_updated_cb (EWebView *web_view)
Milan Crha c605da
 	g_free (color_value);
Milan Crha c605da
 	g_free (style);
Milan Crha c605da
 
Milan Crha c605da
-	gtk_style_context_get_color (
Milan Crha c605da
-		style_context,
Milan Crha c605da
-		state_flags | GTK_STATE_FLAG_FOCUSED,
Milan Crha c605da
-		&color;;
Milan Crha c605da
-	color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color));
Milan Crha c605da
+	if (gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_fg_color" : "theme_fg_color",
Milan Crha c605da
+			&color))
Milan Crha c605da
+		color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color));
Milan Crha c605da
+	else
Milan Crha c605da
+		color_value = g_strdup("#000000");
Milan Crha c605da
+
Milan Crha c605da
 	style = g_strconcat ("color: ", color_value, ";", NULL);
Milan Crha c605da
 
Milan Crha c605da
 	e_web_view_add_css_rule_into_style_sheet (
Milan Crha c605da
@@ -612,9 +615,6 @@ style_updated_cb (EWebView *web_view)
Milan Crha c605da
 		".-e-web-view-text-color",
Milan Crha c605da
 		style);
Milan Crha c605da
 
Milan Crha c605da
-	gtk_widget_path_free (widget_path);
Milan Crha c605da
-	g_object_unref (style_context);
Milan Crha c605da
-
Milan Crha c605da
 	g_free (color_value);
Milan Crha c605da
 	g_free (style);
Milan Crha c605da
 }
Milan Crha c605da
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
Milan Crha c605da
index 2efe8eb..a81802b 100644
Milan Crha c605da
--- a/em-format/e-mail-formatter.c
Milan Crha c605da
+++ b/em-format/e-mail-formatter.c
Milan Crha c605da
@@ -489,20 +489,21 @@ mail_formatter_update_style (EMailFormatter *formatter,
Milan Crha c605da
 	GtkStyleContext *style_context;
Milan Crha c605da
 	GtkWidgetPath *widget_path;
Milan Crha c605da
 	GdkRGBA rgba;
Milan Crha c605da
+	gboolean backdrop;
Milan Crha c605da
 
Milan Crha c605da
 	g_object_freeze_notify (G_OBJECT (formatter));
Milan Crha c605da
 
Milan Crha c605da
-	/* derive colors from top-level window */
Milan Crha c605da
 	style_context = gtk_style_context_new ();
Milan Crha c605da
 	widget_path = gtk_widget_path_new ();
Milan Crha c605da
 	gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
Milan Crha c605da
 	gtk_style_context_set_path (style_context, widget_path);
Milan Crha c605da
-	gtk_style_context_invalidate (style_context);
Milan Crha c605da
+	backdrop = (state & GTK_STATE_FLAG_BACKDROP) != 0;
Milan Crha c605da
 
Milan Crha c605da
-	gtk_style_context_save (style_context);
Milan Crha c605da
-	gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_TOOLBAR);
Milan Crha c605da
-
Milan Crha c605da
-	gtk_style_context_get_background_color (style_context, state, &rgba);
Milan Crha c605da
+	if (!gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_bg_color" : "theme_bg_color",
Milan Crha c605da
+			&rgba))
Milan Crha c605da
+		gdk_rgba_parse (&rgba, "#eeeeee");
Milan Crha c605da
 	e_mail_formatter_set_color (
Milan Crha c605da
 		formatter, E_MAIL_FORMATTER_COLOR_BODY, &rgba);
Milan Crha c605da
 
Milan Crha c605da
@@ -512,20 +513,27 @@ mail_formatter_update_style (EMailFormatter *formatter,
Milan Crha c605da
 	e_mail_formatter_set_color (
Milan Crha c605da
 		formatter, E_MAIL_FORMATTER_COLOR_FRAME, &rgba);
Milan Crha c605da
 
Milan Crha c605da
-	gtk_style_context_restore (style_context);
Milan Crha c605da
-	gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_ENTRY);
Milan Crha c605da
-
Milan Crha c605da
-	gtk_style_context_get_color (style_context, state, &rgba);
Milan Crha c605da
+	if (!gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_fg_color" : "theme_fg_color",
Milan Crha c605da
+			&rgba))
Milan Crha c605da
+		gdk_rgba_parse (&rgba, "#000000");
Milan Crha c605da
 	e_mail_formatter_set_color (
Milan Crha c605da
 		formatter, E_MAIL_FORMATTER_COLOR_HEADER, &rgba);
Milan Crha c605da
 
Milan Crha c605da
-	gtk_style_context_get_background_color (
Milan Crha c605da
-		style_context, state | GTK_STATE_FLAG_FOCUSED, &rgba);
Milan Crha c605da
+	if (!gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_base_color" : "theme_base_color",
Milan Crha c605da
+			&rgba))
Milan Crha c605da
+		gdk_rgba_parse (&rgba, "#ffffff");
Milan Crha c605da
 	e_mail_formatter_set_color  (
Milan Crha c605da
 		formatter, E_MAIL_FORMATTER_COLOR_CONTENT, &rgba);
Milan Crha c605da
 
Milan Crha c605da
-	gtk_style_context_get_color (
Milan Crha c605da
-		style_context, state | GTK_STATE_FLAG_FOCUSED, &rgba);
Milan Crha c605da
+	if (!gtk_style_context_lookup_color (
Milan Crha c605da
+			style_context,
Milan Crha c605da
+			backdrop ? "theme_unfocused_fg_color" : "theme_fg_color",
Milan Crha c605da
+			&rgba))
Milan Crha c605da
+		gdk_rgba_parse (&rgba, "#000000");
Milan Crha c605da
 	e_mail_formatter_set_color (
Milan Crha c605da
 		formatter, E_MAIL_FORMATTER_COLOR_TEXT, &rgba);
Milan Crha c605da
 
Milan Crha c605da
@@ -605,7 +613,7 @@ e_mail_formatter_class_init (EMailFormatterClass *class)
Milan Crha c605da
 	gdk_rgba_parse (rgba, "#3f3f3f");
Milan Crha c605da
 
Milan Crha c605da
 	rgba = &class->colors[E_MAIL_FORMATTER_COLOR_HEADER];
Milan Crha c605da
-	gdk_rgba_parse (rgba, "#eeeeee");
Milan Crha c605da
+	gdk_rgba_parse (rgba, "#000000");
Milan Crha c605da
 
Milan Crha c605da
 	rgba = &class->colors[E_MAIL_FORMATTER_COLOR_TEXT];
Milan Crha c605da
 	gdk_rgba_parse (rgba, "#000000");
Milan Crha c605da
-- 
Milan Crha c605da
cgit v0.10.1
Milan Crha c605da