From 5bab11348602b7f5281d3dd76cc7f93f48b18696 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 19 Nov 2021 17:45:03 +0800 Subject: [PATCH] Add `xwidget-webkit-estimated-load-progress' * doc/lispref/display.texi (Xwidgets): Document new function. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_estimated_load_progress): New function. (syms_of_xwidget): Define new subr. --- doc/lispref/display.texi | 8 ++++++++ etc/NEWS | 5 +++++ src/xwidget.c | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 8decff6fa8f..e9b50707ded 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -7004,6 +7004,14 @@ manually to reach a specific history item. Instead, @var{idx} should be passed as an index to @code{xwidget-webkit-goto-history}. @end defun +@defun xwidget-webkit-estimated-load-progress xwidget +Return an estimate of how much data is remaining to be transferred +before the page displayed by the WebKit widget @var{xwidget} is fully +loaded. + +The value returned is a float ranging between 0.0 and 1.0. +@end defun + @node Buttons @section Buttons @cindex buttons in buffers diff --git a/etc/NEWS b/etc/NEWS index cee2844be3a..ad31b232714 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -863,6 +863,11 @@ for performing searches on WebKit xwidgets. This function is used to obtain the history of page-loads in a given WebKit xwidget. ++++ +*** New function 'xwidget-webkit-estimated-load-progress'. +This function is used to obtain the estimated progress of page loading +in a given WebKit xwidget. + +++ *** 'load-changed' xwidget events are now more detailed. In particular, they can now have different arguments based on the diff --git a/src/xwidget.c b/src/xwidget.c index e1bf40ea437..62b01b741cd 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2555,6 +2555,29 @@ LIMIT is not specified or nil, it is treated as `50'. */) return list3 (back, here, forward); } + +DEFUN ("xwidget-webkit-estimated-load-progress", + Fxwidget_webkit_estimated_load_progress, Sxwidget_webkit_estimated_load_progress, + 1, 1, 0, doc: /* Get the estimated load progress of XWIDGET, a WebKit widget. +Return a value ranging from 0.0 to 1.0, based on how close XWIDGET +is to completely loading its page. */) + (Lisp_Object xwidget) +{ + struct xwidget *xw; + WebKitWebView *webview; + double value; + + CHECK_XWIDGET (xwidget); + xw = XXWIDGET (xwidget); + CHECK_WEBKIT_WIDGET (xw); + + block_input (); + webview = WEBKIT_WEB_VIEW (xw->widget_osr); + value = webkit_web_view_get_estimated_load_progress (webview); + unblock_input (); + + return make_float (value); +} #endif void @@ -2600,6 +2623,7 @@ syms_of_xwidget (void) #ifdef USE_GTK defsubr (&Sxwidget_webkit_load_html); defsubr (&Sxwidget_webkit_back_forward_list); + defsubr (&Sxwidget_webkit_estimated_load_progress); #endif defsubr (&Skill_xwidget); -- 2.39.2