emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 03/15] Remove scrolled window container around WebKit widget


From: Ricardo Wurmus
Subject: [PATCH 03/15] Remove scrolled window container around WebKit widget
Date: Mon, 24 Oct 2016 18:40:49 +0200

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]