[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 37ad776b9e: Make xwidget motion commands hscroll the window of wi
From: |
Po Lu |
Subject: |
master 37ad776b9e: Make xwidget motion commands hscroll the window of wide widgets |
Date: |
Thu, 30 Dec 2021 02:06:03 -0500 (EST) |
branch: master
commit 37ad776b9e6c90b2c289dd2413868066608594a7
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Make xwidget motion commands hscroll the window of wide widgets
* lisp/xwidget.el (xwidget-info): New function declaration.
(xwidget-webkit-scroll-forward):
(xwidget-webkit-scroll-backward): Hscroll the window if the
widget is wider than the text area. (bug#52885)
* src/xwidget.c (xwidget_scroll, xwidget_motion_notify): Apply
clip offsets to coordinates.
---
lisp/xwidget.el | 38 ++++++++++++++++++++++++++------------
src/xwidget.c | 6 ++++--
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index ce9839ebd3..12ee597504 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -60,6 +60,7 @@
(declare-function xwidget-webkit-set-cookie-storage-file "xwidget.c" (xwidget
file))
(declare-function xwidget-live-p "xwidget.c" (xwidget))
(declare-function xwidget-webkit-stop-loading "xwidget.c" (xwidget))
+(declare-function xwidget-info "xwidget.c" (xwidget))
(defgroup xwidget nil
"Displaying native widgets in Emacs buffers."
@@ -347,23 +348,36 @@ If N is omitted or nil, scroll down by one line."
(defun xwidget-webkit-scroll-forward (&optional n)
"Scroll webkit horizontally by N chars.
-The width of char is calculated with `window-font-width'.
-If N is omitted or nil, scroll forwards by one char."
+If the widget is larger than the window, hscroll by N columns
+instead. The width of char is calculated with
+`window-font-width'. If N is omitted or nil, scroll forwards by
+one char."
(interactive "p" xwidget-webkit-mode)
- (xwidget-webkit-execute-script
- (xwidget-webkit-current-session)
- (format "window.scrollBy(%d, 0);"
- (* n (window-font-width)))))
+ (let ((session (xwidget-webkit-current-session)))
+ (if (> (- (aref (xwidget-info session) 2)
+ (window-text-width nil t))
+ (window-font-width))
+ (set-window-hscroll nil (+ (window-hscroll) n))
+ (xwidget-webkit-execute-script session
+ (format "window.scrollBy(%d, 0);"
+ (* n (window-font-width)))))))
(defun xwidget-webkit-scroll-backward (&optional n)
"Scroll webkit back by N chars.
-The width of char is calculated with `window-font-width'.
-If N is omitted or nil, scroll backwards by one char."
+If the widget is larger than the window, hscroll backwards by N
+columns instead. The width of char is calculated with
+`window-font-width'. If N is omitted or nil, scroll backwards by
+one char."
(interactive "p" xwidget-webkit-mode)
- (xwidget-webkit-execute-script
- (xwidget-webkit-current-session)
- (format "window.scrollBy(-%d, 0);"
- (* n (window-font-width)))))
+ (let ((session (xwidget-webkit-current-session)))
+ (if (and (> (- (aref (xwidget-info session) 2)
+ (window-text-width nil t))
+ (window-font-width))
+ (> (window-hscroll) 0))
+ (set-window-hscroll nil (- (window-hscroll) n))
+ (xwidget-webkit-execute-script session
+ (format "window.scrollBy(%-d, 0);"
+ (* n (window-font-width)))))))
(defun xwidget-webkit-scroll-top ()
"Scroll webkit to the very top."
diff --git a/src/xwidget.c b/src/xwidget.c
index 5aeb2beae2..49e15a0955 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -1156,7 +1156,8 @@ xwidget_motion_notify (struct xwidget_view *view,
record_osr_embedder (view);
target = find_widget_at_pos (model->widgetwindow_osr,
- lrint (x), lrint (y),
+ lrint (x + view->clip_left),
+ lrint (y + view->clip_top),
&target_x, &target_y);
if (!target)
@@ -1198,7 +1199,8 @@ xwidget_scroll (struct xwidget_view *view, double x,
double y,
record_osr_embedder (view);
target = find_widget_at_pos (model->widgetwindow_osr,
- lrint (x), lrint (y),
+ lrint (x + view->clip_left),
+ lrint (y + view->clip_top),
&target_x, &target_y);
if (!target)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 37ad776b9e: Make xwidget motion commands hscroll the window of wide widgets,
Po Lu <=