unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: emacs-devel@gnu.org
Cc: Ricardo Wurmus <rekado@elephly.net>
Subject: [PATCH 3/6] Implement zoom for WebKit widget
Date: Wed, 21 Sep 2016 13:50:15 +0200	[thread overview]
Message-ID: <20160921115018.29576-4-rekado@elephly.net> (raw)
In-Reply-To: <20160921115018.29576-1-rekado@elephly.net>

* 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





  parent reply	other threads:[~2016-09-21 11:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-09-21 11:50 ` [PATCH 4/6] xwidget: Bind "beginning-of-buffer" and "end-of-buffer" Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 5/6] Let initial WebKit view fill window Ricardo Wurmus
2016-09-21 11:50 ` [PATCH 6/6] xwidget: Map "previous-line" and "next-line" to scroll Ricardo Wurmus
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
2016-09-21 19:12     ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160921115018.29576-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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).