* [PATCH 1/6] xwidget: Use WebKit2 API
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 2/6] Remove scrolled window container around WebKit widget Ricardo Wurmus
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
* configure.ac: Check for webkit2gtk-4.0.
* src/xwidget.c: Adjust to use WebKit2 API.
---
configure.ac | 4 +-
src/xwidget.c | 186 +++++++++++++++++++++++++---------------------------------
2 files changed, 82 insertions(+), 108 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6488f90..f382520 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2630,8 +2630,8 @@ if test "$with_xwidgets" != "no"; then
test "$USE_GTK_TOOLKIT" = "GTK3" && test "$window_system" != "none" ||
AC_MSG_ERROR([xwidgets requested but gtk3 not used.])
- WEBKIT_REQUIRED=1.4.0
- WEBKIT_MODULES="webkitgtk-3.0 >= $WEBKIT_REQUIRED"
+ WEBKIT_REQUIRED=2.12
+ WEBKIT_MODULES="webkit2gtk-4.0 >= $WEBKIT_REQUIRED"
EMACS_CHECK_MODULES([WEBKIT], [$WEBKIT_MODULES])
HAVE_XWIDGETS=$HAVE_WEBKIT
test $HAVE_XWIDGETS = yes ||
diff --git a/src/xwidget.c b/src/xwidget.c
index f5f4da0..78349a8 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -27,10 +27,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "keyboard.h"
#include "gtkutil.h"
-#include <webkit/webkitwebview.h>
-#include <webkit/webkitwebnavigationaction.h>
-#include <webkit/webkitdownload.h>
-#include <webkit/webkitwebpolicydecision.h>
+#include <webkit2/webkit2.h>
static struct xwidget *
allocate_xwidget (void)
@@ -50,34 +47,16 @@ allocate_xwidget_view (void)
static struct xwidget_view *xwidget_view_lookup (struct xwidget *,
struct window *);
-static void webkit_document_load_finished_cb (WebKitWebView *, WebKitWebFrame *,
- gpointer);
-static gboolean webkit_download_cb (WebKitWebView *, WebKitDownload *, gpointer);
+static void webkit_view_load_changed_cb (WebKitWebView *,
+ WebKitLoadEvent,
+ gpointer);
+static gboolean webkit_download_cb (WebKitWebContext *, WebKitDownload *, gpointer);
static gboolean
-webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *,
- WebKitWebFrame *,
- WebKitNetworkRequest *,
- gchar *,
- WebKitWebPolicyDecision *,
- gpointer);
-
-static gboolean
-webkit_new_window_policy_decision_requested_cb (WebKitWebView *,
- WebKitWebFrame *,
- WebKitNetworkRequest *,
- WebKitWebNavigationAction *,
- WebKitWebPolicyDecision *,
- gpointer);
-
-static gboolean
-webkit_navigation_policy_decision_requested_cb (WebKitWebView *,
- WebKitWebFrame *,
- WebKitNetworkRequest *,
- WebKitWebNavigationAction *,
- WebKitWebPolicyDecision *,
- gpointer);
-
+webkit_decide_policy_cb (WebKitWebView *,
+ WebKitPolicyDecision *,
+ WebKitPolicyDecisionType,
+ gpointer);
DEFUN ("make-xwidget",
@@ -168,29 +147,17 @@ Returns the newly constructed xwidget, or nil if construction fails. */)
if (EQ (xw->type, Qwebkit))
{
g_signal_connect (G_OBJECT (xw->widget_osr),
- "document-load-finished",
- G_CALLBACK (webkit_document_load_finished_cb), xw);
+ "load-changed",
+ G_CALLBACK (webkit_view_load_changed_cb), xw);
- g_signal_connect (G_OBJECT (xw->widget_osr),
- "download-requested",
+ g_signal_connect (G_OBJECT (webkit_web_context_get_default ()),
+ "download-started",
G_CALLBACK (webkit_download_cb), xw);
g_signal_connect (G_OBJECT (xw->widget_osr),
- "mime-type-policy-decision-requested",
- G_CALLBACK
- (webkit_mime_type_policy_typedecision_requested_cb),
- xw);
-
- g_signal_connect (G_OBJECT (xw->widget_osr),
- "new-window-policy-decision-requested",
- G_CALLBACK
- (webkit_new_window_policy_decision_requested_cb),
- xw);
-
- g_signal_connect (G_OBJECT (xw->widget_osr),
- "navigation-policy-decision-requested",
+ "decide-policy",
G_CALLBACK
- (webkit_navigation_policy_decision_requested_cb),
+ (webkit_decide_policy_cb),
xw);
}
@@ -284,81 +251,83 @@ store_xwidget_event_string (struct xwidget *xw, const char *eventname,
kbd_buffer_store_event (&event);
}
-/* TODO deprecated, use load-status. */
void
-webkit_document_load_finished_cb (WebKitWebView *webkitwebview,
- WebKitWebFrame *arg1,
- gpointer data)
+webkit_view_load_changed_cb (WebKitWebView *webkitwebview,
+ WebKitLoadEvent load_event,
+ gpointer data)
{
- struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview),
- XG_XWIDGET);
-
- store_xwidget_event_string (xw, "document-load-finished", "");
+ switch (load_event) {
+ case WEBKIT_LOAD_FINISHED:
+ {
+ struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview),
+ XG_XWIDGET);
+ store_xwidget_event_string (xw, "load-changed", "");
+ break;
+ }
+ default:
+ break;
+ }
}
gboolean
-webkit_download_cb (WebKitWebView *webkitwebview,
+webkit_download_cb (WebKitWebContext *webkitwebcontext,
WebKitDownload *arg1,
gpointer data)
{
- struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview),
+ WebKitWebView *view = webkit_download_get_web_view(arg1);
+ WebKitURIRequest *request = webkit_download_get_request(arg1);
+ struct xwidget *xw = g_object_get_data (G_OBJECT (view),
XG_XWIDGET);
- store_xwidget_event_string (xw, "download-requested",
- webkit_download_get_uri (arg1));
+
+ store_xwidget_event_string (xw, "download-started",
+ webkit_uri_request_get_uri(request));
return FALSE;
}
static gboolean
-webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *webView,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- gchar *mimetype,
- WebKitWebPolicyDecision *policy_decision,
- gpointer user_data)
+webkit_decide_policy_cb (WebKitWebView *webView,
+ WebKitPolicyDecision *decision,
+ WebKitPolicyDecisionType type,
+ gpointer user_data)
{
- /* This function makes webkit send a download signal for all unknown
- mime types. TODO: Defer the decision to Lisp, so that it's
- possible to make Emacs handle mime text for instance. */
- if (!webkit_web_view_can_show_mime_type (webView, mimetype))
+ switch (type) {
+ case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
+ /* This function makes webkit send a download signal for all unknown
+ mime types. TODO: Defer the decision to Lisp, so that it's
+ possible to make Emacs handle mime text for instance. */
{
- webkit_web_policy_decision_download (policy_decision);
- return TRUE;
+ WebKitResponsePolicyDecision *response =
+ WEBKIT_RESPONSE_POLICY_DECISION (decision);
+ if (!webkit_response_policy_decision_is_mime_type_supported (response))
+ {
+ webkit_policy_decision_download (decision);
+ return TRUE;
+ }
+ else
+ return FALSE;
+ break;
}
- else
+ case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION:
+ case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
+ {
+ WebKitNavigationPolicyDecision *navigation_decision =
+ WEBKIT_NAVIGATION_POLICY_DECISION (decision);
+ WebKitNavigationAction *navigation_action =
+ webkit_navigation_policy_decision_get_navigation_action (navigation_decision);
+ WebKitURIRequest *request =
+ webkit_navigation_action_get_request (navigation_action);
+
+ struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET);
+ store_xwidget_event_string (xw, "decide-policy",
+ webkit_uri_request_get_uri (request));
+ return FALSE;
+ break;
+ }
+ default:
return FALSE;
+ }
}
-static gboolean
-webkit_new_window_policy_decision_requested_cb (WebKitWebView *webView,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- WebKitWebNavigationAction *navigation_action,
- WebKitWebPolicyDecision *policy_decision,
- gpointer user_data)
-{
- struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET);
- webkit_web_navigation_action_get_original_uri (navigation_action);
-
- store_xwidget_event_string (xw, "new-window-policy-decision-requested",
- webkit_web_navigation_action_get_original_uri
- (navigation_action));
- return FALSE;
-}
-
-static gboolean
-webkit_navigation_policy_decision_requested_cb (WebKitWebView *webView,
- WebKitWebFrame *frame,
- WebKitNetworkRequest *request,
- WebKitWebNavigationAction *navigation_action,
- WebKitWebPolicyDecision *policy_decision,
- gpointer user_data)
-{
- struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET);
- store_xwidget_event_string (xw, "navigation-policy-decision-requested",
- webkit_web_navigation_action_get_original_uri
- (navigation_action));
- return FALSE;
-}
/* For gtk3 offscreen rendered widgets. */
static gboolean
@@ -599,8 +568,13 @@ DEFUN ("xwidget-webkit-execute-script",
{
WEBKIT_FN_INIT ();
CHECK_STRING (script);
- webkit_web_view_execute_script (WEBKIT_WEB_VIEW (xw->widget_osr),
- SSDATA (script));
+ // TODO: provide callback function to do something with the return
+ // value! This allows us to get rid of the title hack.
+ webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (xw->widget_osr),
+ SSDATA (script),
+ NULL, /*cancellable*/
+ NULL, /*callback*/
+ NULL /*user data*/);
return Qnil;
}
--
2.10.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/6] Remove scrolled window container around WebKit widget
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 1/6] xwidget: " Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 3/6] Implement zoom for " Ricardo Wurmus
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
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 7a0ca8b..ba05a16 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 78349a8..8e6b475 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 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.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/6] Implement zoom for WebKit widget
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 1/6] xwidget: " Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 2/6] Remove scrolled window container around WebKit widget Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 4/6] xwidget: Bind "beginning-of-buffer" and "end-of-buffer" Ricardo Wurmus
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
* src/xwidget.c (xwidget-webkit-zoom): New procedure.
* lisp/xwidget.el: Bind "+" and "-" to zoom in and out, respectively.
(xwidget-webkit-zoom): Declare procedure.
(xwidget-webkit-zoom-in, xwidget-webkit-zoom-out): New procedures.
---
lisp/xwidget.el | 13 +++++++++++++
src/xwidget.c | 20 ++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index ba05a16..0892030 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -42,6 +42,7 @@
(declare-function xwidget-resize "xwidget.c" (xwidget new-width new-height))
(declare-function xwidget-webkit-execute-script "xwidget.c" (xwidget script))
(declare-function xwidget-webkit-goto-uri "xwidget.c" (xwidget uri))
+(declare-function xwidget-webkit-zoom "xwidget.c" (xwidget factor))
(declare-function xwidget-plist "xwidget.c" (xwidget))
(declare-function set-xwidget-plist "xwidget.c" (xwidget plist))
(declare-function xwidget-view-window "xwidget.c" (xwidget-view))
@@ -106,6 +107,8 @@ Interactively, URL defaults to the string looking like a url around point."
(define-key map "t" (lambda () (interactive) (message "o"))) ;FIXME: ?!?
(define-key map "\C-m" 'xwidget-webkit-insert-string)
(define-key map "w" 'xwidget-webkit-current-url)
+ (define-key map "+" 'xwidget-webkit-zoom-in)
+ (define-key map "-" 'xwidget-webkit-zoom-out)
;;similar to image mode bindings
(define-key map (kbd "SPC") 'xwidget-webkit-scroll-up)
@@ -131,6 +134,16 @@ Interactively, URL defaults to the string looking like a url around point."
map)
"Keymap for `xwidget-webkit-mode'.")
+(defun xwidget-webkit-zoom-in ()
+ "Increase webkit view zoom factor."
+ (interactive)
+ (xwidget-webkit-zoom (xwidget-webkit-current-session) 0.1))
+
+(defun xwidget-webkit-zoom-out ()
+ "Decrease webkit view zoom factor."
+ (interactive)
+ (xwidget-webkit-zoom (xwidget-webkit-current-session) -0.1))
+
(defun xwidget-webkit-scroll-up ()
"Scroll webkit up."
(interactive)
diff --git a/src/xwidget.c b/src/xwidget.c
index 8e6b475..a098150 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -539,6 +539,25 @@ DEFUN ("xwidget-webkit-goto-uri",
return Qnil;
}
+DEFUN ("xwidget-webkit-zoom",
+ Fxwidget_webkit_zoom, Sxwidget_webkit_zoom,
+ 2, 2, 0,
+ doc: /* Change the zoom factor of the xwidget webkit instance
+referenced by XWIDGET. */)
+ (Lisp_Object xwidget, Lisp_Object factor)
+{
+ WEBKIT_FN_INIT ();
+ if (FLOATP (factor))
+ {
+ double zoom_change = XFLOAT_DATA (factor);
+ webkit_web_view_set_zoom_level
+ (WEBKIT_WEB_VIEW (xw->widget_osr),
+ webkit_web_view_get_zoom_level
+ (WEBKIT_WEB_VIEW (xw->widget_osr)) + zoom_change);
+ }
+ return Qnil;
+}
+
DEFUN ("xwidget-webkit-execute-script",
Fxwidget_webkit_execute_script, Sxwidget_webkit_execute_script,
@@ -823,6 +842,7 @@ syms_of_xwidget (void)
defsubr (&Sset_xwidget_query_on_exit_flag);
defsubr (&Sxwidget_webkit_goto_uri);
+ defsubr (&Sxwidget_webkit_zoom);
defsubr (&Sxwidget_webkit_execute_script);
defsubr (&Sxwidget_webkit_get_title);
DEFSYM (Qwebkit, "webkit");
--
2.10.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/6] xwidget: Bind "beginning-of-buffer" and "end-of-buffer"
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
` (2 preceding siblings ...)
2016-09-21 11:50 ` [PATCH 3/6] Implement zoom for " Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 5/6] Let initial WebKit view fill window Ricardo Wurmus
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
* lisp/xwidget.el: Rebind "beginning-of-buffer" and "end-of-buffer" to
"xwidget-webkit-scroll-top" and "xwidget-webkit-scroll-bottom",
respectively.
(xwidget-webkit-scroll-top,
xwidget-webkit-scroll-bottom): New procedures.
---
lisp/xwidget.el | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 0892030..6ee4c67 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -129,8 +129,8 @@ Interactively, URL defaults to the string looking like a url around point."
;; (define-key map [remap move-beginning-of-line] 'image-bol)
;; (define-key map [remap move-end-of-line] 'image-eol)
- ;; (define-key map [remap beginning-of-buffer] 'image-bob)
- ;; (define-key map [remap end-of-buffer] 'image-eob)
+ (define-key map [remap beginning-of-buffer] 'xwidget-webkit-scroll-top)
+ (define-key map [remap end-of-buffer] 'xwidget-webkit-scroll-bottom)
map)
"Keymap for `xwidget-webkit-mode'.")
@@ -172,6 +172,19 @@ Interactively, URL defaults to the string looking like a url around point."
(xwidget-webkit-current-session)
"window.scrollBy(-50, 0);"))
+(defun xwidget-webkit-scroll-top ()
+ "Scroll webkit to the very top."
+ (interactive)
+ (xwidget-webkit-execute-script
+ (xwidget-webkit-current-session)
+ "window.scrollTo(pageXOffset, 0);"))
+
+(defun xwidget-webkit-scroll-bottom ()
+ "Scroll webkit to the very bottom."
+ (interactive)
+ (xwidget-webkit-execute-script
+ (xwidget-webkit-current-session)
+ "window.scrollTo(pageXOffset, window.document.body.clientHeight);"))
;; The xwidget event needs to go into a higher level handler
;; since the xwidget can generate an event even if it's offscreen.
--
2.10.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/6] Let initial WebKit view fill window
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
` (3 preceding siblings ...)
2016-09-21 11:50 ` [PATCH 4/6] xwidget: Bind "beginning-of-buffer" and "end-of-buffer" Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 6/6] xwidget: Map "previous-line" and "next-line" to scroll Ricardo Wurmus
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
* lisp/xwidget.el (xwidget-webkit-new-session): Change default size of
WebKit widget to window size.
---
lisp/xwidget.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 6ee4c67..c266cac 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -460,7 +460,9 @@ For example, use this to display an anchor."
(setq xwidget-webkit-last-session-buffer (switch-to-buffer
(get-buffer-create bufname)))
(insert " 'a' adjusts the xwidget size.")
- (setq xw (xwidget-insert 1 'webkit bufname 1000 1000))
+ (setq xw (xwidget-insert 1 'webkit bufname
+ (window-pixel-width)
+ (window-pixel-height)))
(xwidget-put xw 'callback 'xwidget-webkit-callback)
(xwidget-webkit-mode)
(xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
--
2.10.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/6] xwidget: Map "previous-line" and "next-line" to scroll
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
` (4 preceding siblings ...)
2016-09-21 11:50 ` [PATCH 5/6] Let initial WebKit view fill window Ricardo Wurmus
@ 2016-09-21 11:50 ` Ricardo Wurmus
2016-09-21 12:05 ` [PATCH 0/6] xwidget webkit: Use WebKit2 API joakim
2016-09-21 14:51 ` Eli Zaretskii
7 siblings, 0 replies; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 11:50 UTC (permalink / raw)
To: emacs-devel; +Cc: Ricardo Wurmus
* lisp/xwidget.el: Map "previous-line" and "next-line" to scrolling
procedures.
---
lisp/xwidget.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index c266cac..a540a11 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -124,8 +124,8 @@ Interactively, URL defaults to the string looking like a url around point."
(define-key map [remap backward-char] 'xwidget-webkit-scroll-backward)
(define-key map [remap right-char] 'xwidget-webkit-scroll-forward)
(define-key map [remap left-char] 'xwidget-webkit-scroll-backward)
- ;; (define-key map [remap previous-line] 'image-previous-line)
- ;; (define-key map [remap next-line] 'image-next-line)
+ (define-key map [remap previous-line] 'xwidget-webkit-scroll-down)
+ (define-key map [remap next-line] 'xwidget-webkit-scroll-up)
;; (define-key map [remap move-beginning-of-line] 'image-bol)
;; (define-key map [remap move-end-of-line] 'image-eol)
--
2.10.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] xwidget webkit: Use WebKit2 API.
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
` (5 preceding siblings ...)
2016-09-21 11:50 ` [PATCH 6/6] xwidget: Map "previous-line" and "next-line" to scroll Ricardo Wurmus
@ 2016-09-21 12:05 ` joakim
2016-09-21 14:51 ` Eli Zaretskii
7 siblings, 0 replies; 11+ messages in thread
From: joakim @ 2016-09-21 12:05 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: emacs-devel
Ricardo Wurmus <rekado@elephly.net> writes:
> O fellow humans on emacs-devel!
>
> I noticed that for the embedding of a WebKit widget in Emacs an old
> version of WebKitGtk is needed, because the code in "src/xwidget.c"
> targets the WebKit1 API. As far as I know, only the latest version of
> WebKitGtk is actively maintained, so it seems like a good idea to make
> Emacs work with the latest version.
I haven't had a chance to try this yet, but I'm very happy that you are
working on this!
>
> The first patch in this series adjusts the code such that the WebKit2
> API is used instead, which allows users to build Emacs with the latest
> version of WebKit(2)Gtk. Due to process separation in WebKit2Gtk,
> scrolling is now supposed to be done in the UI process. This is what
> the second patch does; it implements scrolling by executing JavaScript
> in the WebKit view. (Maybe the first two commits should be squashed?)
>
> The other patches are simple changes to make interacting with the
> WebKit widget a little easier.
>
> If these patches are okay I'd like to continue by removing the title
> hack, which is currently used to get a stringified return value from
> JavaScript. This is no longer needed when using the WebKit2 API as it
> supports passing a callback to process any JS return values.
Indeed the title hack is horrible, and I'm glad you have found a better solution.
> ~~ Ricardo
>
> PS: I did copyright assigment for GNU Guile already, but I'm not sure
> if copyright assignment is on file for Emacs already.
>
> Ricardo Wurmus (6):
> xwidget: Use WebKit2 API
> Remove scrolled window container around WebKit widget
> Implement zoom for WebKit widget.
> xwidget: Bind "beginning-of-buffer" and "end-of-buffer"
> Let initial WebKit view fill window
> xwidget: Map "previous-line" and "next-line" to scroll
>
> configure.ac | 4 +-
> lisp/xwidget.el | 56 +++++++++---
> src/xwidget.c | 270 ++++++++++++++++++++++----------------------------------
> src/xwidget.h | 3 -
> 4 files changed, 151 insertions(+), 182 deletions(-)
--
Joakim Verona
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] xwidget webkit: Use WebKit2 API.
2016-09-21 11:50 [PATCH 0/6] xwidget webkit: Use WebKit2 API Ricardo Wurmus
` (6 preceding siblings ...)
2016-09-21 12:05 ` [PATCH 0/6] xwidget webkit: Use WebKit2 API joakim
@ 2016-09-21 14:51 ` Eli Zaretskii
2016-09-21 18:47 ` Ricardo Wurmus
7 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2016-09-21 14:51 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: emacs-devel
> From: Ricardo Wurmus <rekado@elephly.net>
> Date: Wed, 21 Sep 2016 13:50:12 +0200
> Cc: Ricardo Wurmus <rekado@elephly.net>
>
> O fellow humans on emacs-devel!
>
> I noticed that for the embedding of a WebKit widget in Emacs an old
> version of WebKitGtk is needed, because the code in "src/xwidget.c"
> targets the WebKit1 API. As far as I know, only the latest version of
> WebKitGtk is actively maintained, so it seems like a good idea to make
> Emacs work with the latest version.
>
> The first patch in this series adjusts the code such that the WebKit2
> API is used instead, which allows users to build Emacs with the latest
> version of WebKit(2)Gtk. Due to process separation in WebKit2Gtk,
> scrolling is now supposed to be done in the UI process. This is what
> the second patch does; it implements scrolling by executing JavaScript
> in the WebKit view. (Maybe the first two commits should be squashed?)
>
> The other patches are simple changes to make interacting with the
> WebKit widget a little easier.
Thank you for your contribution.
> PS: I did copyright assigment for GNU Guile already, but I'm not sure
> if copyright assignment is on file for Emacs already.
No, the Emacs assignment is not yet on file. We will have to wait
until it is, before we can accept your contributions.
Thanks again for working on this.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] xwidget webkit: Use WebKit2 API.
2016-09-21 14:51 ` Eli Zaretskii
@ 2016-09-21 18:47 ` Ricardo Wurmus
2016-09-21 19:12 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2016-09-21 18:47 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
Eli Zaretskii <eliz@gnu.org> writes:
>> PS: I did copyright assigment for GNU Guile already, but I'm not sure
>> if copyright assignment is on file for Emacs already.
>
> No, the Emacs assignment is not yet on file. We will have to wait
> until it is, before we can accept your contributions.
Okay, I’ll send an email to assign@gnu.org to get this done. Should I
resend these patches in the future or just ping this thread once the
assignment is complete? (Or neither?)
~~ Ricardo
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 0/6] xwidget webkit: Use WebKit2 API.
2016-09-21 18:47 ` Ricardo Wurmus
@ 2016-09-21 19:12 ` Eli Zaretskii
0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2016-09-21 19:12 UTC (permalink / raw)
To: Ricardo Wurmus; +Cc: emacs-devel
> From: Ricardo Wurmus <rekado@elephly.net>
> Date: Wed, 21 Sep 2016 20:47:43 +0200
> Cc: emacs-devel@gnu.org
>
> Okay, I’ll send an email to assign@gnu.org to get this done.
Thanks.
> Should I resend these patches in the future or just ping this thread
> once the assignment is complete? (Or neither?)
It depends on how much time passes until your assignment is on file.
If it will take some time, it would be best to rebase your patches on
the-then current master branch and resend.
^ permalink raw reply [flat|nested] 11+ messages in thread