aboutsummaryrefslogtreecommitdiffstats
path: root/src/xwidget.c
diff options
context:
space:
mode:
authorPo Lu2021-11-11 09:01:38 +0800
committerPo Lu2021-11-14 17:45:23 +0800
commitc3f53d26043a4e4a91a3f1d140f080b6c8d190d2 (patch)
treef10d8e8fe866db61efb07e32f490ebcca1dc344f /src/xwidget.c
parent609bc1d33ad81f9f2ffa0ff34522cfdb743d2dbb (diff)
downloademacs-c3f53d26043a4e4a91a3f1d140f080b6c8d190d2.tar.gz
emacs-c3f53d26043a4e4a91a3f1d140f080b6c8d190d2.zip
Expose xwidget navigation history to Lisp code
* doc/lispref/display.texi (Xwidgets): Document changes. * etc/NEWS: Announce new function. * src/xwidget.c (Fxwidget_webkit_back_forward_list): New function. (syms_of_xwidget): Define new subr.
Diffstat (limited to 'src/xwidget.c')
-rw-r--r--src/xwidget.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/xwidget.c b/src/xwidget.c
index 344016ed744..0e8bf13715f 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
20#include <config.h> 20#include <config.h>
21 21
22#include "buffer.h" 22#include "buffer.h"
23#include "coding.h"
23#include "xwidget.h" 24#include "xwidget.h"
24 25
25#include "lisp.h" 26#include "lisp.h"
@@ -2444,6 +2445,99 @@ to "about:blank". */)
2444 2445
2445 return Qnil; 2446 return Qnil;
2446} 2447}
2448
2449DEFUN ("xwidget-webkit-back-forward-list", Fxwidget_webkit_back_forward_list,
2450 Sxwidget_webkit_back_forward_list, 1, 2, 0,
2451 doc: /* Return the navigation history of XWIDGET, a WebKit xwidget.
2452
2453Return the history as a list of the form (BACK HERE FORWARD), where
2454HERE is the current navigation item, while BACK and FORWARD are lists
2455of history items of the form (IDX TITLE URI). Here, IDX is an index
2456that can be passed to `xwidget-webkit-goto-history', TITLE is a string
2457containing the human-readable title of the history item, and URI is
2458the URI of the history item.
2459
2460BACK, HERE, and FORWARD can all be nil depending on the state of the
2461navigation history.
2462
2463BACK and FORWARD will each not contain more elements than LIMIT. If
2464LIMIT is not specified or nil, it is treated as `50'. */)
2465 (Lisp_Object xwidget, Lisp_Object limit)
2466{
2467 struct xwidget *xw;
2468 Lisp_Object back, here, forward;
2469 WebKitWebView *webview;
2470 WebKitBackForwardList *list;
2471 WebKitBackForwardListItem *item;
2472 GList *parent, *tem;
2473 int i;
2474 unsigned int lim;
2475 Lisp_Object title, uri;
2476 const gchar *item_title, *item_uri;
2477
2478 back = Qnil;
2479 here = Qnil;
2480 forward = Qnil;
2481
2482 if (NILP (limit))
2483 limit = make_fixnum (50);
2484 else
2485 CHECK_FIXNAT (limit);
2486
2487 CHECK_LIVE_XWIDGET (xwidget);
2488 xw = XXWIDGET (xwidget);
2489
2490 webview = WEBKIT_WEB_VIEW (xw->widget_osr);
2491 list = webkit_web_view_get_back_forward_list (webview);
2492 item = webkit_back_forward_list_get_current_item (list);
2493 lim = XFIXNAT (limit);
2494
2495 if (item)
2496 {
2497 item_title = webkit_back_forward_list_item_get_title (item);
2498 item_uri = webkit_back_forward_list_item_get_uri (item);
2499 here = list3 (make_fixnum (0),
2500 build_string_from_utf8 (item_title ? item_title : ""),
2501 build_string_from_utf8 (item_uri ? item_uri : ""));
2502 }
2503 parent = webkit_back_forward_list_get_back_list_with_limit (list, lim);
2504
2505 if (parent)
2506 {
2507 for (i = 1, tem = parent; parent; parent = parent->next, ++i)
2508 {
2509 item = tem->data;
2510 item_title = webkit_back_forward_list_item_get_title (item);
2511 item_uri = webkit_back_forward_list_item_get_uri (item);
2512 title = build_string_from_utf8 (item_title ? item_title : "");
2513 uri = build_string_from_utf8 (item_uri ? item_uri : "");
2514 back = Fcons (list3 (make_fixnum (-i), title, uri), back);
2515 }
2516 }
2517
2518 back = Fnreverse (back);
2519 g_list_free (parent);
2520
2521 parent = webkit_back_forward_list_get_forward_list_with_limit (list, lim);
2522
2523 if (parent)
2524 {
2525 for (i = 1, tem = parent; parent; parent = parent->next, ++i)
2526 {
2527 item = tem->data;
2528 item_title = webkit_back_forward_list_item_get_title (item);
2529 item_uri = webkit_back_forward_list_item_get_uri (item);
2530 title = build_string_from_utf8 (item_title ? item_title : "");
2531 uri = build_string_from_utf8 (item_uri ? item_uri : "");
2532 forward = Fcons (list3 (make_fixnum (i), title, uri), forward);
2533 }
2534 }
2535
2536 forward = Fnreverse (forward);
2537 g_list_free (parent);
2538
2539 return list3 (back, here, forward);
2540}
2447#endif 2541#endif
2448 2542
2449void 2543void
@@ -2488,6 +2582,7 @@ syms_of_xwidget (void)
2488 defsubr (&Sset_xwidget_buffer); 2582 defsubr (&Sset_xwidget_buffer);
2489#ifdef USE_GTK 2583#ifdef USE_GTK
2490 defsubr (&Sxwidget_webkit_load_html); 2584 defsubr (&Sxwidget_webkit_load_html);
2585 defsubr (&Sxwidget_webkit_back_forward_list);
2491#endif 2586#endif
2492 defsubr (&Skill_xwidget); 2587 defsubr (&Skill_xwidget);
2493 2588