diff options
| author | Po Lu | 2021-11-22 10:42:46 +0800 |
|---|---|---|
| committer | Po Lu | 2021-11-22 10:47:29 +0800 |
| commit | 9324efac480df3cd78af112da2b12a0d2bd18e02 (patch) | |
| tree | df9a164eca57746fd357c296613062cec7b1f49b | |
| parent | 536e7bf03b2ef8451fdd6b8d62db08f2bc7ebec9 (diff) | |
| download | emacs-9324efac480df3cd78af112da2b12a0d2bd18e02.tar.gz emacs-9324efac480df3cd78af112da2b12a0d2bd18e02.zip | |
Make `xwidget-display-event' a special event as well
* doc/lispref/commands.texi (Xwidget Events): Document that
`xwidget-display-event' is a special event, and that it should
be handled through callbacks.
* etc/NEWS: Update NEWS entry.
* lisp/xwidget.el (xwidget-webkit-new-session)
(xwidget-webkit-import-widget): Attach display callback.
(xwidget-webkit-display-event): Call display callback instead.
(xwidget-webkit-display-callback): New function.
* src/keyboard.c (make_lispy_event): Store
source information for XWIDGET_DISPLAY_EVENT correctly.
* src/xwidget.c (store_xwidget_display_event): Store
source of the display request.
(webkit_ready_to_show): Store source if available.
(webkit_create_cb_1): Store source if available.
(kill_xwidget): Remove dead widget from internal_xwidget_list.
| -rw-r--r-- | doc/lispref/commands.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/xwidget.el | 17 | ||||
| -rw-r--r-- | src/keyboard.c | 2 | ||||
| -rw-r--r-- | src/xwidget.c | 34 |
5 files changed, 50 insertions, 17 deletions
diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texi index 5fd7b55a60b..c12a97cc7df 100644 --- a/doc/lispref/commands.texi +++ b/doc/lispref/commands.texi | |||
| @@ -1950,9 +1950,15 @@ internally by @code{xwidget-webkit-execute-script}. | |||
| 1950 | @end table | 1950 | @end table |
| 1951 | 1951 | ||
| 1952 | @cindex @code{xwidget-display-event} event | 1952 | @cindex @code{xwidget-display-event} event |
| 1953 | @item (xwidget-display-event @var{xwidget}) | 1953 | @item (xwidget-display-event @var{xwidget} @var{source}) |
| 1954 | This event is sent whenever an xwidget requests that another xwidget | 1954 | This event is sent whenever an xwidget requests that another xwidget |
| 1955 | be displayed. @var{xwidget} is the xwidget that should be displayed. | 1955 | be displayed. @var{xwidget} is the xwidget that should be displayed, |
| 1956 | and @var{source} is the xwidget that asked to display @var{xwidget}. | ||
| 1957 | |||
| 1958 | It is also a special event which should be handled through callbacks. | ||
| 1959 | You can add such a callback by setting the @code{display-callback} of | ||
| 1960 | @var{source}'s property list, which should be a function that accepts | ||
| 1961 | @var{xwidget} and @var{source} as arguments. | ||
| 1956 | 1962 | ||
| 1957 | @var{xwidget}'s buffer will be set to a temporary buffer. When | 1963 | @var{xwidget}'s buffer will be set to a temporary buffer. When |
| 1958 | displaying the widget, care should be taken to replace the buffer with | 1964 | displaying the widget, care should be taken to replace the buffer with |
| @@ -927,8 +927,8 @@ commits to the load. | |||
| 927 | +++ | 927 | +++ |
| 928 | *** New event type 'xwidget-display-event'. | 928 | *** New event type 'xwidget-display-event'. |
| 929 | These events are sent whenever an xwidget requests that Emacs display | 929 | These events are sent whenever an xwidget requests that Emacs display |
| 930 | another xwidget. The only argument to this event is the xwidget that | 930 | another xwidget. The only arguments to this event are the xwidget |
| 931 | should be displayed. | 931 | that should be displayed, and the xwidget that asked to display it. |
| 932 | 932 | ||
| 933 | +++ | 933 | +++ |
| 934 | *** New function 'xwidget-webkit-set-cookie-storage-file'. | 934 | *** New function 'xwidget-webkit-set-cookie-storage-file'. |
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 160da67cb21..cf4396fec2d 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -818,6 +818,7 @@ For example, use this to display an anchor." | |||
| 818 | (xwidget-webkit-set-cookie-storage-file | 818 | (xwidget-webkit-set-cookie-storage-file |
| 819 | xw (expand-file-name xwidget-webkit-cookie-file))) | 819 | xw (expand-file-name xwidget-webkit-cookie-file))) |
| 820 | (xwidget-put xw 'callback callback) | 820 | (xwidget-put xw 'callback callback) |
| 821 | (xwidget-put xw 'display-callback #'xwidget-webkit-display-callback) | ||
| 821 | (xwidget-webkit-mode) | 822 | (xwidget-webkit-mode) |
| 822 | (xwidget-webkit-goto-uri (xwidget-webkit-last-session) url))) | 823 | (xwidget-webkit-goto-uri (xwidget-webkit-last-session) url))) |
| 823 | 824 | ||
| @@ -840,16 +841,26 @@ Return the buffer." | |||
| 840 | (put-text-property (point-min) (point-max) | 841 | (put-text-property (point-min) (point-max) |
| 841 | 'display (list 'xwidget :xwidget xwidget))) | 842 | 'display (list 'xwidget :xwidget xwidget))) |
| 842 | (xwidget-put xwidget 'callback callback) | 843 | (xwidget-put xwidget 'callback callback) |
| 844 | (xwidget-put xwidget 'display-callback | ||
| 845 | #'xwidget-webkit-display-callback) | ||
| 843 | (set-xwidget-buffer xwidget buffer) | 846 | (set-xwidget-buffer xwidget buffer) |
| 844 | (xwidget-webkit-mode)) | 847 | (xwidget-webkit-mode)) |
| 845 | buffer)) | 848 | buffer)) |
| 846 | 849 | ||
| 847 | (defun xwidget-webkit-display-event (event) | 850 | (defun xwidget-webkit-display-event (event) |
| 848 | "Import the xwidget inside EVENT and display it." | 851 | "Trigger display callback for EVENT." |
| 849 | (interactive "e") | 852 | (interactive "e") |
| 850 | (display-buffer (xwidget-webkit-import-widget (nth 1 event)))) | 853 | (let ((xwidget (cadr event)) |
| 854 | (source (caddr event))) | ||
| 855 | (when (xwidget-get source 'display-callback) | ||
| 856 | (funcall (xwidget-get source 'display-callback) | ||
| 857 | xwidget source)))) | ||
| 851 | 858 | ||
| 852 | (global-set-key [xwidget-display-event] 'xwidget-webkit-display-event) | 859 | (defun xwidget-webkit-display-callback (xwidget _source) |
| 860 | "Import XWIDGET and display it." | ||
| 861 | (display-buffer (xwidget-webkit-import-widget xwidget))) | ||
| 862 | |||
| 863 | (define-key special-event-map [xwidget-display-event] 'xwidget-webkit-display-event) | ||
| 853 | 864 | ||
| 854 | (defun xwidget-webkit-goto-url (url) | 865 | (defun xwidget-webkit-goto-url (url) |
| 855 | "Goto URL with xwidget webkit." | 866 | "Goto URL with xwidget webkit." |
diff --git a/src/keyboard.c b/src/keyboard.c index 982854c41e1..c98175aea0d 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -6141,7 +6141,7 @@ make_lispy_event (struct input_event *event) | |||
| 6141 | return Fcons (Qxwidget_event, event->arg); | 6141 | return Fcons (Qxwidget_event, event->arg); |
| 6142 | 6142 | ||
| 6143 | case XWIDGET_DISPLAY_EVENT: | 6143 | case XWIDGET_DISPLAY_EVENT: |
| 6144 | return list2 (Qxwidget_display_event, event->arg); | 6144 | return Fcons (Qxwidget_display_event, event->arg); |
| 6145 | #endif | 6145 | #endif |
| 6146 | 6146 | ||
| 6147 | #ifdef USE_FILE_NOTIFY | 6147 | #ifdef USE_FILE_NOTIFY |
diff --git a/src/xwidget.c b/src/xwidget.c index d88270dbe97..5da2aa1743b 100644 --- a/src/xwidget.c +++ b/src/xwidget.c | |||
| @@ -1316,16 +1316,18 @@ store_xwidget_js_callback_event (struct xwidget *xw, | |||
| 1316 | 1316 | ||
| 1317 | #ifdef USE_GTK | 1317 | #ifdef USE_GTK |
| 1318 | static void | 1318 | static void |
| 1319 | store_xwidget_display_event (struct xwidget *xw) | 1319 | store_xwidget_display_event (struct xwidget *xw, |
| 1320 | struct xwidget *src) | ||
| 1320 | { | 1321 | { |
| 1321 | struct input_event evt; | 1322 | struct input_event evt; |
| 1322 | Lisp_Object val; | 1323 | Lisp_Object val, src_val; |
| 1323 | 1324 | ||
| 1324 | XSETXWIDGET (val, xw); | 1325 | XSETXWIDGET (val, xw); |
| 1326 | XSETXWIDGET (src_val, src); | ||
| 1325 | EVENT_INIT (evt); | 1327 | EVENT_INIT (evt); |
| 1326 | evt.kind = XWIDGET_DISPLAY_EVENT; | 1328 | evt.kind = XWIDGET_DISPLAY_EVENT; |
| 1327 | evt.frame_or_window = Qnil; | 1329 | evt.frame_or_window = Qnil; |
| 1328 | evt.arg = val; | 1330 | evt.arg = list2 (val, src_val); |
| 1329 | kbd_buffer_store_event (&evt); | 1331 | kbd_buffer_store_event (&evt); |
| 1330 | } | 1332 | } |
| 1331 | 1333 | ||
| @@ -1335,6 +1337,9 @@ webkit_ready_to_show (WebKitWebView *new_view, | |||
| 1335 | { | 1337 | { |
| 1336 | Lisp_Object tem; | 1338 | Lisp_Object tem; |
| 1337 | struct xwidget *xw; | 1339 | struct xwidget *xw; |
| 1340 | struct xwidget *src; | ||
| 1341 | |||
| 1342 | src = find_xwidget_for_offscreen_window (GDK_WINDOW (user_data)); | ||
| 1338 | 1343 | ||
| 1339 | for (tem = internal_xwidget_list; CONSP (tem); tem = XCDR (tem)) | 1344 | for (tem = internal_xwidget_list; CONSP (tem); tem = XCDR (tem)) |
| 1340 | { | 1345 | { |
| @@ -1344,14 +1349,21 @@ webkit_ready_to_show (WebKitWebView *new_view, | |||
| 1344 | 1349 | ||
| 1345 | if (EQ (xw->type, Qwebkit) | 1350 | if (EQ (xw->type, Qwebkit) |
| 1346 | && WEBKIT_WEB_VIEW (xw->widget_osr) == new_view) | 1351 | && WEBKIT_WEB_VIEW (xw->widget_osr) == new_view) |
| 1347 | store_xwidget_display_event (xw); | 1352 | { |
| 1353 | /* The source widget was destroyed before we had a | ||
| 1354 | chance to display the new widget. */ | ||
| 1355 | if (!src) | ||
| 1356 | kill_xwidget (xw); | ||
| 1357 | else | ||
| 1358 | store_xwidget_display_event (xw, src); | ||
| 1359 | } | ||
| 1348 | } | 1360 | } |
| 1349 | } | 1361 | } |
| 1350 | } | 1362 | } |
| 1351 | 1363 | ||
| 1352 | static GtkWidget * | 1364 | static GtkWidget * |
| 1353 | webkit_create_cb_1 (WebKitWebView *webview, | 1365 | webkit_create_cb_1 (WebKitWebView *webview, |
| 1354 | struct xwidget_view *xv) | 1366 | struct xwidget *xv) |
| 1355 | { | 1367 | { |
| 1356 | Lisp_Object related; | 1368 | Lisp_Object related; |
| 1357 | Lisp_Object xwidget; | 1369 | Lisp_Object xwidget; |
| @@ -1369,7 +1381,8 @@ webkit_create_cb_1 (WebKitWebView *webview, | |||
| 1369 | widget = XXWIDGET (xwidget)->widget_osr; | 1381 | widget = XXWIDGET (xwidget)->widget_osr; |
| 1370 | 1382 | ||
| 1371 | g_signal_connect (G_OBJECT (widget), "ready-to-show", | 1383 | g_signal_connect (G_OBJECT (widget), "ready-to-show", |
| 1372 | G_CALLBACK (webkit_ready_to_show), NULL); | 1384 | G_CALLBACK (webkit_ready_to_show), |
| 1385 | gtk_widget_get_window (xv->widgetwindow_osr)); | ||
| 1373 | 1386 | ||
| 1374 | return widget; | 1387 | return widget; |
| 1375 | } | 1388 | } |
| @@ -1591,7 +1604,7 @@ webkit_decide_policy_cb (WebKitWebView *webView, | |||
| 1591 | newview = WEBKIT_WEB_VIEW (XXWIDGET (new_xwidget)->widget_osr); | 1604 | newview = WEBKIT_WEB_VIEW (XXWIDGET (new_xwidget)->widget_osr); |
| 1592 | webkit_web_view_load_request (newview, request); | 1605 | webkit_web_view_load_request (newview, request); |
| 1593 | 1606 | ||
| 1594 | store_xwidget_display_event (XXWIDGET (new_xwidget)); | 1607 | store_xwidget_display_event (XXWIDGET (new_xwidget), xw); |
| 1595 | return TRUE; | 1608 | return TRUE; |
| 1596 | } | 1609 | } |
| 1597 | case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: | 1610 | case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: |
| @@ -3106,6 +3119,11 @@ kill_frame_xwidget_views (struct frame *f) | |||
| 3106 | static void | 3119 | static void |
| 3107 | kill_xwidget (struct xwidget *xw) | 3120 | kill_xwidget (struct xwidget *xw) |
| 3108 | { | 3121 | { |
| 3122 | Lisp_Object val; | ||
| 3123 | XSETXWIDGET (val, xw); | ||
| 3124 | |||
| 3125 | internal_xwidget_list = Fdelq (val, internal_xwidget_list); | ||
| 3126 | Vxwidget_list = Fcopy_sequence (internal_xwidget_list); | ||
| 3109 | #ifdef USE_GTK | 3127 | #ifdef USE_GTK |
| 3110 | xw->buffer = Qnil; | 3128 | xw->buffer = Qnil; |
| 3111 | 3129 | ||
| @@ -3145,8 +3163,6 @@ kill_buffer_xwidgets (Lisp_Object buffer) | |||
| 3145 | for (tail = Fget_buffer_xwidgets (buffer); CONSP (tail); tail = XCDR (tail)) | 3163 | for (tail = Fget_buffer_xwidgets (buffer); CONSP (tail); tail = XCDR (tail)) |
| 3146 | { | 3164 | { |
| 3147 | xwidget = XCAR (tail); | 3165 | xwidget = XCAR (tail); |
| 3148 | internal_xwidget_list = Fdelq (xwidget, internal_xwidget_list); | ||
| 3149 | Vxwidget_list = Fcopy_sequence (internal_xwidget_list); | ||
| 3150 | { | 3166 | { |
| 3151 | CHECK_LIVE_XWIDGET (xwidget); | 3167 | CHECK_LIVE_XWIDGET (xwidget); |
| 3152 | struct xwidget *xw = XXWIDGET (xwidget); | 3168 | struct xwidget *xw = XXWIDGET (xwidget); |