From aef05e105fb157d8856863c7858d1ce596bd6f2e Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 17 Sep 2017 05:07:42 -0400 Subject: src/tab-chrome.[ch]: Hack around progress bar issue If loading fails, the WebKitWebView's "estimated-load-progress" is set to 1.0 after signals like "load-changed" and "load-failed" are emitted. So the only way to avoid leaving behind a full progress bar after, for example, canceling a page load is to save a flag on a failed load and only update the progress bar if the flag is unset. --- (limited to 'src') diff --git a/src/tab-chrome.c b/src/tab-chrome.c index c3d5860..719d362 100644 --- a/src/tab-chrome.c +++ b/src/tab-chrome.c @@ -113,6 +113,8 @@ navigation_toolbar_new(MqTabChrome *chrome, gchar *uri) gtk_widget_set_hexpand(GTK_WIDGET(navigation_toolbar), TRUE); + chrome->load_failed = FALSE; + return GTK_WIDGET(navigation_toolbar); } @@ -184,10 +186,24 @@ load_changed_cb(WebKitWebView *web_view, WebKitLoadEvent load_event, webkit_web_view_can_go_forward(web_view)); } +static gboolean +load_failed_cb(WebKitWebView __attribute__((unused)) *web_view, + WebKitLoadEvent __attribute__((unused)) load_event, + gchar __attribute__((unused)) *failing_uri, + GError __attribute__((unused)) *error, MqTabChrome *chrome) +{ + chrome->load_failed = TRUE; + return FALSE; +} + static void load_progress_cb(WebKitWebView *web_view, GParamSpec __attribute__((unused)) *paramspec, MqTabChrome *chrome) { + if (chrome->load_failed) { + chrome->load_failed = FALSE; + return; + } gtk_entry_set_progress_fraction(GTK_ENTRY(chrome->uri_entry), webkit_web_view_get_estimated_load_progress(web_view)); } @@ -239,6 +255,8 @@ connect_web_view(MqTabChrome *chrome) { g_signal_connect(chrome->web_view, "load-changed", G_CALLBACK(load_changed_cb), chrome); + g_signal_connect(chrome->web_view, "load-failed", + G_CALLBACK(load_failed_cb), chrome); g_signal_connect(chrome->web_view, "notify::estimated-load-progress", G_CALLBACK(load_progress_cb), chrome); g_signal_connect(chrome->web_view, "notify::uri", diff --git a/src/tab-chrome.h b/src/tab-chrome.h index 90182ef..aef59f9 100644 --- a/src/tab-chrome.h +++ b/src/tab-chrome.h @@ -37,6 +37,7 @@ typedef struct { GtkToolItem *stop_reload_button; GtkWidget *uri_entry; WebKitWebView *web_view; + gboolean load_failed; } MqTabChrome; MqTabChrome * -- cgit v0.9.1