Blame SOURCES/evolution-3.28.5-frame-flattenning.patch

9b9748
diff -up evolution-3.28.5/data/webview.css.frame-flattenning evolution-3.28.5/data/webview.css
9b9748
--- evolution-3.28.5/data/webview.css.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/data/webview.css	2022-09-14 11:12:42.996943588 +0200
9b9748
@@ -8,8 +8,8 @@ img {
9b9748
 }
9b9748
 
9b9748
 body {
9b9748
-  /* Use margin so that children can safely use width=100% */
9b9748
-  margin: 5px 10px 5px 10px;
9b9748
+  /* Use padding so that children can safely use width=100% */
9b9748
+  padding: 8px;
9b9748
 }
9b9748
 
9b9748
 th {
9b9748
@@ -30,21 +30,21 @@ img#__evo-contact-photo {
9b9748
 
9b9748
 img.navigable {
9b9748
   cursor: pointer;
9b9748
-  margin-right: 4px;
9b9748
+  padding-right: 4px;
9b9748
 }
9b9748
 
9b9748
 .attachments {
9b9748
   background: #FFF;
9b9748
   border: 1px solid silver;
9b9748
-  margin: 10px 10px 10px 10px;
9b9748
+  padding: 10px 10px 10px 10px;
9b9748
   border-left: 0;
9b9748
   border-right: 0;
9b9748
   border-bottom: 0;
9b9748
 }
9b9748
 
9b9748
 .attachment {
9b9748
-  margin-left: 8px;
9b9748
-  margin-right: 0px;
9b9748
+  padding-left: 8px;
9b9748
+  padding-right: 0px;
9b9748
 }
9b9748
 
9b9748
 .attachment td {
9b9748
@@ -58,21 +58,21 @@ iframe:not([id$=".itip"]) {
9b9748
 
9b9748
 .part-container {
9b9748
   height: 100%;
9b9748
-  margin-top: 2px;
9b9748
-  margin-bottom: 2px;
9b9748
+  padding: 0px;
9b9748
 }
9b9748
 
9b9748
 .part-container-nostyle iframe {
9b9748
-  margin-right: 10px;
9b9748
+  margin: 0px;
9b9748
+  padding: 0px;
9b9748
 }
9b9748
 
9b9748
 .part-container-inner-margin {
9b9748
-  margin: 8px;
9b9748
+  padding: 0px;
9b9748
 }
9b9748
 
9b9748
 object { /* GtkWidgets */
9b9748
-  margin-top: 2px;
9b9748
-  margin-bottom: 2px;
9b9748
+  padding-top: 2px;
9b9748
+  padding-bottom: 2px;
9b9748
 }
9b9748
 
9b9748
 .__evo-highlight {
9b9748
@@ -139,7 +139,7 @@ th.rtl {
9b9748
 /***** PRINTING *******/
9b9748
 
9b9748
 .printing-header {
9b9748
-  margin-bottom: 20px;
9b9748
+  padding-bottom: 20px;
9b9748
 }
9b9748
 
9b9748
 .printing-header h1,
9b9748
@@ -159,7 +159,7 @@ th.rtl {
9b9748
 /******* ITIP *********/
9b9748
 .itip.icon {
9b9748
   float: left;
9b9748
-  margin-right: 5px;
9b9748
+  padding-right: 5px;
9b9748
 }
9b9748
 
9b9748
 .itip.content {
9b9748
@@ -168,7 +168,7 @@ th.rtl {
9b9748
 }
9b9748
 
9b9748
 .itip.description {
9b9748
-  margin: 5px;
9b9748
+  padding: 5px;
9b9748
 }
9b9748
 
9b9748
 .itip tr {
9b9748
@@ -192,7 +192,7 @@ th.rtl {
9b9748
 }
9b9748
 
9b9748
 #table_row_buttons img {
9b9748
-  margin-right: 5px;
9b9748
+  padding-right: 5px;
9b9748
   vertical-align: middle;
9b9748
 }
9b9748
 
9b9748
diff -up evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c.frame-flattenning evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c
9b9748
--- evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/em-format/e-mail-formatter-text-plain.c	2022-09-14 11:12:42.996943588 +0200
9b9748
@@ -111,7 +111,7 @@ emfe_text_plain_format (EMailFormatterEx
9b9748
 		string =
9b9748
 			"
9b9748
 			"-e-web-view-background-color -e-web-view-text-color\" "
9b9748
-			"style=\"border: none; padding: 8px; margin: 0;\">";
9b9748
+			"style=\"border: none; padding: 0px; margin: 0;\">";
9b9748
 
9b9748
 		g_output_stream_write_all (
9b9748
 			stream, string, strlen (string),
9b9748
diff -up evolution-3.28.5/src/mail/e-mail-display.c.frame-flattenning evolution-3.28.5/src/mail/e-mail-display.c
9b9748
--- evolution-3.28.5/src/mail/e-mail-display.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/mail/e-mail-display.c	2022-09-14 11:12:42.997943589 +0200
9b9748
@@ -1529,6 +1529,19 @@ mail_display_set_fonts (EWebView *web_vi
9b9748
 	mail_display_get_font_settings (display->priv->settings, monospace, variable);
9b9748
 }
9b9748
 
9b9748
+static gboolean
9b9748
+mail_display_can_use_frame_flattening (void)
9b9748
+{
9b9748
+	guint wk_major, wk_minor;
9b9748
+
9b9748
+	wk_major = webkit_get_major_version ();
9b9748
+	wk_minor = webkit_get_minor_version ();
9b9748
+
9b9748
+	/* The 2.38 is the last version, which supports frame-flattening;
9b9748
+	   prefer it over the manual and expensive calculations. */
9b9748
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
9b9748
+}
9b9748
+
9b9748
 static void
9b9748
 mail_display_web_view_initialize (WebKitWebView *web_view)
9b9748
 {
9b9748
@@ -1536,9 +1549,11 @@ mail_display_web_view_initialize (WebKit
9b9748
 
9b9748
 	webkit_settings = webkit_web_view_get_settings (web_view);
9b9748
 
9b9748
-	g_object_set (webkit_settings,
9b9748
-		"enable-frame-flattening", TRUE,
9b9748
-		NULL);
9b9748
+	if (mail_display_can_use_frame_flattening ()) {
9b9748
+		g_object_set (webkit_settings,
9b9748
+			"enable-frame-flattening", TRUE,
9b9748
+			NULL);
9b9748
+	}
9b9748
 }
9b9748
 
9b9748
 static void
9b9748
diff -up evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c.frame-flattenning evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c
9b9748
--- evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/modules/text-highlight/e-mail-formatter-text-highlight.c	2022-09-14 11:12:42.997943589 +0200
9b9748
@@ -122,16 +122,26 @@ text_hightlight_read_data_thread (gpoint
9b9748
 {
9b9748
 	TextHighlightClosure *closure = user_data;
9b9748
 	gint nbuffer = 10240;
9b9748
+	gssize read;
9b9748
+	gsize wrote = 0;
9b9748
 	gchar *buffer;
9b9748
 
9b9748
 	g_return_val_if_fail (closure != NULL, NULL);
9b9748
 
9b9748
 	buffer = g_new (gchar, nbuffer);
9b9748
 
9b9748
+	strcpy (buffer, "<style>body{margin:0; padding:8px;}</style>");
9b9748
+	read = strlen (buffer);
9b9748
+
9b9748
+	if (!g_output_stream_write_all (closure->output_stream, buffer, read, &wrote, closure->cancellable, &closure->error) ||
9b9748
+	    (gssize) wrote != read || closure->error) {
9b9748
+		g_free (buffer);
9b9748
+		return NULL;
9b9748
+	}
9b9748
+
9b9748
 	while (!camel_stream_eos (closure->read_stream) &&
9b9748
 	       !g_cancellable_set_error_if_cancelled (closure->cancellable, &closure->error)) {
9b9748
-		gssize read;
9b9748
-		gsize wrote = 0;
9b9748
+		wrote = 0;
9b9748
 
9b9748
 		read = camel_stream_read (closure->read_stream, buffer, nbuffer, closure->cancellable, &closure->error);
9b9748
 		if (read < 0 || closure->error)
9b9748
diff -up evolution-3.28.5/src/web-extensions/e-dom-utils.c.frame-flattenning evolution-3.28.5/src/web-extensions/e-dom-utils.c
9b9748
--- evolution-3.28.5/src/web-extensions/e-dom-utils.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/web-extensions/e-dom-utils.c	2022-09-14 11:12:42.997943589 +0200
9b9748
@@ -837,9 +837,8 @@ set_iframe_and_body_width (WebKitDOMDocu
9b9748
 		gchar *style;
9b9748
 
9b9748
 		/* Message main body */
9b9748
-		local_width -= 8; /* 8 + 8 margins of body without iframes */
9b9748
-		if (level > 1)
9b9748
-			local_width -= 8;
9b9748
+		local_width -= level * 20; /* 10 + 10 margins of body without iframes */
9b9748
+		local_width -= 4;
9b9748
 
9b9748
 		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
9b9748
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
9b9748
@@ -867,7 +866,7 @@ set_iframe_and_body_width (WebKitDOMDocu
9b9748
 			style);
9b9748
 		g_free (style);
9b9748
 
9b9748
-		local_width -= 2; /* 1 + 1 frame borders */
9b9748
+		local_width -= 4; /* 2 + 2 frame borders */
9b9748
 
9b9748
 		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
9b9748
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
9b9748
@@ -891,15 +890,11 @@ set_iframe_and_body_width (WebKitDOMDocu
9b9748
 	} else {
9b9748
 		gchar *style;
9b9748
 
9b9748
-		local_width -= 20; /* 10 + 10 margins of body with iframes */
9b9748
-		local_width -= 8; /* attachment margin */
9b9748
-		local_width -= 2; /* 1 + 1 frame borders */
9b9748
+		local_width -= (level - 1) * 20; /* 10 + 10 margins of body with iframes */
9b9748
+		local_width -= 4; /* 2 + 2 frame borders */
9b9748
+		local_width -= 10; /* attachment margin */
9b9748
 
9b9748
-		/* We need to subtract another 10 pixels from the iframe width to
9b9748
-		 * have the iframe's borders on the correct place. We can't subtract
9b9748
-		 * it from local_width as we don't want to propagate this change
9b9748
-		 * further. */
9b9748
-		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width - 10);
9b9748
+		style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
9b9748
 		e_dom_utils_add_css_rule_into_style_sheet_in_document (
9b9748
 			document,
9b9748
 			"-e-mail-formatter-style-sheet",
9b9748
@@ -933,7 +928,7 @@ set_iframe_and_body_width (WebKitDOMDocu
9b9748
 		if (level == 0) {
9b9748
 			gchar *style = NULL;
9b9748
 
9b9748
-			tmp_local_width -= 8; /* attachment's margin */
9b9748
+			tmp_local_width -= 10; /* attachment's margin */
9b9748
 
9b9748
 			style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", tmp_local_width);
9b9748
 			e_dom_utils_add_css_rule_into_style_sheet_in_document (
9b9748
@@ -947,9 +942,7 @@ set_iframe_and_body_width (WebKitDOMDocu
9b9748
 				"-e-mail-formatter-style-sheet",
9b9748
 				".attachment-wrapper iframe[src*=\"__formatas=txt\"]",
9b9748
 				style);
9b9748
-			g_free (style);
9b9748
 
9b9748
-			style = g_strdup_printf ("width: %" G_GINT64_FORMAT "px;", local_width);
9b9748
 			e_dom_utils_add_css_rule_into_style_sheet_in_document (
9b9748
 				document,
9b9748
 				"-e-mail-formatter-style-sheet",
9b9748
@@ -992,8 +985,10 @@ dom_window_resize_cb (WebKitDOMDOMWindow
9b9748
 
9b9748
 	document = webkit_dom_dom_window_get_document (dom_window);
9b9748
 
9b9748
-	if (document)
9b9748
+	if (document) {
9b9748
 		e_dom_resize_document_content_to_preview_width (document);
9b9748
+		e_dom_update_iframe_height (document);
9b9748
+	}
9b9748
 }
9b9748
 
9b9748
 static gboolean
9b9748
@@ -1106,6 +1101,7 @@ e_dom_utils_e_mail_display_bind_dom (Web
9b9748
 	e_dom_wrap_long_anchors (document);
9b9748
 
9b9748
 	e_dom_resize_document_content_to_preview_width (document);
9b9748
+	e_dom_update_iframe_height (document);
9b9748
 }
9b9748
 
9b9748
 void
9b9748
@@ -1160,6 +1156,99 @@ e_dom_utils_e_mail_display_unstyle_block
9b9748
 	g_clear_object (&collection);
9b9748
 }
9b9748
 
9b9748
+static void
9b9748
+e_dom_update_iframe_height_recursive (WebKitDOMDocument *document)
9b9748
+{
9b9748
+	WebKitDOMHTMLCollection *frames = NULL;
9b9748
+	WebKitDOMHTMLElement *body;
9b9748
+	gulong ii, length;
9b9748
+
9b9748
+	frames = webkit_dom_document_get_elements_by_tag_name_as_html_collection (document, "iframe");
9b9748
+	length = webkit_dom_html_collection_get_length (frames);
9b9748
+	for (ii = 0; ii < length; ii++) {
9b9748
+		WebKitDOMHTMLIFrameElement *iframe;
9b9748
+		WebKitDOMDocument *content_document;
9b9748
+
9b9748
+		iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (webkit_dom_html_collection_item (frames, ii));
9b9748
+
9b9748
+		content_document = webkit_dom_html_iframe_element_get_content_document (iframe);
9b9748
+		if (!content_document)
9b9748
+			continue;
9b9748
+
9b9748
+		e_dom_update_iframe_height_recursive (content_document);
9b9748
+	}
9b9748
+
9b9748
+	body = webkit_dom_document_get_body (document);
9b9748
+	if (body) {
9b9748
+		WebKitDOMDOMWindow *default_view;
9b9748
+
9b9748
+		default_view = webkit_dom_document_get_default_view (document);
9b9748
+		if (default_view) {
9b9748
+			WebKitDOMElement *frame_elem;
9b9748
+
9b9748
+			frame_elem = webkit_dom_dom_window_get_frame_element (default_view);
9b9748
+			if (frame_elem) {
9b9748
+				WebKitDOMHTMLIFrameElement *iframe = WEBKIT_DOM_HTML_IFRAME_ELEMENT (frame_elem);
9b9748
+				WebKitDOMElement *body_elem = WEBKIT_DOM_ELEMENT (body);
9b9748
+				glong scroll_height;
9b9748
+				gchar *height;
9b9748
+
9b9748
+				scroll_height = webkit_dom_element_get_scroll_height (body_elem);
9b9748
+				height = webkit_dom_html_iframe_element_get_height (iframe);
9b9748
+				if (!height || scroll_height != (glong) g_ascii_strtoll (height, NULL, 10))
9b9748
+					webkit_dom_html_iframe_element_set_height (iframe, "10");
9b9748
+				g_free (height);
9b9748
+
9b9748
+				height = g_strdup_printf ("%" G_GINT64_FORMAT, (gint64) (scroll_height + 2 +
9b9748
+					(webkit_dom_element_get_scroll_width (body_elem) > webkit_dom_element_get_client_width (body_elem) ? 20 : 0)));
9b9748
+				webkit_dom_html_iframe_element_set_height (iframe, height);
9b9748
+				g_free (height);
9b9748
+			}
9b9748
+		}
9b9748
+
9b9748
+		g_clear_object (&default_view);
9b9748
+	}
9b9748
+
9b9748
+	g_clear_object (&frames);
9b9748
+}
9b9748
+
9b9748
+static gboolean
9b9748
+mail_display_can_use_frame_flattening (void)
9b9748
+{
9b9748
+	guint wk_major, wk_minor;
9b9748
+
9b9748
+	wk_major = webkit_get_major_version ();
9b9748
+	wk_minor = webkit_get_minor_version ();
9b9748
+
9b9748
+	/* The 2.38 is the last version, which supports frame-flattening;
9b9748
+	   prefer it over the manual and expensive calculations. */
9b9748
+	return (wk_major < 2) || (wk_major == 2 && wk_minor <= 38);
9b9748
+}
9b9748
+
9b9748
+void
9b9748
+e_dom_update_iframe_height (WebKitDOMDocument *document)
9b9748
+{
9b9748
+	WebKitDOMDOMWindow *default_view;
9b9748
+
9b9748
+	if (mail_display_can_use_frame_flattening ())
9b9748
+		return;
9b9748
+
9b9748
+	default_view = webkit_dom_document_get_default_view (document);
9b9748
+	if (default_view) {
9b9748
+		glong scroll_x, scroll_y;
9b9748
+
9b9748
+		scroll_x = webkit_dom_dom_window_get_scroll_x (default_view);
9b9748
+		scroll_y = webkit_dom_dom_window_get_scroll_y (default_view);
9b9748
+
9b9748
+		e_dom_update_iframe_height_recursive (document);
9b9748
+
9b9748
+		if (scroll_y != webkit_dom_dom_window_get_scroll_y (default_view))
9b9748
+			webkit_dom_dom_window_scroll_to (default_view, scroll_x, scroll_y);
9b9748
+	}
9b9748
+
9b9748
+	g_clear_object (&default_view);
9b9748
+}
9b9748
+
9b9748
 void
9b9748
 e_dom_utils_eab_contact_formatter_bind_dom (WebKitDOMDocument *document)
9b9748
 {
9b9748
diff -up evolution-3.28.5/src/web-extensions/e-dom-utils.h.frame-flattenning evolution-3.28.5/src/web-extensions/e-dom-utils.h
9b9748
--- evolution-3.28.5/src/web-extensions/e-dom-utils.h.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/web-extensions/e-dom-utils.h	2022-09-14 11:12:42.997943589 +0200
9b9748
@@ -69,6 +69,7 @@ void		e_dom_utils_e_mail_display_bind_do
9b9748
 						 GDBusConnection *connection);
9b9748
 void		e_dom_utils_e_mail_display_unstyle_blockquotes
9b9748
 						(WebKitDOMDocument *document);
9b9748
+void		e_dom_update_iframe_height	(WebKitDOMDocument *document);
9b9748
 WebKitDOMElement *
9b9748
 		e_dom_utils_find_element_by_selector
9b9748
 						(WebKitDOMDocument *document,
9b9748
diff -up evolution-3.28.5/src/web-extensions/e-web-extension.c.frame-flattenning evolution-3.28.5/src/web-extensions/e-web-extension.c
9b9748
--- evolution-3.28.5/src/web-extensions/e-web-extension.c.frame-flattenning	2018-07-30 15:37:05.000000000 +0200
9b9748
+++ evolution-3.28.5/src/web-extensions/e-web-extension.c	2022-09-14 11:12:42.997943589 +0200
9b9748
@@ -613,8 +613,10 @@ handle_method_call (GDBusConnection *con
9b9748
 
9b9748
 			e_dom_utils_hide_element (document, element_id, hidden);
9b9748
 
9b9748
-			if (expand_inner_data)
9b9748
+			if (expand_inner_data) {
9b9748
 				e_dom_resize_document_content_to_preview_width (document);
9b9748
+				e_dom_update_iframe_height (document);
9b9748
+			}
9b9748
 		}
9b9748
 
9b9748
 		g_dbus_method_invocation_return_value (invocation, NULL);