client: Always load email once view is mapped

Remove CSS width workaround.

Fix #283 #1205
This commit is contained in:
Cédric Bellegarde 2023-03-01 22:02:11 +01:00 committed by Niels De Graef
parent d47e357b2c
commit 40a2c1aec4
6 changed files with 69 additions and 38 deletions

View file

@ -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);
}

View file

@ -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));

View file

@ -43,7 +43,7 @@ public abstract class Components.WebViewTestCase<V> : 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();
}

View file

@ -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();
}

View file

@ -421,7 +421,7 @@ I can send email through smtp.gmail.com:587 or through <a href="https://www.gmai
protected void load_body_fixture_full(string body,
string quote,
bool top_posting) {
this.test_view.load_html(body, quote, top_posting, false);
this.test_view.load_html_headless(body, quote, top_posting, false);
while (this.test_view.is_loading) {
Gtk.main_iteration();
}

View file

@ -23,15 +23,6 @@ html {
width: 100vw !important;
height: max-content !important;
/* Despite the fact that the width must always be defined by the
viewport, 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, set a
reasonable minimum width. See
https://gitlab.gnome.org/GNOME/geary/-/issues/283 */
min-width: 400px !important;
/* Lock down the box sizing just enough so that the width and height
constraints above work as expected, and so the element's
scrollHeight is accurate. */