diff options
| author | Joakim Verona | 2011-10-26 13:47:00 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-10-26 13:47:00 +0200 |
| commit | c591741609839575d7e0353a180b8eeb3e422fe1 (patch) | |
| tree | 0860e35b82648e3e475a06a135c067d7e37e028e | |
| parent | ac8bd0ce49c8259343d7cf56e0bc71bd120742c3 (diff) | |
| download | emacs-c591741609839575d7e0353a180b8eeb3e422fe1.tar.gz emacs-c591741609839575d7e0353a180b8eeb3e422fe1.zip | |
ugly title return value workaround
| -rw-r--r-- | lisp/xwidget.el | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 33ed66334ff..fa0a54cd4a3 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -227,10 +227,11 @@ Argument STR string." | |||
| 227 | ;;read out the string in the field first and provide for edit | 227 | ;;read out the string in the field first and provide for edit |
| 228 | (interactive | 228 | (interactive |
| 229 | (let* ((xww (xwidget-webkit-current-session)) | 229 | (let* ((xww (xwidget-webkit-current-session)) |
| 230 | |||
| 230 | (field-value | 231 | (field-value |
| 231 | (progn | 232 | (progn |
| 232 | (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) | 233 | (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) |
| 233 | (xwidget-webkit-execute-script-rv xww "findactiveelement(frames).value" "")))) | 234 | (xwidget-webkit-execute-script-rv xww "findactiveelement(frames).value")))) |
| 234 | (list xww | 235 | (list xww |
| 235 | (read-string "string:" field-value)))) | 236 | (read-string "string:" field-value)))) |
| 236 | (xwidget-webkit-execute-script xw (format "findactiveelement(frames).value='%s'" str))) | 237 | (xwidget-webkit-execute-script xw (format "findactiveelement(frames).value='%s'" str))) |
| @@ -238,12 +239,20 @@ Argument STR string." | |||
| 238 | 239 | ||
| 239 | (defun xwidget-webkit-show-named-element (xw element-name) | 240 | (defun xwidget-webkit-show-named-element (xw element-name) |
| 240 | "make named-element show. for instance an anchor." | 241 | "make named-element show. for instance an anchor." |
| 242 | (interactive (list (xwidget-webkit-current-session) (read-string "element name:"))) | ||
| 241 | ;;TODO | 243 | ;;TODO |
| 244 | ;; since an xwidget is an Emacs object, it is not trivial to do some things that are taken for granted in a normal browser. | ||
| 245 | ;; scrolling an anchor/named-element into view is one such thing. | ||
| 246 | ;; this function implements a proof-of-concept for this. | ||
| 247 | ;; problems remaining: | ||
| 248 | ;; - the selected window is scrolled but this is not always correct | ||
| 249 | ;; - this needs to be interfaced into browse-url somehow. the tricky part is that we need to do this in two steps: | ||
| 250 | ;; A: load the base url, wait for load signal to arrive B: navigate to the anchor when the base url is finished rendering | ||
| 251 | |||
| 242 | ;;this part figures out the Y coordinate of the element | 252 | ;;this part figures out the Y coordinate of the element |
| 243 | (let ((y | 253 | (let ((y |
| 244 | (string-to-number (xwidget-webkit-execute-script-rv xw (format "document.getElementsByName('%s')[0].getBoundingClientRect().top" element-name) 0)))) | 254 | (string-to-number (xwidget-webkit-execute-script-rv xw (format "document.getElementsByName('%s')[0].getBoundingClientRect().top" element-name) 0)))) |
| 245 | ;;now we need to tell emacs to scroll it into view. | 255 | ;;now we need to tell emacs to scroll the element into view. |
| 246 | ;;hmm. the "y" seems not to be in screen coords? | ||
| 247 | (message "scroll: %d" y) | 256 | (message "scroll: %d" y) |
| 248 | (set-window-vscroll (selected-window) y t)) | 257 | (set-window-vscroll (selected-window) y t)) |
| 249 | ) | 258 | ) |
| @@ -303,9 +312,14 @@ Argument H height." | |||
| 303 | ;;this is a wrapper for the title hack so its easy to remove should webkit someday support JS return values | 312 | ;;this is a wrapper for the title hack so its easy to remove should webkit someday support JS return values |
| 304 | ;;or we find some other way to access the DOM | 313 | ;;or we find some other way to access the DOM |
| 305 | 314 | ||
| 306 | (xwidget-webkit-execute-script xw (format "document.title='%s';" (if default default ""))) | 315 | ;;reset webkit title. fugly. |
| 307 | (xwidget-webkit-execute-script xw (format "document.title=%s;" script)) | 316 | (let* ( (emptytag "titlecantbewhitespaceohthehorror") |
| 308 | (xwidget-webkit-get-title xw)) | 317 | title) |
| 318 | (xwidget-webkit-execute-script xw (format "document.title=\"%s\";" (if default default emptytag))) | ||
| 319 | (xwidget-webkit-execute-script xw (format "document.title=%s;" script)) | ||
| 320 | (setq title (xwidget-webkit-get-title xw)) | ||
| 321 | (if (equal emptytag title) (setq title "")) | ||
| 322 | title)) | ||
| 309 | 323 | ||
| 310 | 324 | ||
| 311 | ;; use declare here? | 325 | ;; use declare here? |