From: Ricardo Wurmus <rekado@elephly.net>
To: emacs-devel@gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>
Subject: [PATCH 03/15] Remove scrolled window container around WebKit widget
Date: Mon, 24 Oct 2016 18:40:49 +0200 [thread overview]
Message-ID: <20161024164101.26043-4-rekado@elephly.net> (raw)
In-Reply-To: <20161024164101.26043-1-rekado@elephly.net>
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
next prev 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 ` Ricardo Wurmus [this message]
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 ` [PATCH 12/15] Dynamically resize WebKit widget Ricardo Wurmus
2016-10-24 16:40 ` [PATCH 13/15] Implement zoom for " 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-4-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.