@end table
@cindex @code{xwidget-display-event} event
-@item (xwidget-display-event @var{xwidget})
+@item (xwidget-display-event @var{xwidget} @var{source})
This event is sent whenever an xwidget requests that another xwidget
-be displayed. @var{xwidget} is the xwidget that should be displayed.
+be displayed. @var{xwidget} is the xwidget that should be displayed,
+and @var{source} is the xwidget that asked to display @var{xwidget}.
+
+It is also a special event which should be handled through callbacks.
+You can add such a callback by setting the @code{display-callback} of
+@var{source}'s property list, which should be a function that accepts
+@var{xwidget} and @var{source} as arguments.
@var{xwidget}'s buffer will be set to a temporary buffer. When
displaying the widget, care should be taken to replace the buffer with
+++
*** New event type 'xwidget-display-event'.
These events are sent whenever an xwidget requests that Emacs display
-another xwidget. The only argument to this event is the xwidget that
-should be displayed.
+another xwidget. The only arguments to this event are the xwidget
+that should be displayed, and the xwidget that asked to display it.
+++
*** New function 'xwidget-webkit-set-cookie-storage-file'.
(xwidget-webkit-set-cookie-storage-file
xw (expand-file-name xwidget-webkit-cookie-file)))
(xwidget-put xw 'callback callback)
+ (xwidget-put xw 'display-callback #'xwidget-webkit-display-callback)
(xwidget-webkit-mode)
(xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
(put-text-property (point-min) (point-max)
'display (list 'xwidget :xwidget xwidget)))
(xwidget-put xwidget 'callback callback)
+ (xwidget-put xwidget 'display-callback
+ #'xwidget-webkit-display-callback)
(set-xwidget-buffer xwidget buffer)
(xwidget-webkit-mode))
buffer))
(defun xwidget-webkit-display-event (event)
- "Import the xwidget inside EVENT and display it."
+ "Trigger display callback for EVENT."
(interactive "e")
- (display-buffer (xwidget-webkit-import-widget (nth 1 event))))
+ (let ((xwidget (cadr event))
+ (source (caddr event)))
+ (when (xwidget-get source 'display-callback)
+ (funcall (xwidget-get source 'display-callback)
+ xwidget source))))
-(global-set-key [xwidget-display-event] 'xwidget-webkit-display-event)
+(defun xwidget-webkit-display-callback (xwidget _source)
+ "Import XWIDGET and display it."
+ (display-buffer (xwidget-webkit-import-widget xwidget)))
+
+(define-key special-event-map [xwidget-display-event] 'xwidget-webkit-display-event)
(defun xwidget-webkit-goto-url (url)
"Goto URL with xwidget webkit."
return Fcons (Qxwidget_event, event->arg);
case XWIDGET_DISPLAY_EVENT:
- return list2 (Qxwidget_display_event, event->arg);
+ return Fcons (Qxwidget_display_event, event->arg);
#endif
#ifdef USE_FILE_NOTIFY
#ifdef USE_GTK
static void
-store_xwidget_display_event (struct xwidget *xw)
+store_xwidget_display_event (struct xwidget *xw,
+ struct xwidget *src)
{
struct input_event evt;
- Lisp_Object val;
+ Lisp_Object val, src_val;
XSETXWIDGET (val, xw);
+ XSETXWIDGET (src_val, src);
EVENT_INIT (evt);
evt.kind = XWIDGET_DISPLAY_EVENT;
evt.frame_or_window = Qnil;
- evt.arg = val;
+ evt.arg = list2 (val, src_val);
kbd_buffer_store_event (&evt);
}
{
Lisp_Object tem;
struct xwidget *xw;
+ struct xwidget *src;
+
+ src = find_xwidget_for_offscreen_window (GDK_WINDOW (user_data));
for (tem = internal_xwidget_list; CONSP (tem); tem = XCDR (tem))
{
if (EQ (xw->type, Qwebkit)
&& WEBKIT_WEB_VIEW (xw->widget_osr) == new_view)
- store_xwidget_display_event (xw);
+ {
+ /* The source widget was destroyed before we had a
+ chance to display the new widget. */
+ if (!src)
+ kill_xwidget (xw);
+ else
+ store_xwidget_display_event (xw, src);
+ }
}
}
}
static GtkWidget *
webkit_create_cb_1 (WebKitWebView *webview,
- struct xwidget_view *xv)
+ struct xwidget *xv)
{
Lisp_Object related;
Lisp_Object xwidget;
widget = XXWIDGET (xwidget)->widget_osr;
g_signal_connect (G_OBJECT (widget), "ready-to-show",
- G_CALLBACK (webkit_ready_to_show), NULL);
+ G_CALLBACK (webkit_ready_to_show),
+ gtk_widget_get_window (xv->widgetwindow_osr));
return widget;
}
newview = WEBKIT_WEB_VIEW (XXWIDGET (new_xwidget)->widget_osr);
webkit_web_view_load_request (newview, request);
- store_xwidget_display_event (XXWIDGET (new_xwidget));
+ store_xwidget_display_event (XXWIDGET (new_xwidget), xw);
return TRUE;
}
case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION:
static void
kill_xwidget (struct xwidget *xw)
{
+ Lisp_Object val;
+ XSETXWIDGET (val, xw);
+
+ internal_xwidget_list = Fdelq (val, internal_xwidget_list);
+ Vxwidget_list = Fcopy_sequence (internal_xwidget_list);
#ifdef USE_GTK
xw->buffer = Qnil;
for (tail = Fget_buffer_xwidgets (buffer); CONSP (tail); tail = XCDR (tail))
{
xwidget = XCAR (tail);
- internal_xwidget_list = Fdelq (xwidget, internal_xwidget_list);
- Vxwidget_list = Fcopy_sequence (internal_xwidget_list);
{
CHECK_LIVE_XWIDGET (xwidget);
struct xwidget *xw = XXWIDGET (xwidget);