[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/15] xwidget: Do not use `xwidget-execute-script-rv' to insert
From: |
Ricardo Wurmus |
Subject: |
[PATCH 04/15] xwidget: Do not use `xwidget-execute-script-rv' to insert string |
Date: |
Mon, 24 Oct 2016 18:40:50 +0200 |
* lisp/xwidget.el (xwidget-webkit-insert-string): Obtain JavaScript
return value via callback instead of using
`xwidget-webkit-execute-script-rv'.
---
lisp/xwidget.el | 47 +++++++++++++++++++++++------------------------
1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index d2b9a09..a252fd7 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -286,31 +286,30 @@ function findactiveelement(doc){
;;TODO the activeelement type needs to be examined, for iframe, etc.
)
-(defun xwidget-webkit-insert-string (xw str)
- "Insert string STR in the active field in the webkit XW."
+(defun xwidget-webkit-insert-string ()
+ "Prompt for a string and insert it in the active field in the
+current webkit widget."
;; Read out the string in the field first and provide for edit.
- (interactive
- (let* ((xww (xwidget-webkit-current-session))
-
- (field-value
- (progn
- (xwidget-webkit-execute-script xww
xwidget-webkit-activeelement-js)
- (xwidget-webkit-execute-script-rv
- xww
- "findactiveelement(document).value;")))
- (field-type (xwidget-webkit-execute-script-rv
- xww
- "findactiveelement(document).type;")))
- (list xww
- (cond ((equal "text" field-type)
- (read-string "Text: " field-value))
- ((equal "password" field-type)
- (read-passwd "Password: " nil field-value))
- ((equal "textarea" field-type)
- (xwidget-webkit-begin-edit-textarea xww field-value))))))
- (xwidget-webkit-execute-script
- xw
- (format "findactiveelement(document).value='%s'" str)))
+ (interactive)
+ (let ((xww (xwidget-webkit-current-session)))
+ (xwidget-webkit-execute-script
+ xww
+ (concat xwidget-webkit-activeelement-js "
+(function () {
+ var res = findactiveelement(document);
+ return [res.value, res.type];
+})();")
+ (lambda (field)
+ (let ((str (pcase field
+ (`[,val "text"]
+ (read-string "Text: " val))
+ (`[,val "password"]
+ (read-passwd "Password: " nil val))
+ (`[,val "textarea"]
+ (xwidget-webkit-begin-edit-textarea xww val)))))
+ (xwidget-webkit-execute-script
+ xww
+ (format "findactiveelement(document).value='%s'" str)))))))
(defvar xwidget-xwbl)
(defun xwidget-webkit-begin-edit-textarea (xw text)
--
2.10.1
- [PATCH v2 00/15] xwidget webkit improvements, Ricardo Wurmus, 2016/10/24
- [PATCH v2 00/15] xwidget webkit improvements, Ricardo Wurmus, 2016/10/24
- [PATCH 01/15] xwidget: Use WebKit2 API, Ricardo Wurmus, 2016/10/24
- [PATCH 02/15] xwidget: Pass JavaScript return value to optional callback procedure, Ricardo Wurmus, 2016/10/24
- [PATCH 03/15] Remove scrolled window container around WebKit widget, Ricardo Wurmus, 2016/10/24
- [PATCH 04/15] xwidget: Do not use `xwidget-execute-script-rv' to insert string,
Ricardo Wurmus <=
- [PATCH 05/15] xwidget: Get title via asynchronous JavaScript., Ricardo Wurmus, 2016/10/24
- [PATCH 06/15] xwidget: Simplify functions to scroll to elements, Ricardo Wurmus, 2016/10/24
- [PATCH 07/15] xwidget: Add function to find element by CSS selector, Ricardo Wurmus, 2016/10/24
- [PATCH 08/15] xwidget: Get selection with asynchronous JavaScript, Ricardo Wurmus, 2016/10/24
- [PATCH 09/15] xwidget: Get URL asynchronously., Ricardo Wurmus, 2016/10/24
- [PATCH 10/15] xwidget: Remove title hack., Ricardo Wurmus, 2016/10/24
- [PATCH 11/15] Let initial WebKit view fill window, Ricardo Wurmus, 2016/10/24
- [PATCH 12/15] Dynamically resize WebKit widget., Ricardo Wurmus, 2016/10/24
- [PATCH 13/15] Implement zoom for WebKit widget., Ricardo Wurmus, 2016/10/24
- [PATCH 14/15] xwidget: Bind "beginning-of-buffer" and "end-of-buffer", Ricardo Wurmus, 2016/10/24