diff options
| -rw-r--r-- | lisp/xwidget.el | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index ebd79f246a1..ec611fe8c1b 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -25,7 +25,8 @@ | |||
| 25 | ;; | 25 | ;; |
| 26 | ;; See xwidget.c for more api functions. | 26 | ;; See xwidget.c for more api functions. |
| 27 | 27 | ||
| 28 | ;; TODO this breaks compilation when we don't have xwidgets. | 28 | ;; This breaks compilation when we don't have xwidgets. |
| 29 | ;; And is pointless when we do, since it's in C and so preloaded. | ||
| 29 | ;;(require 'xwidget-internal) | 30 | ;;(require 'xwidget-internal) |
| 30 | 31 | ||
| 31 | ;;; Code: | 32 | ;;; Code: |
| @@ -34,8 +35,8 @@ | |||
| 34 | (require 'bookmark) | 35 | (require 'bookmark) |
| 35 | 36 | ||
| 36 | (defcustom xwidget-webkit-scroll-behaviour 'native | 37 | (defcustom xwidget-webkit-scroll-behaviour 'native |
| 37 | "Scroll behaviour of the webkit instance. | 38 | "Scrolling behavior of the webkit instance. |
| 38 | 'native or 'image." | 39 | The possible values are: `native' or `image'." |
| 39 | :version "25.1" | 40 | :version "25.1" |
| 40 | :group 'frames ; TODO add xwidgets group if more options are added | 41 | :group 'frames ; TODO add xwidgets group if more options are added |
| 41 | :type '(choice (const native) (const image))) | 42 | :type '(choice (const native) (const image))) |
| @@ -58,14 +59,11 @@ | |||
| 58 | (declare-function get-buffer-xwidgets "xwidget.c" (buffer)) | 59 | (declare-function get-buffer-xwidgets "xwidget.c" (buffer)) |
| 59 | 60 | ||
| 60 | (defun xwidget-insert (pos type title width height &optional args) | 61 | (defun xwidget-insert (pos type title width height &optional args) |
| 61 | "Insert an xwidget at POS. | 62 | "Insert an xwidget at position POS. |
| 62 | given ID, TYPE, TITLE WIDTH and | 63 | Supply the xwidget's TYPE, TITLE, WIDTH, and HEIGHT. |
| 63 | HEIGHT in the current buffer. | 64 | See `make-xwidget' for the possible TYPE values. |
| 64 | 65 | The usage of optional argument ARGS depends on the xwidget. | |
| 65 | Return ID | 66 | This returns the result of `make-xwidget'." |
| 66 | |||
| 67 | see `make-xwidget' for types suitable for TYPE. | ||
| 68 | Optional argument ARGS usage depends on the xwidget." | ||
| 69 | (goto-char pos) | 67 | (goto-char pos) |
| 70 | (let ((id (make-xwidget (point) (point) | 68 | (let ((id (make-xwidget (point) (point) |
| 71 | type title width height args))) | 69 | type title width height args))) |
| @@ -92,8 +90,8 @@ Optional argument ARGS usage depends on the xwidget." | |||
| 92 | ;;;###autoload | 90 | ;;;###autoload |
| 93 | (defun xwidget-webkit-browse-url (url &optional new-session) | 91 | (defun xwidget-webkit-browse-url (url &optional new-session) |
| 94 | "Ask xwidget-webkit to browse URL. | 92 | "Ask xwidget-webkit to browse URL. |
| 95 | NEW-SESSION specifies whether to create a new xwidget-webkit session. URL | 93 | NEW-SESSION specifies whether to create a new xwidget-webkit session. |
| 96 | defaults to the string looking like a url around the cursor position." | 94 | Interactively, URL defaults to the string looking like a url around point." |
| 97 | (interactive (progn | 95 | (interactive (progn |
| 98 | (require 'browse-url) | 96 | (require 'browse-url) |
| 99 | (browse-url-interactive-arg "xwidget-webkit URL: " | 97 | (browse-url-interactive-arg "xwidget-webkit URL: " |
| @@ -141,32 +139,40 @@ defaults to the string looking like a url around the cursor position." | |||
| 141 | "Keymap for `xwidget-webkit-mode'.") | 139 | "Keymap for `xwidget-webkit-mode'.") |
| 142 | 140 | ||
| 143 | (defun xwidget-webkit-scroll-up () | 141 | (defun xwidget-webkit-scroll-up () |
| 144 | "Scroll webkit up,either native or like image mode." | 142 | "Scroll webkit up. |
| 143 | Depending on the value of `xwidget-webkit-scroll-behaviour', | ||
| 144 | this scrolls in 'native' fashion, or like `image-mode' would." | ||
| 145 | (interactive) | 145 | (interactive) |
| 146 | (if (eq xwidget-webkit-scroll-behaviour 'native) | 146 | (if (eq xwidget-webkit-scroll-behaviour 'native) |
| 147 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t 50) | 147 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t 50) |
| 148 | (image-scroll-up))) | 148 | (image-scroll-up))) |
| 149 | 149 | ||
| 150 | (defun xwidget-webkit-scroll-down () | 150 | (defun xwidget-webkit-scroll-down () |
| 151 | "Scroll webkit down,either native or like image mode." | 151 | "Scroll webkit down. |
| 152 | Depending on the value of `xwidget-webkit-scroll-behaviour', | ||
| 153 | this scrolls in 'native' fashion, or like `image-mode' would." | ||
| 152 | (interactive) | 154 | (interactive) |
| 153 | (if (eq xwidget-webkit-scroll-behaviour 'native) | 155 | (if (eq xwidget-webkit-scroll-behaviour 'native) |
| 154 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t -50) | 156 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t -50) |
| 155 | (image-scroll-down))) | 157 | (image-scroll-down))) |
| 156 | 158 | ||
| 157 | (defun xwidget-webkit-scroll-forward () | 159 | (defun xwidget-webkit-scroll-forward () |
| 158 | "Scroll webkit forward,either native or like image mode." | 160 | "Scroll webkit forwards. |
| 161 | Depending on the value of `xwidget-webkit-scroll-behaviour', | ||
| 162 | this scrolls in 'native' fashion, or like `image-mode' would." | ||
| 159 | (interactive) | 163 | (interactive) |
| 160 | (if (eq xwidget-webkit-scroll-behaviour 'native) | 164 | (if (eq xwidget-webkit-scroll-behaviour 'native) |
| 161 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t 50) | 165 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t 50) |
| 162 | (xwidget-webkit-scroll-forward))) | 166 | (xwidget-webkit-scroll-forward))) ; FIXME infloop! |
| 163 | 167 | ||
| 164 | (defun xwidget-webkit-scroll-backward () | 168 | (defun xwidget-webkit-scroll-backward () |
| 165 | "Scroll webkit backward,either native or like image mode." | 169 | "Scroll webkit backwards. |
| 170 | Depending on the value of `xwidget-webkit-scroll-behaviour', | ||
| 171 | this scrolls in 'native' fashion, or like `image-mode' would." | ||
| 166 | (interactive) | 172 | (interactive) |
| 167 | (if (eq xwidget-webkit-scroll-behaviour 'native) | 173 | (if (eq xwidget-webkit-scroll-behaviour 'native) |
| 168 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t -50) | 174 | (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t -50) |
| 169 | (xwidget-webkit-scroll-backward))) | 175 | (xwidget-webkit-scroll-backward))) ; FIXME infloop! |
| 170 | 176 | ||
| 171 | 177 | ||
| 172 | ;; The xwidget event needs to go into a higher level handler | 178 | ;; The xwidget event needs to go into a higher level handler |
| @@ -292,9 +298,7 @@ function findactiveelement(doc){ | |||
| 292 | ) | 298 | ) |
| 293 | 299 | ||
| 294 | (defun xwidget-webkit-insert-string (xw str) | 300 | (defun xwidget-webkit-insert-string (xw str) |
| 295 | "Insert string in the active field in the webkit. | 301 | "Insert string STR in the active field in the webkit XW." |
| 296 | Argument XW webkit. | ||
| 297 | Argument STR string." | ||
| 298 | ;; Read out the string in the field first and provide for edit. | 302 | ;; Read out the string in the field first and provide for edit. |
| 299 | (interactive | 303 | (interactive |
| 300 | (let* ((xww (xwidget-webkit-current-session)) | 304 | (let* ((xww (xwidget-webkit-current-session)) |
| @@ -310,9 +314,9 @@ Argument STR string." | |||
| 310 | "findactiveelement(document).type;"))) | 314 | "findactiveelement(document).type;"))) |
| 311 | (list xww | 315 | (list xww |
| 312 | (cond ((equal "text" field-type) | 316 | (cond ((equal "text" field-type) |
| 313 | (read-string "text:" field-value)) | 317 | (read-string "Text: " field-value)) |
| 314 | ((equal "password" field-type) | 318 | ((equal "password" field-type) |
| 315 | (read-passwd "password:" nil field-value)) | 319 | (read-passwd "Password: " nil field-value)) |
| 316 | ((equal "textarea" field-type) | 320 | ((equal "textarea" field-type) |
| 317 | (xwidget-webkit-begin-edit-textarea xww field-value)))))) | 321 | (xwidget-webkit-begin-edit-textarea xww field-value)))))) |
| 318 | (xwidget-webkit-execute-script | 322 | (xwidget-webkit-execute-script |
| @@ -325,7 +329,6 @@ Argument STR string." | |||
| 325 | XW is the xwidget identifier, TEXT is retrieved from the webkit." | 329 | XW is the xwidget identifier, TEXT is retrieved from the webkit." |
| 326 | (switch-to-buffer | 330 | (switch-to-buffer |
| 327 | (generate-new-buffer "textarea")) | 331 | (generate-new-buffer "textarea")) |
| 328 | |||
| 329 | (set (make-local-variable 'xwidget-xwbl) xw) | 332 | (set (make-local-variable 'xwidget-xwbl) xw) |
| 330 | (insert text)) | 333 | (insert text)) |
| 331 | 334 | ||
| @@ -343,11 +346,10 @@ XW is the xwidget identifier, TEXT is retrieved from the webkit." | |||
| 343 | ) | 346 | ) |
| 344 | 347 | ||
| 345 | (defun xwidget-webkit-show-named-element (xw element-name) | 348 | (defun xwidget-webkit-show-named-element (xw element-name) |
| 346 | "Make named-element show. for instance an anchor. | 349 | "Make webkit xwidget XW show a named element ELEMENT-NAME. |
| 347 | Argument XW is the xwidget. | 350 | For example, use this to display an anchor." |
| 348 | Argument ELEMENT-NAME is the element name to display in the webkit xwidget." | ||
| 349 | (interactive (list (xwidget-webkit-current-session) | 351 | (interactive (list (xwidget-webkit-current-session) |
| 350 | (read-string "element name:"))) | 352 | (read-string "Element name: "))) |
| 351 | ;;TODO since an xwidget is an Emacs object, it is not trivial to do | 353 | ;;TODO since an xwidget is an Emacs object, it is not trivial to do |
| 352 | ;; some things that are taken for granted in a normal browser. | 354 | ;; some things that are taken for granted in a normal browser. |
| 353 | ;; scrolling an anchor/named-element into view is one such thing. | 355 | ;; scrolling an anchor/named-element into view is one such thing. |
| @@ -371,11 +373,10 @@ Argument ELEMENT-NAME is the element name to display in the webkit xwidget." | |||
| 371 | (set-window-vscroll (selected-window) y t))) | 373 | (set-window-vscroll (selected-window) y t))) |
| 372 | 374 | ||
| 373 | (defun xwidget-webkit-show-id-element (xw element-id) | 375 | (defun xwidget-webkit-show-id-element (xw element-id) |
| 374 | "Make id-element show. for instance an anchor. | 376 | "Make webkit xwidget XW show an id-element ELEMENT-ID. |
| 375 | Argument XW is the webkit xwidget. | 377 | For example, use this to display an anchor." |
| 376 | Argument ELEMENT-ID is the id of the element to show." | ||
| 377 | (interactive (list (xwidget-webkit-current-session) | 378 | (interactive (list (xwidget-webkit-current-session) |
| 378 | (read-string "element id:"))) | 379 | (read-string "Element id: "))) |
| 379 | (let ((y (string-to-number | 380 | (let ((y (string-to-number |
| 380 | (xwidget-webkit-execute-script-rv | 381 | (xwidget-webkit-execute-script-rv |
| 381 | xw | 382 | xw |
| @@ -387,11 +388,10 @@ Argument ELEMENT-ID is the id of the element to show." | |||
| 387 | (set-window-vscroll (selected-window) y t))) | 388 | (set-window-vscroll (selected-window) y t))) |
| 388 | 389 | ||
| 389 | (defun xwidget-webkit-show-id-or-named-element (xw element-id) | 390 | (defun xwidget-webkit-show-id-or-named-element (xw element-id) |
| 390 | "Make id-element show. for instance an anchor. | 391 | "Make webkit xwidget XW show a name or element id ELEMENT-ID. |
| 391 | Argument XW is the webkit xwidget. | 392 | For example, use this to display an anchor." |
| 392 | Argument ELEMENT-ID is either a name or an element id." | ||
| 393 | (interactive (list (xwidget-webkit-current-session) | 393 | (interactive (list (xwidget-webkit-current-session) |
| 394 | (read-string "element id:"))) | 394 | (read-string "Name or element id: "))) |
| 395 | (let* ((y1 (string-to-number | 395 | (let* ((y1 (string-to-number |
| 396 | (xwidget-webkit-execute-script-rv | 396 | (xwidget-webkit-execute-script-rv |
| 397 | xw | 397 | xw |
| @@ -422,8 +422,7 @@ Argument ELEMENT-ID is either a name or an element id." | |||
| 422 | ;; It errors out if the buffer isn't visible, but then we don't get | 422 | ;; It errors out if the buffer isn't visible, but then we don't get |
| 423 | ;; the glitch, so silence errors. | 423 | ;; the glitch, so silence errors. |
| 424 | (ignore-errors | 424 | (ignore-errors |
| 425 | (recenter-top-bottom)) | 425 | (recenter-top-bottom))) |
| 426 | ) | ||
| 427 | 426 | ||
| 428 | (defun xwidget-webkit-adjust-size-to-window () | 427 | (defun xwidget-webkit-adjust-size-to-window () |
| 429 | "Adjust webkit to window." | 428 | "Adjust webkit to window." |
| @@ -432,9 +431,7 @@ Argument ELEMENT-ID is either a name or an element id." | |||
| 432 | (window-pixel-height))) | 431 | (window-pixel-height))) |
| 433 | 432 | ||
| 434 | (defun xwidget-webkit-adjust-size (w h) | 433 | (defun xwidget-webkit-adjust-size (w h) |
| 435 | "Manually set webkit size. | 434 | "Manually set webkit size to width W, height H." |
| 436 | Argument W width. | ||
| 437 | Argument H height." | ||
| 438 | ;; TODO shouldn't be tied to the webkit xwidget | 435 | ;; TODO shouldn't be tied to the webkit xwidget |
| 439 | (interactive "nWidth:\nnHeight:\n") | 436 | (interactive "nWidth:\nnHeight:\n") |
| 440 | (xwidget-resize (xwidget-webkit-current-session) w h)) | 437 | (xwidget-resize (xwidget-webkit-current-session) w h)) |
| @@ -468,7 +465,7 @@ Argument H height." | |||
| 468 | (xwidget-webkit-new-session url))) | 465 | (xwidget-webkit-new-session url))) |
| 469 | 466 | ||
| 470 | (defun xwidget-webkit-back () | 467 | (defun xwidget-webkit-back () |
| 471 | "Back in history." | 468 | "Go back in history." |
| 472 | (interactive) | 469 | (interactive) |
| 473 | (xwidget-webkit-execute-script (xwidget-webkit-current-session) | 470 | (xwidget-webkit-execute-script (xwidget-webkit-current-session) |
| 474 | "history.go(-1);")) | 471 | "history.go(-1);")) |
| @@ -480,7 +477,7 @@ Argument H height." | |||
| 480 | "history.go(0);")) | 477 | "history.go(0);")) |
| 481 | 478 | ||
| 482 | (defun xwidget-webkit-current-url () | 479 | (defun xwidget-webkit-current-url () |
| 483 | "Get the webkit url. place it on kill ring." | 480 | "Get the webkit url and place it on the kill-ring." |
| 484 | (interactive) | 481 | (interactive) |
| 485 | (let* ((rv (xwidget-webkit-execute-script-rv (xwidget-webkit-current-session) | 482 | (let* ((rv (xwidget-webkit-execute-script-rv (xwidget-webkit-current-session) |
| 486 | "document.URL")) | 483 | "document.URL")) |
| @@ -489,7 +486,7 @@ Argument H height." | |||
| 489 | url)) | 486 | url)) |
| 490 | 487 | ||
| 491 | (defun xwidget-webkit-execute-script-rv (xw script &optional default) | 488 | (defun xwidget-webkit-execute-script-rv (xw script &optional default) |
| 492 | "Same as 'xwidget-webkit-execute-script' but but with return value. | 489 | "Same as `xwidget-webkit-execute-script' but with return value. |
| 493 | XW is the webkit instance. SCRIPT is the script to execute. | 490 | XW is the webkit instance. SCRIPT is the script to execute. |
| 494 | DEFAULT is the default return value." | 491 | DEFAULT is the default return value." |
| 495 | ;; Notice the ugly "title" hack. It is needed because the Webkit | 492 | ;; Notice the ugly "title" hack. It is needed because the Webkit |
| @@ -518,7 +515,7 @@ DEFAULT is the default return value." | |||
| 518 | "window.getSelection().toString();")) | 515 | "window.getSelection().toString();")) |
| 519 | 516 | ||
| 520 | (defun xwidget-webkit-copy-selection-as-kill () | 517 | (defun xwidget-webkit-copy-selection-as-kill () |
| 521 | "Get the webkit selection and put it on the kill ring." | 518 | "Get the webkit selection and put it on the kill-ring." |
| 522 | (interactive) | 519 | (interactive) |
| 523 | (kill-new (xwidget-webkit-get-selection))) | 520 | (kill-new (xwidget-webkit-get-selection))) |
| 524 | 521 | ||
| @@ -527,13 +524,15 @@ DEFAULT is the default return value." | |||
| 527 | ;; Xwidget plist management (similar to the process plist functions) | 524 | ;; Xwidget plist management (similar to the process plist functions) |
| 528 | 525 | ||
| 529 | (defun xwidget-get (xwidget propname) | 526 | (defun xwidget-get (xwidget propname) |
| 530 | "Return the value of XWIDGET' PROPNAME property. | 527 | "Get an xwidget's property value. |
| 531 | This is the last value stored with `(xwidget-put XWIDGET PROPNAME VALUE)'." | 528 | XWIDGET is an xwidget, PROPNAME a property. |
| 529 | Returns the last value stored with `xwidget-put'." | ||
| 532 | (plist-get (xwidget-plist xwidget) propname)) | 530 | (plist-get (xwidget-plist xwidget) propname)) |
| 533 | 531 | ||
| 534 | (defun xwidget-put (xwidget propname value) | 532 | (defun xwidget-put (xwidget propname value) |
| 535 | "Change XWIDGET' PROPNAME property to VALUE. | 533 | "Set an xwidget's property value. |
| 536 | It can be retrieved with `(xwidget-get XWIDGET PROPNAME)'." | 534 | XWIDGET is an xwidget, PROPNAME a property to be set to specified VALUE. |
| 535 | You can retrieve the value with `xwidget-get'." | ||
| 537 | (set-xwidget-plist xwidget | 536 | (set-xwidget-plist xwidget |
| 538 | (plist-put (xwidget-plist xwidget) propname value))) | 537 | (plist-put (xwidget-plist xwidget) propname value))) |
| 539 | 538 | ||