summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrekado <rekado@elephly.net>2016-09-20 16:19:04 +0200
committerrekado <rekado@elephly.net>2016-09-20 22:11:45 +0200
commit9261c64e6830cb9a661f83b59be986d2eab41765 (patch)
tree94d89ffa03275305aac27748f06572c73554925d
parent2404437902ee6b92207d90ac797c6f1c07b705ea (diff)
WIP: WebKit widget can scroll by itself.
-rw-r--r--lisp/xwidget.el18
-rw-r--r--src/xwidget.c64
-rw-r--r--src/xwidget.h3
3 files changed, 16 insertions, 69 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 7a0ca8bd55..ba05a161ae 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))
@@ -136,22 +134,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 78349a819a..8e6b47507b 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -99,25 +99,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,
@@ -126,7 +110,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
{
@@ -136,7 +120,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. */
@@ -340,10 +323,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;
}
@@ -616,21 +596,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))
@@ -649,30 +619,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,
@@ -888,8 +834,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 8fc382188f..4447abbe38 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;
};