all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: emacs-devel@gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>
Subject: [PATCH 12/15] Dynamically resize WebKit widget.
Date: Mon, 24 Oct 2016 18:40:58 +0200	[thread overview]
Message-ID: <20161024164101.26043-13-rekado@elephly.net> (raw)
In-Reply-To: <20161024164101.26043-1-rekado@elephly.net>

* lisp/xwidget.el (xwidget-webkit-auto-adjust-size,
xwidget-webkit-adjust-size-in-frame): New procedures.
(xwidget-webkit-new-session): Remove hint to resize widget with `a'.
(xwidget-webkit-adjust-size-dispatch): Resize current webkit widget.
(xwidget-webkit-adjust-size-to-window): Make non-interactive, add widget and window as arguments.
(xwidget-webkit-callback): Use xwidget-webkit-adjust-size-to-window.
---
 lisp/xwidget.el | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index e5b51ce..13e3fdf2 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -199,7 +199,7 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget."
                 (xwidget-log "webkit finished loading: '%s'" title)
                 ;;TODO - check the native/internal scroll
                 ;;(xwidget-adjust-size-to-content xwidget)
-                (xwidget-webkit-adjust-size-dispatch) ;;TODO xwidget arg
+                (xwidget-webkit-adjust-size-to-window xwidget)
                 (rename-buffer (format "*xwidget webkit: %s *" title))))
              (pop-to-buffer (current-buffer)))
             ((eq xwidget-event-type 'decide-policy)
@@ -411,18 +411,18 @@ For example, use this to display an anchor."
 (defun xwidget-webkit-adjust-size-dispatch ()
   "Adjust size according to mode."
   (interactive)
-  (xwidget-webkit-adjust-size-to-window)
+  (xwidget-webkit-adjust-size-to-window (xwidget-webkit-current-session))
   ;; The recenter is intended to correct a visual glitch.
   ;; It errors out if the buffer isn't visible, but then we don't get
   ;; the glitch, so silence errors.
   (ignore-errors
     (recenter-top-bottom)))
 
-(defun xwidget-webkit-adjust-size-to-window ()
-  "Adjust webkit to window."
-  (interactive)
-  (xwidget-resize (xwidget-webkit-current-session) (window-pixel-width)
-                  (window-pixel-height)))
+(defun xwidget-webkit-adjust-size-to-window (xwidget &optional window)
+  "Adjust the size of the webkit XWIDGET to fit the WINDOW."
+  (xwidget-resize xwidget
+                  (window-pixel-width window)
+                  (window-pixel-height window)))
 
 (defun xwidget-webkit-adjust-size (w h)
   "Manually set webkit size to width W, height H."
@@ -437,6 +437,21 @@ For example, use this to display an anchor."
                                  (car (window-inside-pixel-edges)))
                               1000))
 
+(defun xwidget-webkit-auto-adjust-size (window)
+  "Adjust the size of the webkit widget in the given WINDOW."
+  (with-current-buffer (window-buffer window)
+    (when (eq major-mode 'xwidget-webkit-mode)
+      (let ((xwidget (xwidget-webkit-current-session)))
+        (xwidget-webkit-adjust-size-to-window xwidget window)))))
+
+(defun xwidget-webkit-adjust-size-in-frame (frame)
+  "Dynamically adjust webkit widget for all windows of the FRAME."
+  (walk-windows 'xwidget-webkit-auto-adjust-size 'no-minibuf frame))
+
+(eval-after-load 'xwidget-webkit-mode
+  (add-to-list 'window-size-change-functions
+               'xwidget-webkit-adjust-size-in-frame))
+
 (defun xwidget-webkit-new-session (url)
   "Create a new webkit session buffer with URL."
   (let*
@@ -444,7 +459,9 @@ For example, use this to display an anchor."
        xw)
     (setq xwidget-webkit-last-session-buffer (switch-to-buffer
                                               (get-buffer-create bufname)))
-    (insert " 'a' adjusts the xwidget size.")
+    ;; The xwidget id is stored in a text property, so we need to have
+    ;; at least character in this buffer.
+    (insert " ")
     (setq xw (xwidget-insert 1 'webkit bufname
                              (window-pixel-width)
                              (window-pixel-height)))
-- 
2.10.1





  parent reply	other threads:[~2016-10-24 16:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 16:40 [PATCH v2 00/15] xwidget webkit improvements Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 01/15] xwidget: Use WebKit2 API Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 02/15] xwidget: Pass JavaScript return value to optional callback procedure Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 03/15] Remove scrolled window container around WebKit widget Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 04/15] xwidget: Do not use `xwidget-execute-script-rv' to insert string Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 05/15] xwidget: Get title via asynchronous JavaScript Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 06/15] xwidget: Simplify functions to scroll to elements Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 07/15] xwidget: Add function to find element by CSS selector Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 08/15] xwidget: Get selection with asynchronous JavaScript Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 09/15] xwidget: Get URL asynchronously Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 10/15] xwidget: Remove title hack Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 11/15] Let initial WebKit view fill window Ricardo Wurmus
2016-10-24 16:40 ` Ricardo Wurmus [this message]
2016-10-24 16:40 ` [PATCH 13/15] Implement zoom for WebKit widget Ricardo Wurmus
2016-10-24 16:41 ` [PATCH 14/15] xwidget: Bind "beginning-of-buffer" and "end-of-buffer" Ricardo Wurmus
2016-10-24 16:41 ` [PATCH 15/15] xwidget: Map "previous-line" and "next-line" to scroll Ricardo Wurmus
2016-10-25 15:30 ` [PATCH v2 00/15] xwidget webkit improvements Paul Eggert
2016-10-26  5:12   ` Ricardo Wurmus
2016-10-26  6:08     ` Paul Eggert
2016-10-26  9:18       ` joakim
2016-10-26  9:19       ` joakim
2016-10-26  8:08     ` Live System User
2016-10-26  8:14     ` Live System User

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161024164101.26043-13-rekado@elephly.net \
    --to=rekado@elephly.net \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.