[Nautilus-list] Mozilla dialog patch



This is a patch from blizzard that makes it possible for the mozilla 
component to open dialogs. This was needed to make submitting forms work.

This works with the patched Mozilla 0.9.2 in redhat. I'm unsure if it will 
compile with Mozilla 0.9.3. That needs to be tested before this goes into 
HEAD.

I think Darin uses Mozilla 0.9.3, could you try this patch?

/ Alex

Index: components/mozilla/nautilus-mozilla-content-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/components/mozilla/nautilus-mozilla-content-view.c,v
retrieving revision 1.99
retrieving revision 1.99.2.2
diff -u -p -r1.99 -r1.99.2.2
--- components/mozilla/nautilus-mozilla-content-view.c	2001/07/15 08:54:10	1.99
+++ components/mozilla/nautilus-mozilla-content-view.c	2001/08/17 21:44:26	1.99.2.2
@@ -110,8 +110,17 @@ struct NautilusMozillaContentViewDetails
 	gboolean	user_initiated_navigation;
 
 	BonoboUIComponent *ui;
+
+	GSList            *chrome_list;
+
 };
 
+typedef struct NautilusMozillaContentViewChrome {
+	GtkWidget                   *toplevel_window;
+	GtkMozEmbed                 *mozilla;
+	NautilusMozillaContentView  *view;
+} NautilusMozillaContentViewChrome;
+
 /* GTK Type System */
 static void     nautilus_mozilla_content_view_initialize_class (NautilusMozillaContentViewClass *klass);
 static void     nautilus_mozilla_content_view_initialize       (NautilusMozillaContentView      *view);
@@ -173,8 +182,28 @@ static gint	mozilla_dom_mouse_click_call
 								 gpointer			dom_event,
 								 gpointer			user_data);
 
-static void	mozilla_new_window_callback			(GtkMozEmbed			*mozilla);
+static void	mozilla_new_window_callback			(GtkMozEmbed			*mozilla,
+								 GtkMozEmbed                    **new_mozilla,
+								 guint                          chromemask,
+								 NautilusMozillaContentView     *view);
+
+/* Chrome callback functions */
+
+static void     mozilla_chrome_visibility_callback             (GtkMozEmbed                      *mozilla,
+								gboolean                         visibility,
+								NautilusMozillaContentViewChrome *chrome);
+
+static void     mozilla_chrome_destroy_brsr_callback           (GtkMozEmbed                      *mozilla,
+								NautilusMozillaContentViewChrome *chrome);
+
+static void     mozilla_chrome_size_to_callback                (GtkMozEmbed                      *mozilla,
+								gint                              width,
+								gint                              height,
+								NautilusMozillaContentViewChrome *chrome);
 
+static void     mozilla_chrome_title_callback                  (GtkMozEmbed                      *mozilla,
+								NautilusMozillaContentViewChrome *chrome);
+
 /* Private NautilusMozillaContentView functions */ 
 
 static char *	translate_uri_nautilus_to_mozilla 		(NautilusMozillaContentView 	*view,
@@ -425,6 +454,24 @@ nautilus_mozilla_content_view_destroy (G
 		bonobo_object_unref (BONOBO_OBJECT (view->details->property_bag));
 	}
 
+	/* make sure to destroy any pending dialogs */
+	while (view->details->chrome_list) {
+		NautilusMozillaContentViewChrome *chrome;
+		GSList *tmp_list;
+
+		/* save the list and advance to the next element */
+		tmp_list = view->details->chrome_list;
+		view->details->chrome_list = view->details->chrome_list->next;
+
+		/* get the chrome and destroy it */
+		chrome = (NautilusMozillaContentViewChrome *)tmp_list->data;
+		gtk_widget_destroy(chrome->toplevel_window);
+
+		/* and free everything */
+		g_free(tmp_list->data);
+		g_slist_free(tmp_list);
+	}
+
 	g_free (view->details);
 
 	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
@@ -824,10 +871,52 @@ mozilla_title_changed_callback (GtkMozEm
 }
 
 static void
-mozilla_new_window_callback (GtkMozEmbed *mozilla)
+mozilla_new_window_callback (GtkMozEmbed *mozilla, GtkMozEmbed **new_mozilla, guint chromemask, NautilusMozillaContentView *view)
 {
 	static GnomeDialog *dialog;
+	NautilusMozillaContentViewChrome *chrome;
+
+	/* it's a chrome window so just create a simple shell to play with. */
+	if (chromemask & GTK_MOZ_EMBED_FLAG_OPENASCHROME) {
+
+		chrome = g_new0 (NautilusMozillaContentViewChrome, 1);
+		if (!chrome) {
+			return;
+		}
 
+		/* save this in this view's chrome list */
+		view->details->chrome_list = g_slist_append(view->details->chrome_list, chrome);
+
+		chrome->view = view;
+
+		chrome->toplevel_window = gtk_window_new(GTK_WINDOW_DIALOG);
+		chrome->mozilla = GTK_MOZ_EMBED (gtk_moz_embed_new());
+
+		gtk_container_add(GTK_CONTAINER(chrome->toplevel_window), GTK_WIDGET(chrome->mozilla));
+
+		/* set up all the signals that we care about for chrome windows. */
+		gtk_signal_connect(GTK_OBJECT(chrome->mozilla), "visibility",
+				   GTK_SIGNAL_FUNC(mozilla_chrome_visibility_callback),
+				   chrome);
+		gtk_signal_connect(GTK_OBJECT(chrome->mozilla), "destroy_browser",
+				   GTK_SIGNAL_FUNC(mozilla_chrome_destroy_brsr_callback),
+				   chrome);
+		gtk_signal_connect(GTK_OBJECT(chrome->mozilla), "size_to",
+				   GTK_SIGNAL_FUNC(mozilla_chrome_size_to_callback),
+				   chrome);
+		gtk_signal_connect(GTK_OBJECT(chrome->mozilla), "title",
+				   GTK_SIGNAL_FUNC(mozilla_chrome_title_callback),
+				   chrome);
+
+		/* and realize the widgets */
+		gtk_widget_realize(chrome->toplevel_window);
+		gtk_widget_realize(GTK_WIDGET(chrome->mozilla));
+
+		/* save the new embed object */
+		*new_mozilla = chrome->mozilla;
+		return;
+	}
+
 	if (dialog == NULL) {
 		dialog = eel_show_warning_dialog (_("A JavaScript function (small software program) on this page "
 						    "tried to open a new window, but Nautilus does not support the "
@@ -836,6 +925,51 @@ mozilla_new_window_callback (GtkMozEmbed
 						  _("Nautilus JavaScript Warning"),
 						  NULL);
 		eel_nullify_when_destroyed (&dialog);
+	}
+}
+
+static void
+mozilla_chrome_visibility_callback (GtkMozEmbed *mozilla, gboolean visibility, NautilusMozillaContentViewChrome *chrome)
+{
+	/* hide? */
+	if (!visibility) {
+		gtk_widget_hide(chrome->toplevel_window);
+		return;
+	}
+	/* else show */
+	gtk_widget_show(GTK_WIDGET(chrome->mozilla));
+	gtk_widget_show(chrome->toplevel_window);
+}
+
+static void
+mozilla_chrome_destroy_brsr_callback (GtkMozEmbed *mozilla, NautilusMozillaContentViewChrome *chrome)
+{
+	GSList *tmp_list;
+	gtk_widget_destroy(chrome->toplevel_window);
+	tmp_list = g_slist_find(chrome->view->details->chrome_list, chrome);
+	chrome->view->details->chrome_list = g_slist_remove_link(chrome->view->details->chrome_list, tmp_list);
+	g_free(tmp_list->data);
+	g_slist_free(tmp_list);
+}
+
+static void
+mozilla_chrome_size_to_callback (GtkMozEmbed *mozilla, gint width, gint height,	NautilusMozillaContentViewChrome *chrome)
+{
+	gtk_widget_set_usize(GTK_WIDGET(chrome->mozilla), width, height);
+}
+
+static void
+mozilla_chrome_title_callback (GtkMozEmbed *mozilla, NautilusMozillaContentViewChrome *chrome)
+{
+	char *new_title;
+
+	new_title = gtk_moz_embed_get_title(chrome->mozilla);
+
+	if (new_title) {
+		if (strcmp(new_title, "") != 0) {
+			gtk_window_set_title(GTK_WINDOW(chrome->toplevel_window), new_title);
+		}
+		g_free(new_title);
 	}
 }
 





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]