WebView: Finish event is correctly raised when the loaded URI is in the current page.

[GB.GTK3.WEBVIEW]
* BUG: WebView: Finish event is correctly raised when the loaded URI is in the current page.

[GB.QT4.WEBVIEW]
* BUG: WebView: Finish event is correctly raised when the loaded URI is in the current page.
* BUG: WebView: Start event is correctly raised.
* BUG: WebView: Cancelling the Start event now should cancel the load.

[GB.QT5.WEBVIEW]
* BUG: WebView: Finish event is correctly raised when the loaded URI is in the current page.
This commit is contained in:
gambas 2021-01-22 21:04:56 +01:00
parent 19822c4923
commit 01a666387f
4 changed files with 37 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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