aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Verona2011-08-08 10:41:33 +0200
committerJoakim Verona2011-08-08 10:41:33 +0200
commitc5e10d038d040a7bb0eedb64469705ff84addd09 (patch)
treefe3213410b1dcbe6401e96b025d74aa42efbd034
parent1cab149286abf2ec366c764e13c5036a3c6f4204 (diff)
downloademacs-c5e10d038d040a7bb0eedb64469705ff84addd09.tar.gz
emacs-c5e10d038d040a7bb0eedb64469705ff84addd09.zip
cleanups
-rw-r--r--README.xwidget20
-rw-r--r--lisp/xwidget.el62
-rw-r--r--src/xwidget.c59
3 files changed, 99 insertions, 42 deletions
diff --git a/README.xwidget b/README.xwidget
index 710c10ed7f3..3673209664a 100644
--- a/README.xwidget
+++ b/README.xwidget
@@ -895,11 +895,27 @@ because one might need tell set a title and sizes and things when it loads.
895**** TODO event bug 895**** TODO event bug
896Debugger entered--Lisp error: (error "Two bases given in one event") 896Debugger entered--Lisp error: (error "Two bases given in one event")
897 897
898for some reason hapens sometimes with xwidget events. 898hapens sometimes with xwidget events. appears to be when the
899originating xwidget is offscreen so that the event doesn't get caught
900by the correct emacs event map.
899 901
900maybe I need to set the originating window? 902maybe I need to set the originating window in the event structure.
901 event.frame_or_window = Qnil; //frame; //how to get the frame here? //TODO i store it in the xwidget now 903 event.frame_or_window = Qnil; //frame; //how to get the frame here? //TODO i store it in the xwidget now
902 904
905since its an offscreen xwidget the buffer local keymap isnt the right
906place for the handler. some global map should be used.
907
908onscreen widgets don't have the same issue.
909
910anyway, seems it'll turn out like this:
911- xwidget-osr stores a callback and user data
912- the event is an implementation detail only and get caught in the
913 topmost event map
914- the event map calls the callback in the xw with the right args.
915
916we need the event handler at some level because we can't call lisp
917asynchronously.
918
903*** TODO console messages 919*** TODO console messages
904http://webkitgtk.org/reference/webkitgtk-webkitwebview.html#WebKitWebView-console-message 920http://webkitgtk.org/reference/webkitgtk-webkitwebview.html#WebKitWebView-console-message
905http://getfirebug.com/wiki/index.php/Console_API#console.count.28.5Btitle.5D.29 921http://getfirebug.com/wiki/index.php/Console_API#console.count.28.5Btitle.5D.29
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index df6e77b708b..97dbe11fed9 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -1,15 +1,20 @@
1;; xwidget.el - api functions for xwidgets 1;;; xwidget.el --- api functions for xwidgets
2;; see xwidget.c for more api functions 2;; see xwidget.c for more api functions
3 3
4
5;;; Commentary:
6;;
7
4(require 'xwidget-internal) 8(require 'xwidget-internal)
5 9
6;;TODO model after make-text-button instead! 10;;TODO model after make-text-button instead!
11;;; Code:
12
7(defun xwidget-insert (pos type title width height) 13(defun xwidget-insert (pos type title width height)
8 "Insert an xwidget at POS, given ID, TYPE, TITLE WIDTH and HEIGHT. 14 "Insert an xwidget at POS, given ID, TYPE, TITLE WIDTH and HEIGHT.
9Return ID 15Return ID
10 16
11see xwidget.c for types suitable for TYPE. 17see xwidget.c for types suitable for TYPE."
12"
13 (goto-char pos) 18 (goto-char pos)
14 (let ((id (make-xwidget (point) (point) type title width height nil))) 19 (let ((id (make-xwidget (point) (point) type title width height nil)))
15 (put-text-property (point) 20 (put-text-property (point)
@@ -19,7 +24,8 @@ see xwidget.c for types suitable for TYPE.
19 24
20 25
21(defun xwidget-at (pos) 26(defun xwidget-at (pos)
22 ;;this function is a bit tedious because the C layer isnt well protected yet and 27 "Return xwidget at POS."
28 ;;TODO this function is a bit tedious because the C layer isnt well protected yet and
23 ;;xwidgetp aparently doesnt work yet 29 ;;xwidgetp aparently doesnt work yet
24 (let* ((disp (get-text-property pos 'display)) 30 (let* ((disp (get-text-property pos 'display))
25 (xw (car (cdr (cdr disp))))) 31 (xw (car (cdr (cdr disp)))))
@@ -31,7 +37,7 @@ see xwidget.c for types suitable for TYPE.
31 37
32 38
33(defun xwidget-socket-handler () 39(defun xwidget-socket-handler ()
34 "creates plug for socket. TODO" 40 "Create plug for socket. TODO."
35 (interactive) 41 (interactive)
36 (message "socket handler xwidget %S" last-input-event) 42 (message "socket handler xwidget %S" last-input-event)
37 (let* 43 (let*
@@ -75,16 +81,19 @@ defaults to the string looking like a url around the cursor position."
75 81
76;;shims for adapting image mode code to the webkit browser window 82;;shims for adapting image mode code to the webkit browser window
77(defun xwidget-image-display-size (spec &optional pixels frame) 83(defun xwidget-image-display-size (spec &optional pixels frame)
84 "Image code adaptor. SPEC PIXELS FRAME like the corresponding `image-mode' fn."
78 (let ((xwi (xwidget-info (xwidget-at 1)))) 85 (let ((xwi (xwidget-info (xwidget-at 1))))
79 (cons (aref xwi 2) 86 (cons (aref xwi 2)
80 (aref xwi 3)))) 87 (aref xwi 3))))
81 88
82(defmacro xwidget-image-mode-navigation-adaptor (fn) 89(defmacro xwidget-image-mode-navigation-adaptor (fn)
90 "Image code adaptor. `image-mode' FN is called."
83 `(lambda () (interactive) 91 `(lambda () (interactive)
84 (flet ((image-display-size (spec) (xwidget-image-display-size spec))) 92 (flet ((image-display-size (spec) (xwidget-image-display-size spec)))
85 (funcall ,fn )))) 93 (funcall ,fn ))))
86 94
87(defmacro xwidget-image-mode-navigation-adaptor-p (fn) 95(defmacro xwidget-image-mode-navigation-adaptor-p (fn)
96 "Image code adaptor. `image-mode' FN is called with interactive arg."
88 `(lambda (n) (interactive "p") 97 `(lambda (n) (interactive "p")
89 (flet ((image-display-size (spec) (xwidget-image-display-size spec))) 98 (flet ((image-display-size (spec) (xwidget-image-display-size spec)))
90 (funcall ,fn n)))) 99 (funcall ,fn n))))
@@ -98,9 +107,9 @@ defaults to the string looking like a url around the cursor position."
98 (define-key map "a" 'xwidget-webkit-adjust-size-to-content) 107 (define-key map "a" 'xwidget-webkit-adjust-size-to-content)
99 (define-key map "b" 'xwidget-webkit-back ) 108 (define-key map "b" 'xwidget-webkit-back )
100 (define-key map "r" 'xwidget-webkit-reload ) 109 (define-key map "r" 'xwidget-webkit-reload )
101 (define-key map "t" (lambda () (interactive) (message "o")) ) 110 (define-key map "t" (lambda () (interactive) (message "o")) )
102 (define-key map "\C-m" 'xwidget-webkit-insert-string) 111 (define-key map "\C-m" 'xwidget-webkit-insert-string)
103 (define-key map [xwidget-event] 'xwidget-webkit-event-handler) 112 (define-key map [xwidget-event] 'xwidget-webkit-event-handler);;TODO needs to go into a higher level handler
104 113
105 ;;similar to image mode bindings 114 ;;similar to image mode bindings
106 ;;TODO theres something wrong with the macro 115 ;;TODO theres something wrong with the macro
@@ -134,6 +143,7 @@ defaults to the string looking like a url around the cursor position."
134 143
135 144
136(defun xwidget-webkit-event-handler () 145(defun xwidget-webkit-event-handler ()
146 "Receive webkit event."
137 (interactive) 147 (interactive)
138 (message "stuff happened to webkit xwidget %S" last-input-event) 148 (message "stuff happened to webkit xwidget %S" last-input-event)
139 (let* 149 (let*
@@ -155,7 +165,7 @@ defaults to the string looking like a url around the cursor position."
155(defvar xwidget-webkit-last-session-buffer nil) 165(defvar xwidget-webkit-last-session-buffer nil)
156 166
157(defun xwidget-webkit-last-session () 167(defun xwidget-webkit-last-session ()
158 "last active webkit, or a new one" 168 "Last active webkit, or a new one."
159 (if (buffer-live-p xwidget-webkit-last-session-buffer) 169 (if (buffer-live-p xwidget-webkit-last-session-buffer)
160 (save-excursion 170 (save-excursion
161 (set-buffer xwidget-webkit-last-session-buffer) 171 (set-buffer xwidget-webkit-last-session-buffer)
@@ -163,34 +173,44 @@ defaults to the string looking like a url around the cursor position."
163 nil)) 173 nil))
164 174
165(defun xwidget-webkit-current-session () 175(defun xwidget-webkit-current-session ()
166 "either the webkit in the current buffer, or the last one used" 176 "Either the webkit in the current buffer, or the last one used, which might be nil."
167 (if (xwidget-at 1) 177 (if (xwidget-at 1)
168 (xwidget-at 1) 178 (xwidget-at 1)
169 (xwidget-webkit-last-session))) 179 (xwidget-webkit-last-session)))
170 180
171(defun xwidget-adjust-size-to-content (xw) 181(defun xwidget-adjust-size-to-content (xw)
172 ;;xwidgets doesnt support widgets that have thoir own opinions about size well yet 182 "Resize XW to content."
173 ;;this reads the size and sets it back 183 ;;xwidgets doesnt support widgets that have their own opinions about size well yet
184 ;;this reads the desired size and resizes the emacs allocated area accordingly
174 (let ((size (xwidget-size-request xw))) 185 (let ((size (xwidget-size-request xw)))
175 (xwidget-resize xw (car size) (cadr size)))) 186 (xwidget-resize xw (car size) (cadr size))))
176 187
177 188
178(defun xwidget-webkit-insert-string (xw str) 189(defun xwidget-webkit-insert-string (xw str)
190 "Insert string in the active field in the webkit.
191Argument XW webkit.
192Argument STR string."
193 ;;TODO read out the string in the field first and provide for edit
179 (interactive (list (xwidget-webkit-current-session) 194 (interactive (list (xwidget-webkit-current-session)
180 (read-string "string:"))) 195 (read-string "string:")))
181 (xwidget-webkit-execute-script xw (format "document.activeElement.value='%s'" str))) 196 (xwidget-webkit-execute-script xw (format "document.activeElement.value='%s'" str)))
182 197
183(defun xwidget-webkit-adjust-size-to-content () 198(defun xwidget-webkit-adjust-size-to-content ()
199 "Adjust webkit to content size."
184 (interactive) 200 (interactive)
185 ( xwidget-adjust-size-to-content ( xwidget-webkit-current-session))) 201 ( xwidget-adjust-size-to-content ( xwidget-webkit-current-session)))
186 202
187(defun xwidget-webkit-adjust-size (w h) 203(defun xwidget-webkit-adjust-size (w h)
204 "Manualy set webkit size.
205Argument W width.
206Argument H height."
207 ;;TODO shouldnt be tied to the webkit xwidget
188 (interactive "nWidth:\nnHeight:\n") 208 (interactive "nWidth:\nnHeight:\n")
189 ( xwidget-resize ( xwidget-webkit-current-session) w h)) 209 ( xwidget-resize ( xwidget-webkit-current-session) w h))
190 210
191 211
192(defun xwidget-webkit-new-session (url) 212(defun xwidget-webkit-new-session (url)
193 213"Create a new webkit session buffer with URL."
194 (let* 214 (let*
195 ((bufname (generate-new-buffer-name "*xwidget-webkit*")) 215 ((bufname (generate-new-buffer-name "*xwidget-webkit*"))
196 ) 216 )
@@ -202,23 +222,27 @@ defaults to the string looking like a url around the cursor position."
202 222
203 223
204(defun xwidget-webkit-goto-url (url) 224(defun xwidget-webkit-goto-url (url)
225 "Goto URL."
205 (if ( xwidget-webkit-current-session) 226 (if ( xwidget-webkit-current-session)
206 (progn 227 (progn
207 (xwidget-webkit-goto-uri ( xwidget-webkit-current-session) url)) 228 (xwidget-webkit-goto-uri ( xwidget-webkit-current-session) url))
208 ( xwidget-webkit-new-session url))) 229 ( xwidget-webkit-new-session url)))
209 230
210(defun xwidget-webkit-back () 231(defun xwidget-webkit-back ()
232 "Back in history."
211 (interactive) 233 (interactive)
212 (xwidget-webkit-execute-script ( xwidget-webkit-current-session) "history.go(-1);")) 234 (xwidget-webkit-execute-script ( xwidget-webkit-current-session) "history.go(-1);"))
213 235
214(defun xwidget-webkit-reload () 236(defun xwidget-webkit-reload ()
237 "Reload current url."
215 (interactive) 238 (interactive)
216 (xwidget-webkit-execute-script ( xwidget-webkit-current-session) "history.go(0);")) 239 (xwidget-webkit-execute-script ( xwidget-webkit-current-session) "history.go(0);"))
217 240
218(defun xwidget-current-url () 241(defun xwidget-current-url ()
219 "get the webkit url" 242 "Get the webkit url."
220 ;;notice the fugly "title" hack. it is needed because the webkit api doesnt support returning values. 243 ;;notice the fugly "title" hack. it is needed because the webkit api doesnt support returning values.
221 ;;TODO make a wrapper for the title hack so its easy to remove should webkit someday support JS return values 244 ;;TODO make a wrapper for the title hack so its easy to remove should webkit someday support JS return values
245 ;;or we find some other way to access the DOM
222 (xwidget-webkit-execute-script (xwidget-webkit-current-session) "document.title=document.URL;") 246 (xwidget-webkit-execute-script (xwidget-webkit-current-session) "document.title=document.URL;")
223 (xwidget-webkit-get-title (xwidget-webkit-current-session))) 247 (xwidget-webkit-get-title (xwidget-webkit-current-session)))
224 248
@@ -230,6 +254,7 @@ defaults to the string looking like a url around the cursor position."
230 254
231;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 255;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
232(defun xwidget-cleanup () 256(defun xwidget-cleanup ()
257 "Delete zombie xwidgets."
233 ;;its still pretty easy to trigger bugs with xwidgets. 258 ;;its still pretty easy to trigger bugs with xwidgets.
234 ;;this function tries to implement a workaround 259 ;;this function tries to implement a workaround
235 (interactive) 260 (interactive)
@@ -240,11 +265,16 @@ defaults to the string looking like a url around the cursor position."
240 265
241 266
242;;this is a workaround because I cant find the right place to put it in C 267;;this is a workaround because I cant find the right place to put it in C
268;;seems to work well in practice though
243(add-hook 'window-configuration-change-hook 'xwidget-cleanup) 269(add-hook 'window-configuration-change-hook 'xwidget-cleanup)
244 270
245;;killflash is sadly not reliable yet. 271;;killflash is sadly not reliable yet.
246(defvar xwidget-webkit-kill-flash-oneshot t) 272(defvar xwidget-webkit-kill-flash-oneshot t)
247(defun xwidget-webkit-kill-flash () 273(defun xwidget-webkit-kill-flash ()
274 "Disable the flash plugin in webkit.
275This is needed because Flash is non-free and doesnt work reliably
276on 64 bit systems and offscreen rendering. Sadly not reliable
277yet, so deinstall Flash instead for now."
248 ;;you can only call this once or webkit crashes and takes emacs with it. odd. 278 ;;you can only call this once or webkit crashes and takes emacs with it. odd.
249 (unless xwidget-webkit-kill-flash-oneshot 279 (unless xwidget-webkit-kill-flash-oneshot
250 (xwidget-disable-plugin-for-mime "application/x-shockwave-flash") 280 (xwidget-disable-plugin-for-mime "application/x-shockwave-flash")
@@ -253,3 +283,7 @@ defaults to the string looking like a url around the cursor position."
253(xwidget-webkit-kill-flash) 283(xwidget-webkit-kill-flash)
254 284
255(provide 'xwidget) 285(provide 'xwidget)
286
287(provide 'xwidget)
288
289;;; xwidget.el ends here
diff --git a/src/xwidget.c b/src/xwidget.c
index 0a5ce3c6f0c..a25dd170731 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -701,6 +701,34 @@ DEFUN ("xwidget-webkit-get-title", Fxwidget_webkit_get_title, Sxwidget_webkit_g
701 return make_string_from_bytes(str, wcslen((const wchar_t *)str), strlen(str)); 701 return make_string_from_bytes(str, wcslen((const wchar_t *)str), strlen(str));
702} 702}
703 703
704//TODO missnamed
705DEFUN("xwidget-disable-plugin-for-mime", Fxwidget_disable_plugin_for_mime , Sxwidget_disable_plugin_for_mime, 1,1,0, doc: /* */)
706 (Lisp_Object mime)
707{
708 WebKitWebPlugin *wp = webkit_web_plugin_database_get_plugin_for_mimetype
709 (webkit_get_web_plugin_database(), SDATA(mime));
710 if(wp == NULL) return Qnil;
711 if(webkit_web_plugin_get_enabled (wp)){
712 webkit_web_plugin_set_enabled (wp, FALSE);
713 return Qt;
714 }
715 return Qnil;
716}
717
718
719//attempting a workaround for a webkit offscreen bug
720//TODO verify its still needed
721void gtk_window_get_position (GtkWindow *window,
722 gint *root_x,
723 gint *root_y){
724 printf("my getsize\n");
725 *root_x = 0;
726 *root_y = 0;
727}
728
729
730
731
704#endif 732#endif
705 733
706 734
@@ -852,18 +880,6 @@ DEFUN("xwidget-delete-zombies", Fxwidget_delete_zombies , Sxwidget_delete_zombie
852 } 880 }
853} 881}
854 882
855DEFUN("xwidget-disable-plugin-for-mime", Fxwidget_disable_plugin_for_mime , Sxwidget_disable_plugin_for_mime, 1,1,0, doc: /* */)
856 (Lisp_Object mime)
857{
858 WebKitWebPlugin *wp = webkit_web_plugin_database_get_plugin_for_mimetype
859 (webkit_get_web_plugin_database(), SDATA(mime));
860 if(wp == NULL) return Qnil;
861 if(webkit_web_plugin_get_enabled (wp)){
862 webkit_web_plugin_set_enabled (wp, FALSE);
863 return Qt;
864 }
865 return Qnil;
866}
867 883
868void 884void
869syms_of_xwidget (void) 885syms_of_xwidget (void)
@@ -876,10 +892,13 @@ syms_of_xwidget (void)
876 defsubr (&Sxwidget_view_info); 892 defsubr (&Sxwidget_view_info);
877 defsubr (&Sxwidget_resize); 893 defsubr (&Sxwidget_resize);
878 894
879 895#ifdef HAVE_WEBKIT_OSR
880 defsubr (&Sxwidget_webkit_goto_uri); 896 defsubr (&Sxwidget_webkit_goto_uri);
881 defsubr (&Sxwidget_webkit_execute_script); 897 defsubr (&Sxwidget_webkit_execute_script);
882 defsubr (&Sxwidget_webkit_get_title); 898 defsubr (&Sxwidget_webkit_get_title);
899 DEFSYM (Qwebkit_osr ,"webkit-osr");
900#endif
901
883 defsubr (&Sxwidget_size_request ); 902 defsubr (&Sxwidget_size_request );
884 defsubr (&Sxwidget_delete_zombies); 903 defsubr (&Sxwidget_delete_zombies);
885 defsubr (&Sxwidget_disable_plugin_for_mime); 904 defsubr (&Sxwidget_disable_plugin_for_mime);
@@ -896,7 +915,7 @@ syms_of_xwidget (void)
896 DEFSYM (Qsocket, "socket"); 915 DEFSYM (Qsocket, "socket");
897 DEFSYM (Qsocket_osr, "socket-osr"); 916 DEFSYM (Qsocket_osr, "socket-osr");
898 DEFSYM (Qcairo, "cairo"); 917 DEFSYM (Qcairo, "cairo");
899 DEFSYM (Qwebkit_osr ,"webkit-osr"); 918
900 DEFSYM (QCplist, ":plist"); 919 DEFSYM (QCplist, ":plist");
901 920
902 DEFVAR_LISP ("xwidget-alist", Vxwidget_alist, doc: /*xwidgets list*/); 921 DEFVAR_LISP ("xwidget-alist", Vxwidget_alist, doc: /*xwidgets list*/);
@@ -1000,18 +1019,6 @@ struct xwidget_view* xwidget_view_lookup(struct xwidget* xw, struct window *
1000 } 1019 }
1001} 1020}
1002 1021
1003//attempting a workaround for a webkit offscreen bug
1004//TODO verify its still needed
1005void gtk_window_get_position (GtkWindow *window,
1006 gint *root_x,
1007 gint *root_y){
1008 printf("my getsize\n");
1009 *root_x = 0;
1010 *root_y = 0;
1011}
1012
1013
1014
1015struct xwidget* 1022struct xwidget*
1016lookup_xwidget (Lisp_Object spec) 1023lookup_xwidget (Lisp_Object spec)
1017{ 1024{