]> code.delx.au - gnu-emacs/commitdiff
some adaptor code that makes webkit mode work a bit more like image mode
authorJoakim Verona <joakim@verona.se>
Mon, 1 Aug 2011 22:32:00 +0000 (00:32 +0200)
committerJoakim Verona <joakim@verona.se>
Mon, 1 Aug 2011 22:32:00 +0000 (00:32 +0200)
README.xwidget
lisp/xwidget.el

index 11406a998940b75c0a3d706f70ae4e886d66506a..f457b5cd10e0bd99cabce7b2832fd9a69e3811ae 100644 (file)
@@ -887,8 +887,16 @@ easy.
 
 ** webkit related
 *** TODO webkit support webkit signals
-*** TODO particularily document-load-finished
+
+**** DONE particularily document-load-finished
+     CLOSED: [2011-08-01 Mon 22:34]
 http://webkitgtk.org/reference/webkitgtk-webkitwebview.html#WebKitWebView-document-load-finished
+because one might need tell set a title and sizes and things when it loads.
+**** TODO event bug
+Debugger entered--Lisp error: (error "Two bases given in one event")
+
+for some reason hapens sometimes with xwidget events.
+
 *** TODO console messages
 http://webkitgtk.org/reference/webkitgtk-webkitwebview.html#WebKitWebView-console-message
 http://getfirebug.com/wiki/index.php/Console_API#console.count.28.5Btitle.5D.29
@@ -898,8 +906,7 @@ because maybe we can make a simple JS REPL that way.
 prints hello to stdout but theres no way to catch stdout from webkit I
 think other than receiving the signal.
 
-*** DONE webkit flashkiller by default
-   CLOSED: [2011-07-19 Tue 14:27]
+*** TODO webkit flashkiller by default
 while its possible to support plugins in the webkit xwidget, flash has
 issues on 64 bit, and slows down emacs to a halt with off screen
 rendering, and of course is not free software. its in the way for real
@@ -912,6 +919,9 @@ http://stackoverflow.com/questions/4885513/prevent-flash-in-cocoa-webview
 simply use this api:
 http://webkitgtk.org/reference/WebKitWebPluginDatabase.html
 
+theres an implementation now but it's not robust enough webkit often
+crashes taking emacs with it.
+
 *** TODO webkit downloads
 when clicking a download link in Webkit Emacs should take over and handle it
 from there. Probably need signals. There are Emacs libraries to
@@ -926,7 +936,8 @@ open a new window or something, which wont work.
 have a look at how docview solves it
 webkit_web_view_search_text ()
 *** TODO webkit relative references doesn't work
-probably because we handle scrolling in a non-standard way
+probably because we handle scrolling in a non-standard way. It does
+work sort of when theres a html frameset and webkit scrols by itself.
 *** TODO webkit width adjustment handling issue
 since there are so many levels of clipping and whatnot in xwidgets
 sizing issues are difficult.
@@ -946,16 +957,33 @@ to see the problem surface to http://www.slashdot.org
 - xwidget-webkit-adjust-size
 - xwidget-webkit-adjust-size-to-content
 
-and then try resizing Epiphany.
+and then compare by resizing in Epiphany, which is also webkit based.
 
 *** TODO xwidget webkit allow loading from string from emacs
-*** TODO xwidget-webkit-last-session
+*** DONE xwidget-webkit-last-session
+    CLOSED: [2011-08-01 Mon 22:38]
 was rather hurried. end result is that the lisp layer only really
 allows for one webkit session.
 *** TODO C-X b in other buffer from webkit
 bafflingly resets the webkit view to the top. Maybe the window
 reconfiguration hook code? further mystification is added because it
 only seems to happen with ido mode enabled.
+
+in comparison with image-mode which does the right thing, I discovered
+that image-mode has special code to handle scrolling. the browser mode
+and image mode has some similarities.
+
+** TODO xwidget image display  spec compatibility
+some history: the first version of the xwidget display spec was
+the same as an image spec. This turned out not to be fantastic because
+an xwidget is both like a process and like an image. it has a separate
+existence from display. So now the xwidget display spec is just a
+pointer to a xwidget. But then some useful functionality in Emacs
+can't be reused for xwidget, in particular image-mode.
+
+Maybe a new image type could be added that was a wraper on an
+xwidget. Then image mode could be reused for webkit mode. 
+
 ** socket related
 *** TODO some flickering during redisplay of sockets
 with gtk3 an size allocation workaround is used.
@@ -987,9 +1015,10 @@ fine-tuning to reduce flicker.
 
 
 
-** TODO xwidgets doesn't work during bootstrap all of a sudden
+** DONE xwidgets doesn't work during bootstrap all of a sudden
+   CLOSED: [2011-08-01 Mon 22:33]
 might be some annoying local issues with my install because it is not
-reliably reproducible.
+reliably reproducible. (went away during merges)
 
 ** TODO low impact xwidget based image viewer
 for instance to render SVG using webkit, or some other canvas.
@@ -998,6 +1027,7 @@ that way it would be possible to merge to trunk in stages.
 so, webkit could be used to display the SVG. the display spec for
 images would be used. multiple webkits would be used rather than
 offscreen rendering, so it would be GTK2 compatible. 
+** 
 * old notes from x_draw_xwidget_glyph_string
 
     BUG it seems this method for some reason is called with bad s->x and s->y sometimes.
index aef04cfb5423abef8409c0122bbe037731db99c7..5ca8fb58d690262f41f2d6d4ab223411fa65f2a8 100644 (file)
@@ -56,6 +56,7 @@ see xwidget.c for types suitable for TYPE.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; webkit support
 (require 'browse-url)
+(require 'image-mode)
 ;;;###autoload
 (defun xwidget-webkit-browse-url (url &optional new-session)
   "Ask xwidget-webkit to browse URL.
@@ -81,23 +82,62 @@ defaults to the string looking like a url around the cursor position."
     (define-key map "r" 'xwidget-webkit-reload )    
     (define-key map "\C-m" 'xwidget-webkit-insert-string)
     (define-key map [xwidget-event] 'xwidget-webkit-event-handler)
+
+    ;;similar to image mode bindings
+    (define-key map (kbd "SPC")       'image-scroll-up)
+    (define-key map (kbd "DEL")       'image-scroll-down)
+    
+    (define-key map [remap forward-char]       (xwidget-image-mode-navigation-adaptor  'image-forward-hscroll))
+    (define-key map [remap backward-char]       (xwidget-image-mode-navigation-adaptor  'image-backward-hscroll))
+    (define-key map [remap right-char]       (xwidget-image-mode-navigation-adaptor  'image-forward-hscroll))
+    (define-key map [remap left-char]       (xwidget-image-mode-navigation-adaptor  'image-backward-hscroll))
+    (define-key map [remap previous-line]       (xwidget-image-mode-navigation-adaptor  'image-previous-line))
+    (define-key map [remap next-line]       (xwidget-image-mode-navigation-adaptor  'image-next-line))
+    (define-key map [remap scroll-up]          (xwidget-image-mode-navigation-adaptor 'image-scroll-up))
+    (define-key map [remap scroll-up-command]  (xwidget-image-mode-navigation-adaptor 'image-scroll-up))
+    
+    (define-key map [remap scroll-down]       (xwidget-image-mode-navigation-adaptor  'image-scroll-down))
+
+    (define-key map [remap scroll-down-command]       (xwidget-image-mode-navigation-adaptor  'image-scroll-down))
+    (define-key map [remap move-beginning-of-line]       (xwidget-image-mode-navigation-adaptor  'image-bol))
+    (define-key map [remap move-end-of-line]       (xwidget-image-mode-navigation-adaptor  'image-eol))
+    (define-key map [remap beginning-of-buffer]       (xwidget-image-mode-navigation-adaptor  'image-bob))
+    (define-key map [remap end-of-buffer]       (xwidget-image-mode-navigation-adaptor  'image-eob))
+
+    
     map)
   
   "Keymap for `xwidget-webkit-mode'.")
 
+(defun xwidget-image-display-size  (spec &optional pixels frame)
+  (let ((xwi (xwidget-info  (xwidget-at 1))))
+    (cons (aref xwi 2)
+          (aref xwi 3))))
+
+(defmacro xwidget-image-mode-navigation-adaptor (fn)
+  `(lambda () (interactive)
+     (flet ((image-display-size (spec &optional pixels frame) (xwidget-image-display-size spec)))
+       (funcall ,fn))))
+  )
+
 (defun xwidget-webkit-event-handler ()
   (interactive)
   (message "stuff happened to webkit xwidget %S" last-input-event)
   (let*
       ((xwidget-event-type (nth 2 last-input-event))
        (xwidget (nth 1 last-input-event)))
-    (cond ( (eq xwidget-event-type 'document-load-finished)
-            (message "webkit loaded %s" xwidget))
+    (cond ((eq xwidget-event-type 'document-load-finished)
+           (message "webkit loaded %s" xwidget)
+           (xwidget-webkit-adjust-size-to-content))
           )))
 
 (define-derived-mode xwidget-webkit-mode
   special-mode "xwidget-webkit" "xwidget webkit view mode"
-  (setq buffer-read-only t))
+  (setq buffer-read-only t)
+  ;; Keep track of [vh]scroll when switching buffers
+  (image-mode-setup-winprops)
+
+  )
 
 (defvar xwidget-webkit-last-session-buffer nil)
 
@@ -189,6 +229,7 @@ defaults to the string looking like a url around the cursor position."
 ;;this is a workaround because I cant find the right place to put it in C
 (add-hook 'window-configuration-change-hook 'xwidget-cleanup)
 
+;;killflash is sadly not reliable yet. 
 (defvar xwidget-webkit-kill-flash-oneshot t)
 (defun xwidget-webkit-kill-flash ()
   ;;you can only call this once or webkit crashes and takes emacs with it. odd.