;;
;; See xwidget.c for more api functions.
-;; TODO this breaks compilation when we don't have xwidgets.
+;; This breaks compilation when we don't have xwidgets.
+;; And is pointless when we do, since it's in C and so preloaded.
;;(require 'xwidget-internal)
;;; Code:
(require 'cl-lib)
(require 'bookmark)
-(defcustom xwidget-webkit-scroll-behaviour 'native
- "Scroll behaviour of the webkit instance.
-'native or 'image."
- :version "25.1"
- :group 'frames ; TODO add xwidgets group if more options are added
- :type '(choice (const native) (const image)))
-
(declare-function make-xwidget "xwidget.c"
- (beg end type title width height arguments &optional buffer))
+ (type title width height arguments &optional buffer))
(declare-function xwidget-set-adjustment "xwidget.c"
(xwidget axis relative value))
(declare-function xwidget-buffer "xwidget.c" (xwidget))
(declare-function xwidget-view-model "xwidget.c" (xwidget-view))
(declare-function delete-xwidget-view "xwidget.c" (xwidget-view))
(declare-function get-buffer-xwidgets "xwidget.c" (buffer))
+(declare-function xwidget-query-on-exit-flag "xwidget.c" (xwidget))
(defun xwidget-insert (pos type title width height &optional args)
- "Insert an xwidget at POS.
-given ID, TYPE, TITLE WIDTH and
-HEIGHT in the current buffer.
-
-Return ID
-
-see `make-xwidget' for types suitable for TYPE.
-Optional argument ARGS usage depends on the xwidget."
+ "Insert an xwidget at position POS.
+Supply the xwidget's TYPE, TITLE, WIDTH, and HEIGHT.
+See `make-xwidget' for the possible TYPE values.
+The usage of optional argument ARGS depends on the xwidget.
+This returns the result of `make-xwidget'."
(goto-char pos)
- (let ((id (make-xwidget (point) (point)
- type title width height args)))
+ (let ((id (make-xwidget type title width height args)))
(put-text-property (point) (+ 1 (point))
'display (list 'xwidget ':xwidget id))
id))
;;;###autoload
(defun xwidget-webkit-browse-url (url &optional new-session)
"Ask xwidget-webkit to browse URL.
-NEW-SESSION specifies whether to create a new xwidget-webkit session. URL
-defaults to the string looking like a url around the cursor position."
+NEW-SESSION specifies whether to create a new xwidget-webkit session.
+Interactively, URL defaults to the string looking like a url around point."
(interactive (progn
(require 'browse-url)
(browse-url-interactive-arg "xwidget-webkit URL: "
;;(xwidget-webkit-current-url)
)))
+ (or (featurep 'xwidget-internal)
+ (user-error "Your Emacs was not compiled with xwidgets support"))
(when (stringp url)
(if new-session
(xwidget-webkit-new-session url)
"Keymap for `xwidget-webkit-mode'.")
(defun xwidget-webkit-scroll-up ()
- "Scroll webkit up,either native or like image mode."
+ "Scroll webkit up."
(interactive)
- (if (eq xwidget-webkit-scroll-behaviour 'native)
- (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t 50)
- (image-scroll-up)))
+ (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t 50))
(defun xwidget-webkit-scroll-down ()
- "Scroll webkit down,either native or like image mode."
+ "Scroll webkit down."
(interactive)
- (if (eq xwidget-webkit-scroll-behaviour 'native)
- (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t -50)
- (image-scroll-down)))
+ (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t -50))
(defun xwidget-webkit-scroll-forward ()
- "Scroll webkit forward,either native or like image mode."
+ "Scroll webkit forwards."
(interactive)
- (if (eq xwidget-webkit-scroll-behaviour 'native)
- (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t 50)
- (xwidget-webkit-scroll-forward)))
+ (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t 50))
(defun xwidget-webkit-scroll-backward ()
- "Scroll webkit backward,either native or like image mode."
+ "Scroll webkit backwards."
(interactive)
- (if (eq xwidget-webkit-scroll-behaviour 'native)
- (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t -50)
- (xwidget-webkit-scroll-backward)))
+ (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t -50))
;; The xwidget event needs to go into a higher level handler
)
(defun xwidget-webkit-insert-string (xw str)
- "Insert string in the active field in the webkit.
-Argument XW webkit.
-Argument STR string."
+ "Insert string STR in the active field in the webkit XW."
;; Read out the string in the field first and provide for edit.
(interactive
(let* ((xww (xwidget-webkit-current-session))
"findactiveelement(document).type;")))
(list xww
(cond ((equal "text" field-type)
- (read-string "text:" field-value))
+ (read-string "Text: " field-value))
((equal "password" field-type)
- (read-passwd "password:" nil field-value))
+ (read-passwd "Password: " nil field-value))
((equal "textarea" field-type)
(xwidget-webkit-begin-edit-textarea xww field-value))))))
(xwidget-webkit-execute-script
XW is the xwidget identifier, TEXT is retrieved from the webkit."
(switch-to-buffer
(generate-new-buffer "textarea"))
-
(set (make-local-variable 'xwidget-xwbl) xw)
(insert text))
)
(defun xwidget-webkit-show-named-element (xw element-name)
- "Make named-element show. for instance an anchor.
-Argument XW is the xwidget.
-Argument ELEMENT-NAME is the element name to display in the webkit xwidget."
+ "Make webkit xwidget XW show a named element ELEMENT-NAME.
+For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
- (read-string "element name:")))
+ (read-string "Element name: ")))
;;TODO since an xwidget is an Emacs object, it is not trivial to do
;; some things that are taken for granted in a normal browser.
;; scrolling an anchor/named-element into view is one such thing.
(set-window-vscroll (selected-window) y t)))
(defun xwidget-webkit-show-id-element (xw element-id)
- "Make id-element show. for instance an anchor.
-Argument XW is the webkit xwidget.
-Argument ELEMENT-ID is the id of the element to show."
+ "Make webkit xwidget XW show an id-element ELEMENT-ID.
+For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
- (read-string "element id:")))
+ (read-string "Element id: ")))
(let ((y (string-to-number
(xwidget-webkit-execute-script-rv
xw
(set-window-vscroll (selected-window) y t)))
(defun xwidget-webkit-show-id-or-named-element (xw element-id)
- "Make id-element show. for instance an anchor.
-Argument XW is the webkit xwidget.
-Argument ELEMENT-ID is either a name or an element id."
+ "Make webkit xwidget XW show a name or element id ELEMENT-ID.
+For example, use this to display an anchor."
(interactive (list (xwidget-webkit-current-session)
- (read-string "element id:")))
+ (read-string "Name or element id: ")))
(let* ((y1 (string-to-number
(xwidget-webkit-execute-script-rv
xw
(defun xwidget-webkit-adjust-size-dispatch ()
"Adjust size according to mode."
(interactive)
- (if (eq xwidget-webkit-scroll-behaviour 'native)
- (xwidget-webkit-adjust-size-to-window)
- (xwidget-webkit-adjust-size-to-content))
+ (xwidget-webkit-adjust-size-to-window)
;; The recenter is intended to correct a visual glitch.
;; It errors out if the buffer isn't visible, but then we don't get
;; the glitch, so silence errors.
(ignore-errors
- (recenter-top-bottom))
- )
+ (recenter-top-bottom)))
(defun xwidget-webkit-adjust-size-to-window ()
"Adjust webkit to window."
(window-pixel-height)))
(defun xwidget-webkit-adjust-size (w h)
- "Manually set webkit size.
-Argument W width.
-Argument H height."
+ "Manually set webkit size to width W, height H."
;; TODO shouldn't be tied to the webkit xwidget
(interactive "nWidth:\nnHeight:\n")
(xwidget-resize (xwidget-webkit-current-session) w h))
(setq xwidget-webkit-last-session-buffer (switch-to-buffer
(get-buffer-create bufname)))
(insert " 'a' adjusts the xwidget size.")
- (setq xw (xwidget-insert 1 'webkit-osr bufname 1000 1000))
+ (setq xw (xwidget-insert 1 'webkit bufname 1000 1000))
(xwidget-put xw 'callback 'xwidget-webkit-callback)
(xwidget-webkit-mode)
(xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
(xwidget-webkit-new-session url)))
(defun xwidget-webkit-back ()
- "Back in history."
+ "Go back in history."
(interactive)
(xwidget-webkit-execute-script (xwidget-webkit-current-session)
"history.go(-1);"))
"history.go(0);"))
(defun xwidget-webkit-current-url ()
- "Get the webkit url. place it on kill ring."
+ "Get the webkit url and place it on the kill-ring."
(interactive)
(let* ((rv (xwidget-webkit-execute-script-rv (xwidget-webkit-current-session)
"document.URL"))
url))
(defun xwidget-webkit-execute-script-rv (xw script &optional default)
- "Same as 'xwidget-webkit-execute-script' but but with return value.
+ "Same as `xwidget-webkit-execute-script' but with return value.
XW is the webkit instance. SCRIPT is the script to execute.
-DEFAULT is the defaultreturn value."
+DEFAULT is the default return value."
;; Notice the ugly "title" hack. It is needed because the Webkit
;; API at the time of writing didn't support returning values. This
;; is a wrapper for the title hack so it's easy to remove should
"window.getSelection().toString();"))
(defun xwidget-webkit-copy-selection-as-kill ()
- "Get the webkit selection and put it on the kill ring."
+ "Get the webkit selection and put it on the kill-ring."
(interactive)
(kill-new (xwidget-webkit-get-selection)))
;; Xwidget plist management (similar to the process plist functions)
(defun xwidget-get (xwidget propname)
- "Return the value of XWIDGET' PROPNAME property.
-This is the last value stored with `(xwidget-put XWIDGET PROPNAME VALUE)'."
+ "Get an xwidget's property value.
+XWIDGET is an xwidget, PROPNAME a property.
+Returns the last value stored with `xwidget-put'."
(plist-get (xwidget-plist xwidget) propname))
(defun xwidget-put (xwidget propname value)
- "Change XWIDGET' PROPNAME property to VALUE.
-It can be retrieved with `(xwidget-get XWIDGET PROPNAME)'."
+ "Set an xwidget's property value.
+XWIDGET is an xwidget, PROPNAME a property to be set to specified VALUE.
+You can retrieve the value with `xwidget-get'."
(set-xwidget-plist xwidget
(plist-put (xwidget-plist xwidget) propname value)))