From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#51712: 29.0.50; [PATCH] New function `xwidget-webkit-load-html' Date: Tue, 09 Nov 2021 21:42:06 +0800 Message-ID: <87y25x5tu9.fsf@yahoo.com> References: <878rxx8w1i.fsf.ref@yahoo.com> <878rxx8w1i.fsf@yahoo.com> <83h7cl5urs.fsf@gnu.org> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26958"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: 51712@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 09 14:43:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mkRPA-0006s5-0u for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Nov 2021 14:43:16 +0100 Original-Received: from localhost ([::1]:34112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkRP9-0002G4-0x for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Nov 2021 08:43:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:34806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkROw-0002FR-TT for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 08:43:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkROw-000415-L3 for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 08:43:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mkROw-00008d-BT for bug-gnu-emacs@gnu.org; Tue, 09 Nov 2021 08:43:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Nov 2021 13:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51712-submit@debbugs.gnu.org id=B51712.1636465349486 (code B ref 51712); Tue, 09 Nov 2021 13:43:02 +0000 Original-Received: (at 51712) by debbugs.gnu.org; 9 Nov 2021 13:42:29 +0000 Original-Received: from localhost ([127.0.0.1]:32998 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkROO-00007l-I5 for submit@debbugs.gnu.org; Tue, 09 Nov 2021 08:42:28 -0500 Original-Received: from sonic301-31.consmr.mail.ne1.yahoo.com ([66.163.184.200]:37322) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkROK-00007T-Vg for 51712@debbugs.gnu.org; Tue, 09 Nov 2021 08:42:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1636465339; bh=JhENjCz8OfkRNzIbtZb3s56eURRodywRH5F0l+zDHe4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=SUZSs4yJKzqjSI25zcDmBLX9/GIwdz5OU3vRvSP6N7OxDVNrH6YVg1YABukpBi6lTMFA1CPYBmDSvEJ9W9mk89eEANmkBjqDNM1MyihN38EwQ2KCPpqTDud6zRazjy6hd7643ErDWqwAPFoAPNpf17mqrGgx6CTw4VbKr/aBGzJBcAPLytSbLjtN1qg5sfdthpJ+Sx61zSJLZeHPamhXp9CMv2Oo/HQ5RNnPv/4IZAI8KGEHMCoB7iOseWsRRu8wkgMbn4zOpFPSeGbeZED4Mv9gzjQ0YXDSma6QezHANok3Nh/lgKIg/k1QmHIin12k+zRTbKFL8fPGx/V61xERCA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1636465339; bh=kI4g8Gqm4/MH9mqii259XdKVfGglwd+zf08TpFt7CbP=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=DZfZtzspdG1wtwgi5dcyNzFY2l911xo3bxJEZAImIJEqJd3D7Hqd2pP96B+wv+do69RiGyg9KUUSGzGbVAFOxWVNd0dAK6Uu7e6klmv1PVGn7wF0XNL5g3B8ksWC46vAz3W0fsk+bcMg650/eUNQT8samQsPGHGexmcRm4xxL2a5k9twkjbI1HjYra3ipETF712hzxbmzuTea/10wk3SITGwRJUWZVWqfYIIxaREehbfWVNbazIRWcf38T5HaNsP3ZCpEKWWXwzLuhrkPZfOYgziDDNrsoi+q3aLh9Hfgl2jauvV3V43uq92FYed5Pyku5zBrUei8KSKV3tbEcNDDw== X-YMail-OSG: inltetMVM1nLjtN6ZHozJBqvf3plr4qO1sh20Sn08FixwCyxUN0yd.CAdKkl5fb 73IuTOcsDLcjMy6teL3jbl4DPhm88tt2yG2v.ce4BTg8SuwmgiIvHrZo7lGL2drcs06snU6kZhqu Bm.dcBA6jT734rJ4UnkqwxU3Lc1gHl05zkNrL9DO2iRFKmGoxI5.iv23fD.SkkmFbHCPI0Jzgb_e pWv4x.7MGYQUbUk4pXmhoCumloMPj0vMe6pl41w2FT8q3xjhIx4IX779w_JVHYx.TRJyG9fqu_vu WidYw6OUsQqqd8ioRRB2stYdCI5RSWbNwXhm743uiTCu60emArnR1Eb67.jHBKfTmtcXN8T5t9.9 FpcNB83tXtA7scrm3KY__dG4fBwKawUfNuaaMUifgSISsnHoS89nrjtAR2sFwUe.2xbpe_mlDvqH 7b.oAhTfcq.XxtMh9xaYbjM0W_Rwfe45ltMg26O4_k_lg6IlVINSOdKH1J_FmqbplukgFkLadW0v ZwCFaGR7L1vO5UK.eBCgORgPTyWyj1cypnGNF_VN6yFCID.21XIFljdQT_Q2BoKmpytccKNJiLIa oy5yDv74rg3ZhX29UYfPQKBFBV6KQF3gbrSgdmkbiw.i4L3jflvVRPKfn5mG0Y4asxeGISDvXboj mwvCut.ThTotV2Y_SaRy2._oI3teTioJ5m9ag7ePKHn5lb13gNWRh5IGNJHIp2AVrtYOSBQP15gI 4JLFdePHlrTcHi.CM6m2wB8C0vRT3StPkw4TN88RBpsMTlZiZezhgWRdIWhNacuQ3cLy7udFID6. 4I8rBz.ABwbvWK0Vhb20FDhdnj7Gk6SMCmktgOsjvK X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Tue, 9 Nov 2021 13:42:19 +0000 Original-Received: by kubenode501.mail-prod1.omega.sg3.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID d432b1c7e9ece9ef4d367970d501bed4; Tue, 09 Nov 2021 13:42:12 +0000 (UTC) In-Reply-To: <83h7cl5urs.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 09 Nov 2021 15:21:59 +0200") X-Mailer: WebService/1.1.19266 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219454 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > > can you rephrase the last sentence not to use passive tense, please? > > But BASE-URI is not an &optional argument above. > > And also, this sentence is unnecessarily complex because you state the > reason before the goal. It is much better to do it the other way > around, and while at that, make 2 simple sentences out of one complex > one: > > Optional argument @var{base-uri}, which should be a string, > specifies the location of the web resource. It defaults to > @samp{about:blank}. > > (Of course, now this begs the question: what does it mean "web > resource" for HTML text? How about answering that in the text?) > > The second part is either unnecessary or too terse. if it is > important to explain that, please elaborate how temporary files are > relevant here. > > The "plain text" part seems to contradict the text in the manual, > which says it will be rendered as HTML markup? > > "will be" is confusing: why the future tense? > > Also, what kind of Lisp type is that? It should be a string, thanks, I've resolved the concerns you listed above. > And I think explaining the importance of "fetching resources" would be > beneficiary here. I documented it in the manual the best I could. I'm no web developer, and the WebKitGTK documentation is vague on this subject, so I can't think of anything better. > And finally, "is treated as equivalent" is better reworded as "and > defaults to ...", which is our style in these cases. Thanks, done. >> + if (NILP (base_uri)) >> + base_uri = build_string ("about:blank"); >> + CHECK_STRING (base_uri); > > That last line should better be under 'else', right? Done, thanks. >> + base_uri = ENCODE_UTF_8 (base_uri); > Is it a good idea to produce non-ASCII URIs? I personally think it's not, but the uuencoding of the URI is done by WebKitGTK, which expects strings passed as the `uri' parameter to be encoded as UTF-8 as opposed to uuencoded. >> + text = ENCODE_UTF_8 (text); >> + xw = XXWIDGET (xwidget); >> + >> +#ifdef USE_GTK >> + 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 (); >> +#endif > Hmm... if we only use TEXT and BASE-URI in the GTK build, why do we > encode them in the other builds? Isn't that a waste of cycles? IOW, > what does this function do if USE_GTK is not defined? This feature isn't supported on macOS, but it's my hope that someone will port it to macOS in short order. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-xwidget-webkit-load-html.patch >From 4d4b1013813bebf9d473cc04f73cf784fb759091 Mon Sep 17 00:00:00 2001 From: Po Lu 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..07b9f1a743 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} 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{}. 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..37e4fd94c1 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -2139,6 +2139,45 @@ DEFUN ("xwidget-webkit-finish-search", Fxwidget_webkit_finish_search, return Qnil; } +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; +#ifdef USE_GTK + WebKitWebView *webview; + char *data, *uri; +#endif + + CHECK_XWIDGET (xwidget); + CHECK_STRING (text); + if (NILP (base_uri)) + base_uri = build_string ("about:blank"); + else + CHECK_STRING (base_uri); + +#ifdef USE_GTK + 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 (); +#endif + + return Qnil; +} + void syms_of_xwidget (void) { @@ -2177,6 +2216,7 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_next_result); defsubr (&Sxwidget_webkit_previous_result); defsubr (&Sset_xwidget_buffer); + defsubr (&Sxwidget_webkit_load_html); DEFSYM (QCxwidget, ":xwidget"); DEFSYM (QCtitle, ":title"); -- 2.31.1 --=-=-=--