diff --git a/src/client/components/components-web-view.vala b/src/client/components/components-web-view.vala index 40101f6f..c2a2b062 100644 --- a/src/client/components/components-web-view.vala +++ b/src/client/components/components-web-view.vala @@ -395,6 +395,25 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface { * Loads a message HTML body into the view. */ public new void load_html(string? body, string? base_uri=null) { + this.body = body; + // The viewport width will be 0 if the email is loaded before + // its WebView is laid out in the widget hierarchy. As a workaround, to + // prevent this causing the email being squished down to is minimum + // width and hence being stretched right out in height, always load + // HTML once view is mapped + if (this.get_mapped()) { + base.load_html(body, base_uri ?? INTERNAL_URL_BODY); + } else { + this.map.connect(() => { + base.load_html(body, base_uri ?? INTERNAL_URL_BODY); + }); + } + } + + /** + * Loads a message HTML body into the view. + */ + public new void load_html_headless(string? body, string? base_uri=null) { this.body = body; base.load_html(body, base_uri ?? INTERNAL_URL_BODY); } diff --git a/src/client/composer/composer-web-view.vala b/src/client/composer/composer-web-view.vala index 8ef501b0..abba0d22 100644 --- a/src/client/composer/composer-web-view.vala +++ b/src/client/composer/composer-web-view.vala @@ -166,33 +166,21 @@ public class Composer.WebView : Components.WebView { string quote, bool top_posting, bool body_complete) { - StringBuilder html = new StringBuilder(); - string body_class = (this.is_rich_text) ? "" : "plain"; - html.append(HTML_PRE.printf(body_class)); - if (!body_complete) { - html.append(BODY_PRE.printf(BODY_HTML_ID)); - bool have_body = !Geary.String.is_empty(body); - if (have_body) { - html.append(body); - html.append(SPACER); - } + base.load_html( + get_internal_html(body, quote, top_posting, body_complete) + ); + } - if (!top_posting && !Geary.String.is_empty(quote)) { - html.append(quote); - html.append(SPACER); - } - - html.append(CURSOR); - html.append(BODY_POST.printf(SIGNATURE_HTML_ID)); - - if (top_posting && !Geary.String.is_empty(quote)) { - html.append_printf(QUOTE, QUOTE_HTML_ID, quote); - } - } else { - html.append(body); - } - html.append(HTML_POST); - base.load_html((string) html.data); + /** + * Loads a message HTML body into the view. + */ + public new void load_html_headless(string body, + string quote, + bool top_posting, + bool body_complete) { + base.load_html_headless( + get_internal_html(body, quote, top_posting, body_complete) + ); } /** @@ -518,6 +506,39 @@ public class Composer.WebView : Components.WebView { return flowed.str; } + private string get_internal_html(string body, + string quote, + bool top_posting, + bool body_complete) { + StringBuilder html = new StringBuilder(); + string body_class = (this.is_rich_text) ? "" : "plain"; + html.append(HTML_PRE.printf(body_class)); + if (!body_complete) { + html.append(BODY_PRE.printf(BODY_HTML_ID)); + bool have_body = !Geary.String.is_empty(body); + if (have_body) { + html.append(body); + html.append(SPACER); + } + + if (!top_posting && !Geary.String.is_empty(quote)) { + html.append(quote); + html.append(SPACER); + } + + html.append(CURSOR); + html.append(BODY_POST.printf(SIGNATURE_HTML_ID)); + + if (top_posting && !Geary.String.is_empty(quote)) { + html.append_printf(QUOTE, QUOTE_HTML_ID, quote); + } + } else { + html.append(body); + } + html.append(HTML_POST); + return (string) html.data; + } + private void on_cursor_context_changed(GLib.Variant? parameters) { if (parameters != null && parameters.classify() == STRING) { cursor_context_changed(new EditContext(parameters as string)); diff --git a/test/client/components/components-web-view-test-case.vala b/test/client/components/components-web-view-test-case.vala index 9f5db70f..8f8f92f7 100644 --- a/test/client/components/components-web-view-test-case.vala +++ b/test/client/components/components-web-view-test-case.vala @@ -43,7 +43,7 @@ public abstract class Components.WebViewTestCase : TestCase { protected virtual void load_body_fixture(string html = "") { WebView client_view = (WebView) this.test_view; - client_view.load_html(html); + client_view.load_html_headless(html); while (!client_view.is_content_loaded) { Gtk.main_iteration(); } diff --git a/test/client/composer/composer-web-view-test.vala b/test/client/composer/composer-web-view-test.vala index 8d02f0d2..a1cc2506 100644 --- a/test/client/composer/composer-web-view-test.vala +++ b/test/client/composer/composer-web-view-test.vala @@ -258,7 +258,7 @@ long, long, long, long, long, long, long, long, long, long, } protected override void load_body_fixture(string html = "") { - this.test_view.load_html(html, "", false, false); + this.test_view.load_html_headless(html, "", false, false); while (this.test_view.is_loading) { Gtk.main_iteration(); } diff --git a/test/js/composer-page-state-test.vala b/test/js/composer-page-state-test.vala index 85634fea..cbb19354 100644 --- a/test/js/composer-page-state-test.vala +++ b/test/js/composer-page-state-test.vala @@ -421,7 +421,7 @@ I can send email through smtp.gmail.com:587 or through