[evolution/gnome-3-24] Bug 781309 - Signature and import previews hard to read with dark theme



commit 3efc5d4429bf7f07415f70ba9b35f0a9b77be2dd
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 4 12:44:04 2017 +0200

    Bug 781309 - Signature and import previews hard to read with dark theme

 src/e-util/e-web-view-preview.c      |   20 ++++++++++++++++++--
 src/e-util/e-web-view.c              |   25 +++++++++++++++++++++++++
 src/web-extensions/e-web-extension.c |   20 ++++++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
---
diff --git a/src/e-util/e-web-view-preview.c b/src/e-util/e-web-view-preview.c
index 3e8833d..9ddeba0 100644
--- a/src/e-util/e-web-view-preview.c
+++ b/src/e-util/e-web-view-preview.c
@@ -20,6 +20,7 @@
 
 #include "evolution-config.h"
 
+#include "e-misc-utils.h"
 #include "e-web-view-preview.h"
 
 #include <string.h>
@@ -268,6 +269,10 @@ e_web_view_preview_set_escape_values (EWebViewPreview *preview,
 void
 e_web_view_preview_begin_update (EWebViewPreview *preview)
 {
+       GtkStyleContext *style_context;
+       GdkRGBA color;
+       gchar *color_value;
+
        g_return_if_fail (E_IS_WEB_VIEW_PREVIEW (preview));
 
        if (preview->priv->updating_content) {
@@ -275,7 +280,18 @@ e_web_view_preview_begin_update (EWebViewPreview *preview)
                g_string_free (preview->priv->updating_content, TRUE);
        }
 
-       preview->priv->updating_content = g_string_new ("<TABLE width=\"100%\" border=\"0\" cols=\"2\">");
+       style_context = gtk_widget_get_style_context (GTK_WIDGET (preview));
+
+       if (gtk_style_context_lookup_color (style_context, "theme_fg_color", &color))
+               color_value = g_strdup_printf ("#%06x", e_rgba_to_value (&color));
+       else
+               color_value = g_strdup (E_UTILS_DEFAULT_THEME_FG_COLOR);
+
+       preview->priv->updating_content = g_string_sized_new (1024);
+       g_string_append_printf (preview->priv->updating_content, "<BODY class=\"-e-web-view-background-color 
-e-web-view-text-color\" text=\"%s\">", color_value);
+       g_string_append (preview->priv->updating_content, "<TABLE width=\"100%\" border=\"0\" cols=\"2\">");
+
+       g_free (color_value);
 }
 
 void
@@ -286,7 +302,7 @@ e_web_view_preview_end_update (EWebViewPreview *preview)
        g_return_if_fail (E_IS_WEB_VIEW_PREVIEW (preview));
        g_return_if_fail (preview->priv->updating_content != NULL);
 
-       g_string_append (preview->priv->updating_content, "</TABLE>");
+       g_string_append (preview->priv->updating_content, "</TABLE></BODY>");
 
        web_view = e_web_view_preview_get_preview (preview);
        if (E_IS_WEB_VIEW (web_view))
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index 44c767d..ff9a3f6 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -660,6 +660,27 @@ web_view_decide_policy_cb (EWebView *web_view,
 }
 
 static void
+e_web_view_ensure_body_class (EWebView *web_view)
+{
+       GDBusProxy *web_extension;
+
+       g_return_if_fail (E_IS_WEB_VIEW (web_view));
+
+       web_extension = e_web_view_get_web_extension_proxy (web_view);
+       if (!web_extension)
+               return;
+
+       e_util_invoke_g_dbus_proxy_call_with_error_check (
+               web_extension,
+               "EWebViewEnsureBodyClass",
+               g_variant_new (
+                       "(ts)",
+                       webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (web_view)),
+                       "-e-web-view-background-color -e-web-view-text-color"),
+               NULL);
+}
+
+static void
 style_updated_cb (EWebView *web_view)
 {
        GdkRGBA color;
@@ -726,6 +747,7 @@ web_view_load_changed_cb (WebKitWebView *webkit_web_view,
        if (load_event != WEBKIT_LOAD_FINISHED)
                return;
 
+       e_web_view_ensure_body_class (web_view);
        style_updated_cb (web_view);
 
        web_view_update_document_highlights (web_view);
@@ -1641,6 +1663,9 @@ web_extension_proxy_created_cb (GDBusProxy *proxy,
                                NULL);
 
                g_hash_table_foreach (web_view->priv->element_clicked_cbs, 
web_view_register_element_clicked_hfunc, web_view);
+
+               e_web_view_ensure_body_class (web_view);
+               style_updated_cb (web_view);
        }
 
        g_clear_object (&web_view);
diff --git a/src/web-extensions/e-web-extension.c b/src/web-extensions/e-web-extension.c
index a4a7ce6..cb67a5a 100644
--- a/src/web-extensions/e-web-extension.c
+++ b/src/web-extensions/e-web-extension.c
@@ -183,6 +183,10 @@ static const char introspection_xml[] =
 "      <arg type='b' name='towards_bottom' direction='in'/>"
 "      <arg type='b' name='processed' direction='out'/>"
 "    </method>"
+"    <method name='EWebViewEnsureBodyClass'>"
+"      <arg type='t' name='page_id' direction='in'/>"
+"      <arg type='s' name='body_class' direction='in'/>"
+"    </method>"
 "    <signal name='NeedInputChanged'>"
 "      <arg type='t' name='page_id' direction='out'/>"
 "      <arg type='b' name='need_input' direction='out'/>"
@@ -1018,6 +1022,22 @@ handle_method_call (GDBusConnection *connection,
                }
 
                g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", processed));
+       } else if (g_strcmp0 (method_name, "EWebViewEnsureBodyClass") == 0) {
+               const gchar *body_class = NULL;
+               WebKitDOMHTMLElement *body;
+
+               g_variant_get (parameters, "(t&s)", &page_id, &body_class);
+               web_page = get_webkit_web_page_or_return_dbus_error (invocation, web_extension, page_id);
+               if (!web_page)
+                       return;
+
+               document = webkit_web_page_get_dom_document (web_page);
+
+               body = webkit_dom_document_get_body (document);
+               if (body && !webkit_dom_element_has_attribute (WEBKIT_DOM_ELEMENT (body), "class"))
+                       webkit_dom_element_set_class_name (WEBKIT_DOM_ELEMENT (body), body_class);
+
+               g_dbus_method_invocation_return_value (invocation, NULL);
        }
 }
 


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