From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.emacs.devel Subject: [PATCH 12/15] Dynamically resize WebKit widget. Date: Mon, 24 Oct 2016 18:40:58 +0200 Message-ID: <20161024164101.26043-13-rekado@elephly.net> References: <20161024164101.26043-1-rekado@elephly.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1477327670 24395 195.159.176.226 (24 Oct 2016 16:47:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Oct 2016 16:47:50 +0000 (UTC) Cc: Ricardo Wurmus To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 24 18:47:46 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byiPZ-0005vb-RA for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 18:47:45 +0200 Original-Received: from localhost ([::1]:48166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiPc-0003WV-3V for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 12:47:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiMA-0000PI-BN for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:44:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byiM6-0003SG-DL for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:44:14 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21348) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1byiM6-0003Ro-4I for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:44:10 -0400 Original-Received: from localhost (89.204.138.233 [89.204.138.233]) by mx.zohomail.com with SMTPS id 1477327447919132.71032205959193; Mon, 24 Oct 2016 09:44:07 -0700 (PDT) X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024164101.26043-1-rekado@elephly.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 74.201.84.163 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208714 Archived-At: * 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