From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 51712@debbugs.gnu.org
Subject: bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html'
Date: Wed, 10 Nov 2021 07:56:02 +0800 [thread overview]
Message-ID: <87wnlgyjcd.fsf@yahoo.com> (raw)
In-Reply-To: <831r3p5sn4.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 09 Nov 2021 16:07:59 +0200")
[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> Then I'd suggest not to have it defined on non-GTK builds for now. It
> is confusing to have a function that silently does nothing (after
> wasting some cycles).
Thanks, I'll keep that in mind.
> I'd say that TEXT should be a string. The name itself doesn't
> necessarily say so.
Fixed, thanks.
>> +Optional argument @var{base-uri}, which should be a string, specifies
>> +the location of web resources, such as the resource @samp{foo.png} in
>> +the HTML tag @samp{<img src="foo.png">}. It defaults to
>> +@samp{about:blank}.
> Hmm... this is better, but at least I am still in the dark regarding
> the need for this optional argument. E.g., what would happen if you
> use that tag, but don't specify the URI?
I'm in the dark too. I am not a web developer, and browser engines are
remarkably lax about these things, but hopefully Lars can explain better
(after all, shr must deal with these things too), so I added him to the
Ccs.
> This still leaves me wondering why the entry talks about temporary
> files.
Previously, loading custom markup into a widget required using a
temporary file to store the markup.
>> +DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html,
>> + Sxwidget_webkit_load_html, 2, 3, 0,
>> + doc: /* Make XWIDGET's WebKit widget render text.
> ^^^^
> "text" should be in CAPS.
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-xwidget-webkit-load-html.patch --]
[-- Type: text/x-patch, Size: 3529 bytes --]
From 8877c57a09dce06f6b1b64294ce8a632f862cc6e Mon Sep 17 00:00:00 2001
From: Po Lu <luangruo@yahoo.com>
Date: Tue, 9 Nov 2021 21:36:40 +0800
Subject: [PATCH] Add `xwidget-webkit-load-html'
* doc/lispref/display.texi (Xwidgets): Document new function.
* etc/NEWS: Announce new function.
* src/xwidget.c (Fxwidget_webkit_load_html): New function.
(syms_of_xwidget): Define new subr.
---
doc/lispref/display.texi | 11 +++++++++++
etc/NEWS | 5 +++++
src/xwidget.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index b6bd14f887..0b6dc05267 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -6943,6 +6943,17 @@ Xwidgets
signals an error.
@end defun
+@defun xwidget-webkit-load-html xwidget text &optional base-uri
+Load @var{text}, a string, into @var{xwidget}, which should be a
+WebKit xwidget. It treats @var{text} as HTML markup, which will be
+rendered by @var{xwidget}.
+
+Optional argument @var{base-uri}, which should be a string, specifies
+the location of web resources, such as the resource @samp{foo.png} in
+the HTML tag @samp{<img src="foo.png">}. It defaults to
+@samp{about:blank}.
+@end defun
+
@node Buttons
@section Buttons
@cindex buttons in buffers
diff --git a/etc/NEWS b/etc/NEWS
index 807f31fa33..b55630336e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -792,6 +792,11 @@ what the widget will actually receive.
On GTK+, only key and function key events are implemented.
++++
+*** New function 'xwidget-webkit-load-html'.
+This function is used to load HTML text into WebKit xwidgets, without
+having to create a temporary file to store the markup.
+
+++
*** New functions for performing searches on WebKit xwidgets.
Some new functions, such as 'xwidget-webkit-search', have been added
diff --git a/src/xwidget.c b/src/xwidget.c
index fc76ce307e..2587b658e7 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -2139,6 +2139,43 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search,
return Qnil;
}
+#ifdef USE_GTK
+DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html,
+ Sxwidget_webkit_load_html, 2, 3, 0,
+ doc: /* Make XWIDGET's WebKit widget render TEXT.
+XWIDGET should be a WebKit xwidget, that will receive TEXT. TEXT
+should be a string that will be displayed by XWIDGET as HTML markup.
+BASE_URI should be a string containing a URI that is used to fetch
+resources, and if not specified, defaults to `about:blank'. */)
+ (Lisp_Object xwidget, Lisp_Object text, Lisp_Object base_uri)
+{
+ struct xwidget *xw;
+ WebKitWebView *webview;
+ char *data, *uri;
+
+ CHECK_XWIDGET (xwidget);
+ CHECK_STRING (text);
+ if (NILP (base_uri))
+ base_uri = build_string ("about:blank");
+ else
+ CHECK_STRING (base_uri);
+
+ base_uri = ENCODE_UTF_8 (base_uri);
+ text = ENCODE_UTF_8 (text);
+ xw = XXWIDGET (xwidget);
+
+ data = SSDATA (text);
+ uri = SSDATA (base_uri);
+ webview = WEBKIT_WEB_VIEW (xw->widget_osr);
+
+ block_input ();
+ webkit_web_view_load_html (webview, data, uri);
+ unblock_input ();
+
+ return Qnil;
+}
+#endif
+
void
syms_of_xwidget (void)
{
@@ -2177,6 +2214,9 @@ syms_of_xwidget (void)
defsubr (&Sxwidget_webkit_next_result);
defsubr (&Sxwidget_webkit_previous_result);
defsubr (&Sset_xwidget_buffer);
+#ifdef USE_GTK
+ defsubr (&Sxwidget_webkit_load_html);
+#endif
DEFSYM (QCxwidget, ":xwidget");
DEFSYM (QCtitle, ":title");
--
2.31.1
next prev parent reply other threads:[~2021-11-09 23:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <878rxx8w1i.fsf.ref@yahoo.com>
2021-11-09 10:26 ` bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09 13:21 ` Eli Zaretskii
2021-11-09 13:42 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-09 14:07 ` Eli Zaretskii
2021-11-09 23:56 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-10 0:02 ` Lars Ingebrigtsen
2021-11-10 0:14 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 0:22 ` Lars Ingebrigtsen
2021-11-10 2:44 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 5:59 ` Lars Ingebrigtsen
2021-11-10 6:08 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 12:50 ` Eli Zaretskii
2021-11-10 13:03 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 14:25 ` Eli Zaretskii
2021-11-11 0:31 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-10 4:34 ` Richard Stallman
2021-11-10 4:37 ` Lars Ingebrigtsen
2021-11-11 3:37 ` Richard Stallman
2021-11-10 4:47 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-09-09 18:26 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wnlgyjcd.fsf@yahoo.com \
--to=bug-gnu-emacs@gnu.org \
--cc=51712@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=larsi@gnus.org \
--cc=luangruo@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).