diff --git a/gb.gtk3/src/webview/c_webview.c b/gb.gtk3/src/webview/c_webview.c index 4ec170c62..c4a24c609 100644 --- a/gb.gtk3/src/webview/c_webview.c +++ b/gb.gtk3/src/webview/c_webview.c @@ -60,7 +60,10 @@ static void cb_title(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object static void cb_url(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object) { + //fprintf(stderr, "cb_url: %s\n", webkit_web_view_get_uri(WIDGET)); GB.Raise(THIS, EVENT_URL, 0); + if (!THIS->got_load_event) + GB.Raise(THIS, EVENT_FINISH, 0); } static void cb_icon(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object) @@ -72,13 +75,20 @@ static void cb_icon(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object) static void cb_load_changed(WebKitWebView *widget, WebKitLoadEvent load_event, CWEBVIEW *_object) { + //fprintf(stderr, "cb_load_changed: %d\n", load_event); + switch (load_event) { + case WEBKIT_LOAD_STARTED: + THIS->got_load_event = TRUE; + break; + case WEBKIT_LOAD_FINISHED: if (!THIS->error) GB.Raise(THIS, EVENT_FINISH, 0); GB.FreeString(&THIS->link); break; + default: break; } @@ -93,8 +103,13 @@ static gboolean cb_load_failed(WebKitWebView *widget, WebKitLoadEvent load_event static void cb_progress(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object) { + //fprintf(stderr, "cb_progress: %f\n", webkit_web_view_get_estimated_load_progress(WIDGET)); if (!THIS->error) + { GB.Raise(THIS, EVENT_PROGRESS, 0); + if (webkit_web_view_get_estimated_load_progress(WIDGET) == 1.0) + GB.Raise(THIS, EVENT_FINISH, 0); + } } static void cb_link(WebKitWebView *widget, WebKitHitTestResult *hit_test_result, guint modifiers, CWEBVIEW *_object) @@ -137,6 +152,7 @@ static gboolean cb_decide_policy(WebKitWebView *widget, WebKitPolicyDecision *de } THIS->error = FALSE; + THIS->got_load_event = FALSE; if (GB.Raise(THIS, EVENT_START, 0)) webkit_policy_decision_ignore(decision); @@ -341,7 +357,7 @@ END_METHOD BEGIN_METHOD_VOID(WebViewHistory_Clear) - fprintf(stderr, "gb.gtk3.webview: warning: WebView.History.Clear() does nothing yet.\n"); + fprintf(stderr, "gb.gtk3.webview: warning: WebKitGTK does not know how to clear its history at the moment.\n"); END_METHOD diff --git a/gb.gtk3/src/webview/c_webview.h b/gb.gtk3/src/webview/c_webview.h index 2658a8ed2..cdaa113de 100644 --- a/gb.gtk3/src/webview/c_webview.h +++ b/gb.gtk3/src/webview/c_webview.h @@ -35,9 +35,9 @@ typedef GTK_PICTURE icon; void *new_view; char *link; - double progress; unsigned error : 1; unsigned accept_next : 1; + unsigned got_load_event : 1; } CWEBVIEW; diff --git a/gb.qt4/src/webview/c_webview.cpp b/gb.qt4/src/webview/c_webview.cpp index 6e0e1d17e..58b5d0c78 100644 --- a/gb.qt4/src/webview/c_webview.cpp +++ b/gb.qt4/src/webview/c_webview.cpp @@ -114,6 +114,7 @@ static void stop_view(void *_object) THIS->stopping = TRUE; WIDGET->stop(); THIS->stopping = FALSE; + THIS->cancel = FALSE; } static void set_link(void *_object, const QString &link) @@ -533,7 +534,7 @@ void CWebView::loadProgress(int progress) { GET_SENDER(); - if (THIS->progress == progress) + if (THIS->cancel || THIS->progress == progress) return; THIS->progress = progress; @@ -546,7 +547,11 @@ void CWebView::loadStarted() THIS->progress = 0; _network_access_manager_view = THIS; - GB.Raise(THIS, EVENT_PROGRESS, 0); + THIS->cancel = GB.Raise(THIS, EVENT_START, 0); + if (THIS->cancel) + stop_view(THIS); + else + GB.Raise(THIS, EVENT_PROGRESS, 0); } /*void CWebView::selectionChanged() diff --git a/gb.qt5/src/webview/c_webview.cpp b/gb.qt5/src/webview/c_webview.cpp index 12bfda865..ea1103fc9 100644 --- a/gb.qt5/src/webview/c_webview.cpp +++ b/gb.qt5/src/webview/c_webview.cpp @@ -975,6 +975,8 @@ void WebViewSignalManager::loadStarted() THIS->progress = 0; THIS->cancel = GB.Raise(THIS, EVENT_START, 0); + if (!THIS->cancel) + GB.Raise(THIS, EVENT_PROGRESS, 0); } void WebViewSignalManager::loadProgress(int progress) @@ -986,16 +988,23 @@ void WebViewSignalManager::loadProgress(int progress) THIS->progress = progress; GB.Raise(THIS, EVENT_PROGRESS, 0); + + if (progress == 100) + GB.Raise(THIS, EVENT_FINISH, 0); } void WebViewSignalManager::loadFinished(bool ok) { GET_SENDER(); - THIS->progress = 100; - if (ok) - GB.Raise(THIS, EVENT_FINISH, 0); + { + if (THIS->progress < 100) + { + THIS->progress = 100; + GB.Raise(THIS, EVENT_FINISH, 0); + } + } else //if (!THIS->stopping) GB.Raise(THIS, EVENT_ERROR, 0);