From: Po Lu Date: Thu, 30 Dec 2021 07:04:18 +0000 (+0800) Subject: Make xwidget motion commands hscroll the window of wide widgets X-Git-Tag: emacs-29.0.90~3353 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=37ad776b9e6c90b2c289dd2413868066608594a7;p=emacs.git 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. --- diff --git a/lisp/xwidget.el b/lisp/xwidget.el index ce9839ebd34..12ee5975040 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 5aeb2beae2d..49e15a0955c 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)