aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-11-09 06:19:09 +0100
committerLars Ingebrigtsen2021-11-09 06:19:09 +0100
commit9a67efa11b0fb9add6325cf68f8c0f8c7fcff861 (patch)
tree9580b0f0e5f6808baf1c1e1c270d6cfc0be7594e
parent5ba738eb0a24e54852e3a5fb11894a3f39355b7e (diff)
downloademacs-9a67efa11b0fb9add6325cf68f8c0f8c7fcff861.tar.gz
emacs-9a67efa11b0fb9add6325cf68f8c0f8c7fcff861.zip
Optionally use use xwidgets to display <video> elements in shr
* doc/misc/eww.texi (Advanced): Document it. * lisp/net/shr.el (shr-use-xwidgets-for-media): New user option. (shr-tag-video): Use xwidgets to display <video> elements.
-rw-r--r--doc/misc/eww.texi9
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/net/shr.el42
3 files changed, 55 insertions, 5 deletions
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index 5d308efba4d..95e59d98f8a 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -397,6 +397,15 @@ transformed URL. By default, this variable contains
397@code{eww-remove-tracking}, which removes the common @samp{utm_} 397@code{eww-remove-tracking}, which removes the common @samp{utm_}
398trackers from links. 398trackers from links.
399 399
400@cindex video
401@vindex shr-use-xwidgets-for-media
402 If Emacs has been built with xwidget support, EWW can use that to
403display @samp{<video>} elements. However, this support is still
404experimental, and on some systems doesn't work (and even worse) may
405crash your Emacs, so this feature is off by default. If you wish to
406switch it on, set @code{shr-use-xwidgets-for-media} to a
407non-@code{nil} value.
408
400@node Command Line 409@node Command Line
401@chapter Command Line Usage 410@chapter Command Line Usage
402 411
diff --git a/etc/NEWS b/etc/NEWS
index bb25365030d..c9144a5feeb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -228,7 +228,14 @@ If non-nil, 'C-c C-a' will put attached files at the end of the message.
228*** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition. 228*** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition.
229It narrows to the current node. 229It narrows to the current node.
230 230
231** eww 231** eww/shr
232
233+++
234*** New user option 'shr-use-xwidgets-for-media'.
235If non-nil (and Emacs has been built with support for xwidgets),
236display <video> elements with an xwidget. Note that this is
237experimental, and is known to crash Emacs on some systems, and just
238doesn't work on other systems. Also see etc/PROBLEMS.
232 239
233+++ 240+++
234*** New user option 'eww-url-transformers'. 241*** New user option 'eww-url-transformers'.
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index cb8ee73c14c..295ffddf059 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1626,6 +1626,14 @@ url if no type is specified. The value should be a float in the range 0.0 to
1626 :version "24.4" 1626 :version "24.4"
1627 :type '(alist :key-type regexp :value-type float)) 1627 :type '(alist :key-type regexp :value-type float))
1628 1628
1629(defcustom shr-use-xwidgets-for-media nil
1630 "If non-nil, use xwidgets to display video and audio elements.
1631This also depends on Emacs being built with xwidgets capability.
1632Note that this is experimental, and may lead to instability on
1633some platforms."
1634 :type 'boolean
1635 :version "29.1")
1636
1629(defun shr--get-media-pref (elem) 1637(defun shr--get-media-pref (elem)
1630 "Determine the preference for ELEM. 1638 "Determine the preference for ELEM.
1631The preference is a float determined from `shr-prefer-media-type'." 1639The preference is a float determined from `shr-prefer-media-type'."
@@ -1668,10 +1676,36 @@ The preference is a float determined from `shr-prefer-media-type'."
1668 (start (point))) 1676 (start (point)))
1669 (unless url 1677 (unless url
1670 (setq url (car (shr--extract-best-source dom)))) 1678 (setq url (car (shr--extract-best-source dom))))
1671 (if (> (length image) 0) 1679 (if (and shr-use-xwidgets-for-media
1672 (shr-indirect-call 'img nil image) 1680 (fboundp 'make-xwidget))
1673 (shr-insert " [video] ")) 1681 ;; Play the video.
1674 (shr-urlify start (shr-expand-url url)))) 1682 (progn
1683 (let ((widget (make-xwidget
1684 'webkit
1685 "Video"
1686 (truncate (* (window-pixel-width) 0.8))
1687 (truncate (* (window-pixel-width) 0.8 0.75))))
1688 (file (make-temp-file "shr" nil ".html")))
1689 (run-at-time 1 nil (lambda ()
1690 (ignore-errors
1691 (delete-file file))))
1692 (insert
1693 (propertize
1694 " [video] "
1695 'display (list 'xwidget :xwidget widget)))
1696 (with-temp-buffer
1697 (insert
1698 (format
1699 "<video autoplay loop muted><source src=%S type=\"video/mp4\"></source></video>"
1700 url))
1701 (write-region (point-min) (point-max) file nil 'silent))
1702 (xwidget-webkit-goto-uri widget
1703 (concat "file://" file))))
1704 ;; No xwidgets.
1705 (if (> (length image) 0)
1706 (shr-indirect-call 'img nil image)
1707 (shr-insert " [video] "))
1708 (shr-urlify start (shr-expand-url url)))))
1675 1709
1676(defun shr-tag-audio (dom) 1710(defun shr-tag-audio (dom)
1677 (let ((url (dom-attr dom 'src)) 1711 (let ((url (dom-attr dom 'src))