diff options
| author | Joakim Verona | 2011-08-22 01:04:50 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-08-22 01:04:50 +0200 |
| commit | c0ebe7cea4722801eab10b22f12cf7ce146e3fc9 (patch) | |
| tree | 9da55324838f0619360c2679055116cf7dda4ba8 | |
| parent | 324cf6dc8b18f90e6b9ca315608fd37838bd822a (diff) | |
| download | emacs-c0ebe7cea4722801eab10b22f12cf7ce146e3fc9.tar.gz emacs-c0ebe7cea4722801eab10b22f12cf7ce146e3fc9.zip | |
improved webkit field edit
| -rw-r--r-- | lisp/xwidget.el | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 1700a37b500..73ab7bf66bf 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -191,20 +191,51 @@ defaults to the string looking like a url around the cursor position." | |||
| 191 | (xwidget-resize xw (car size) (cadr size)))) | 191 | (xwidget-resize xw (car size) (cadr size)))) |
| 192 | 192 | ||
| 193 | 193 | ||
| 194 | (defvar xwidget-webkit-activeelement-js | ||
| 195 | " | ||
| 196 | function findactiveelement(myframes){ | ||
| 197 | if(document.activeElement.value != undefined) | ||
| 198 | return document.activeElement; | ||
| 199 | for(i=0;i<myframes.length;i++){ | ||
| 200 | if(myframes[i].document.activeElement.value != undefined) | ||
| 201 | return myframes[i].document.activeElement; | ||
| 202 | else{ | ||
| 203 | if(myframes[i].frames.length > 0) | ||
| 204 | findactiveelement(myframes[i].frames); | ||
| 205 | else | ||
| 206 | return; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | " | ||
| 212 | |||
| 213 | "javascript that finds the active element." | ||
| 214 | ;;yes its ugly. because: | ||
| 215 | ;; - there is aparently no way to find the active frame other than recursion | ||
| 216 | ;; - the js "for each" construct missbehaved on the "frames" collection | ||
| 217 | ;; - a window with no frameset still has frames.length == 1, but frames[0].document.activeElement != document.activeElement | ||
| 218 | |||
| 219 | ) | ||
| 220 | |||
| 194 | (defun xwidget-webkit-insert-string (xw str) | 221 | (defun xwidget-webkit-insert-string (xw str) |
| 195 | "Insert string in the active field in the webkit. | 222 | "Insert string in the active field in the webkit. |
| 196 | Argument XW webkit. | 223 | Argument XW webkit. |
| 197 | Argument STR string." | 224 | Argument STR string." |
| 198 | ;;TODO read out the string in the field first and provide for edit | 225 | ;;read out the string in the field first and provide for edit |
| 199 | (interactive | 226 | (interactive |
| 200 | (let* ((xww (xwidget-webkit-current-session)) | 227 | (let* ((xww (xwidget-webkit-current-session)) |
| 201 | (field-value | 228 | (field-value |
| 202 | (progn | 229 | (progn |
| 203 | (xwidget-webkit-execute-script xww "document.title=document.activeElement.value;") | 230 | (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) |
| 231 | (xwidget-webkit-execute-script xww "document.title=findactiveelement(frames).value") | ||
| 204 | (xwidget-webkit-get-title xww)))) | 232 | (xwidget-webkit-get-title xww)))) |
| 205 | (list xww | 233 | (list xww |
| 206 | (read-string "string:" field-value)))) | 234 | (read-string "string:" field-value)))) |
| 207 | (xwidget-webkit-execute-script xw (format "document.activeElement.value='%s'" str))) | 235 | (xwidget-webkit-execute-script xw (format "findactiveelement(frames).value='%s'" str))) |
| 236 | |||
| 237 | |||
| 238 | |||
| 208 | 239 | ||
| 209 | (defun xwidget-webkit-adjust-size-to-content () | 240 | (defun xwidget-webkit-adjust-size-to-content () |
| 210 | "Adjust webkit to content size." | 241 | "Adjust webkit to content size." |