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 03/15] Remove scrolled window container around WebKit widget Date: Mon, 24 Oct 2016 18:40:49 +0200 Message-ID: <20161024164101.26043-4-rekado@elephly.net> References: <20161024164101.26043-1-rekado@elephly.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1477327383 1483 195.159.176.226 (24 Oct 2016 16:43:03 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Oct 2016 16:43:03 +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:42:59 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 1byiKm-0006wK-1Q for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 18:42:48 +0200 Original-Received: from localhost ([::1]:48133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiKo-0007Kx-BB for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 12:42:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiKT-00079M-Gb for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byiKO-0002Kx-Cq for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:29 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21433) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1byiKO-0002K6-4c for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:42:24 -0400 Original-Received: from localhost (89.204.138.233 [89.204.138.233]) by mx.zohomail.com with SMTPS id 147732733924423.45549841705042; Mon, 24 Oct 2016 09:42:19 -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:208708 Archived-At: The WebKit widget can scroll on its own and does not need to wrapped with a scrolled window container. * src/xwidget.h: Remove struct member widgetscrolledwindow_osr. * src/xwidget.c: Remove widgetscrolledwindow_osr. (xwidget-set-adjustment): Remove. (xwidget-resize): Resize Webkit widget last. * lisp/xwidget.el (xwidget-set-adjustment): Remove. (xwidget-webkit-scroll-up, xwidget-webkit-scroll-down, xwidget-webkit-scroll-forward, xwidget-webkit-scroll-backward): Implement scrolling via JavaScript. --- lisp/xwidget.el | 18 ++++++++++------ src/xwidget.c | 64 ++++----------------------------------------------------- src/xwidget.h | 3 --- 3 files changed, 16 insertions(+), 69 deletions(-) diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 69b1002..d2b9a09 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -36,8 +36,6 @@ (declare-function make-xwidget "xwidget.c" (type title width height arguments &optional buffer)) -(declare-function xwidget-set-adjustment "xwidget.c" - (xwidget axis relative value)) (declare-function xwidget-buffer "xwidget.c" (xwidget)) (declare-function xwidget-webkit-get-title "xwidget.c" (xwidget)) (declare-function xwidget-size-request "xwidget.c" (xwidget)) @@ -137,22 +135,30 @@ Interactively, URL defaults to the string looking like a url around point." (defun xwidget-webkit-scroll-up () "Scroll webkit up." (interactive) - (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t 50)) + (xwidget-webkit-execute-script + (xwidget-webkit-current-session) + "window.scrollBy(0, 50);")) (defun xwidget-webkit-scroll-down () "Scroll webkit down." (interactive) - (xwidget-set-adjustment (xwidget-webkit-last-session) 'vertical t -50)) + (xwidget-webkit-execute-script + (xwidget-webkit-current-session) + "window.scrollBy(0, -50);")) (defun xwidget-webkit-scroll-forward () "Scroll webkit forwards." (interactive) - (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t 50)) + (xwidget-webkit-execute-script + (xwidget-webkit-current-session) + "window.scrollBy(50, 0);")) (defun xwidget-webkit-scroll-backward () "Scroll webkit backwards." (interactive) - (xwidget-set-adjustment (xwidget-webkit-last-session) 'horizontal t -50)) + (xwidget-webkit-execute-script + (xwidget-webkit-current-session) + "window.scrollBy(-50, 0);")) ;; The xwidget event needs to go into a higher level handler diff --git a/src/xwidget.c b/src/xwidget.c index 4f53b93..8552810 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -103,25 +103,9 @@ Returns the newly constructed xwidget, or nil if construction fails. */) gtk_window_resize (GTK_WINDOW (xw->widgetwindow_osr), xw->width, xw->height); - /* WebKit OSR is the only scrolled component at the moment. */ - xw->widgetscrolledwindow_osr = NULL; - if (EQ (xw->type, Qwebkit)) { - xw->widgetscrolledwindow_osr = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_min_content_height - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr), - xw->height); - gtk_scrolled_window_set_min_content_width - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr), - xw->width); - gtk_scrolled_window_set_policy - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr), - GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); - xw->widget_osr = webkit_web_view_new (); - gtk_container_add (GTK_CONTAINER (xw->widgetscrolledwindow_osr), - GTK_WIDGET (WEBKIT_WEB_VIEW (xw->widget_osr))); } gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width, @@ -130,7 +114,7 @@ Returns the newly constructed xwidget, or nil if construction fails. */) if (EQ (xw->type, Qwebkit)) { gtk_container_add (GTK_CONTAINER (xw->widgetwindow_osr), - xw->widgetscrolledwindow_osr); + GTK_WIDGET (WEBKIT_WEB_VIEW (xw->widget_osr))); } else { @@ -140,7 +124,6 @@ Returns the newly constructed xwidget, or nil if construction fails. */) gtk_widget_show (xw->widget_osr); gtk_widget_show (xw->widgetwindow_osr); - gtk_widget_show (xw->widgetscrolledwindow_osr); /* Store some xwidget data in the gtk widgets for convenient retrieval in the event handlers. */ @@ -482,10 +465,7 @@ xwidget_osr_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data) cairo_rectangle (cr, 0, 0, xv->clip_right, xv->clip_bottom); cairo_clip (cr); - if (xw->widgetscrolledwindow_osr != NULL) - gtk_widget_draw (xw->widgetscrolledwindow_osr, cr); - else - gtk_widget_draw (xw->widget_osr, cr); + gtk_widget_draw (xw->widget_osr, cr); return FALSE; } @@ -767,21 +747,11 @@ DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0, /* If there is an offscreen widget resize it first. */ if (xw->widget_osr) { - /* Use minimum size. */ - gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), - xw->width, xw->height); - gtk_window_resize (GTK_WINDOW (xw->widgetwindow_osr), xw->width, xw->height); - gtk_scrolled_window_set_min_content_height - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr), - xw->height); - gtk_scrolled_window_set_min_content_width - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr), - xw->width); - gtk_container_resize_children (GTK_CONTAINER (xw->widgetwindow_osr)); - + gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width, + xw->height); } for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail); tail = XCDR (tail)) @@ -800,30 +770,6 @@ DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0, -DEFUN ("xwidget-set-adjustment", - Fxwidget_set_adjustment, Sxwidget_set_adjustment, 4, 4, 0, - doc: /* Set native scrolling for XWIDGET. -AXIS can be `vertical' or `horizontal'. -If RELATIVE is t, scroll relative, otherwise absolutely. -VALUE is the amount to scroll, either relatively or absolutely. */) - (Lisp_Object xwidget, Lisp_Object axis, Lisp_Object relative, - Lisp_Object value) -{ - CHECK_XWIDGET (xwidget); - CHECK_NUMBER (value); - struct xwidget *xw = XXWIDGET (xwidget); - GtkAdjustment *adjustment - = ((EQ (Qhorizontal, axis) - ? gtk_scrolled_window_get_hadjustment - : gtk_scrolled_window_get_vadjustment) - (GTK_SCROLLED_WINDOW (xw->widgetscrolledwindow_osr))); - double final_value = XINT (value); - if (EQ (Qt, relative)) - final_value += gtk_adjustment_get_value (adjustment); - gtk_adjustment_set_value (adjustment, final_value); - return Qnil; -} - DEFUN ("xwidget-size-request", Fxwidget_size_request, Sxwidget_size_request, @@ -1039,8 +985,6 @@ syms_of_xwidget (void) defsubr (&Sxwidget_buffer); defsubr (&Sset_xwidget_plist); - defsubr (&Sxwidget_set_adjustment); - DEFSYM (Qxwidget, "xwidget"); DEFSYM (QCxwidget, ":xwidget"); diff --git a/src/xwidget.h b/src/xwidget.h index 8fc3821..4447abb 100644 --- a/src/xwidget.h +++ b/src/xwidget.h @@ -56,9 +56,6 @@ struct xwidget GtkWidget *widget_osr; GtkWidget *widgetwindow_osr; - /* Used if the widget (webkit) is to be wrapped in a scrolled window. */ - GtkWidget *widgetscrolledwindow_osr; - /* Kill silently if Emacs is exited. */ bool_bf kill_without_query : 1; }; -- 2.10.1