[gtkhtml] Bug #689476 - Slow composer open (emoticon and color widget leaks)



commit 9026ede3104cc70008060fcca2402201fc8f841e
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jan 30 12:03:28 2013 +0100

    Bug #689476 - Slow composer open (emoticon and color widget leaks)

 components/editor/gtkhtml-color-combo.c      |   27 +++++++++++++++++------
 components/editor/gtkhtml-face-tool-button.c |   30 +++++++++++++++++++-------
 2 files changed, 42 insertions(+), 15 deletions(-)
---
diff --git a/components/editor/gtkhtml-color-combo.c b/components/editor/gtkhtml-color-combo.c
index d30ee54..cd4d664 100644
--- a/components/editor/gtkhtml-color-combo.c
+++ b/components/editor/gtkhtml-color-combo.c
@@ -120,6 +120,8 @@ static struct {
 	{ "#FFFFFF", N_("white") }
 };
 
+static void color_combo_build_popup_window (GtkhtmlColorCombo *combo);
+
 static void
 color_combo_notify_current_color_cb (GtkhtmlColorCombo *combo)
 {
@@ -574,7 +576,7 @@ color_combo_dispose (GObject *object)
 	}
 
 	if (priv->window != NULL) {
-		g_object_unref (priv->window);
+		gtk_widget_destroy (priv->window);
 		priv->window = NULL;
 	}
 
@@ -653,6 +655,9 @@ color_combo_popup (GtkhtmlColorCombo *combo)
 	if (combo->priv->popup_shown)
 		return;
 
+	if (!combo->priv->window)
+		color_combo_build_popup_window (combo);
+
 	activate_time = gtk_get_current_event_time ();
 	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
 		keyboard = device;
@@ -875,11 +880,8 @@ static void
 color_combo_init (GtkhtmlColorCombo *combo)
 {
 	GtkhtmlColorState *state;
-	GtkWidget *toplevel;
 	GtkWidget *container;
 	GtkWidget *widget;
-	GtkWidget *window;
-	guint ii;
 
 	combo->priv = G_TYPE_INSTANCE_GET_PRIVATE (
 		combo, GTKHTML_TYPE_COLOR_COMBO, GtkhtmlColorComboPrivate);
@@ -925,22 +927,33 @@ color_combo_init (GtkhtmlColorCombo *combo)
 	g_signal_connect_swapped (
 		combo->priv->toggle_button, "toggled",
 		G_CALLBACK (color_combo_toggled_cb), combo);
+}
 
-	/* Build the pop-up window. */
+static void
+color_combo_build_popup_window (GtkhtmlColorCombo *combo)
+{
+	GtkWidget *toplevel;
+	GtkWidget *container;
+	GtkWidget *widget;
+	GtkWidget *window;
+	guint ii;
+
+	g_return_if_fail (combo->priv->window == NULL);
 
 	window = gtk_window_new (GTK_WINDOW_POPUP);
 	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (combo));
 	gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
 	gtk_window_set_type_hint (
 		GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_COMBO);
-	if (gtk_widget_is_toplevel (toplevel)) {
+	if (GTK_IS_WINDOW (toplevel)) {
 		gtk_window_group_add_window (
 			gtk_window_get_group (GTK_WINDOW (toplevel)),
 			GTK_WINDOW (window));
 		gtk_window_set_transient_for (
 			GTK_WINDOW (window), GTK_WINDOW (toplevel));
 	}
-	combo->priv->window = g_object_ref (window);
+
+	combo->priv->window = window;
 
 	g_signal_connect_swapped (
 		window, "show",
diff --git a/components/editor/gtkhtml-face-tool-button.c b/components/editor/gtkhtml-face-tool-button.c
index 576f7dd..0ba31e3 100644
--- a/components/editor/gtkhtml-face-tool-button.c
+++ b/components/editor/gtkhtml-face-tool-button.c
@@ -60,6 +60,8 @@ struct _GtkhtmlFaceToolButtonPrivate {
 static gpointer parent_class;
 static guint signals[LAST_SIGNAL];
 
+static void face_tool_button_build_popup_window (GtkhtmlFaceToolButton *button);
+
 /* XXX Copied from _gtk_toolbar_elide_underscores() */
 static gchar *
 face_tool_button_elide_underscores (const gchar *original)
@@ -273,8 +275,13 @@ face_tool_button_dispose (GObject *object)
 
 	priv = GTKHTML_FACE_TOOL_BUTTON (object)->priv;
 
+	if (priv->table != NULL) {
+		g_object_unref (priv->table);
+		priv->table = NULL;
+	}
+
 	if (priv->window != NULL) {
-		g_object_unref (priv->window);
+		gtk_widget_destroy (priv->window);
 		priv->window = NULL;
 	}
 
@@ -340,6 +347,9 @@ face_tool_button_popup (GtkhtmlFaceToolButton *button)
 	if (button->priv->popup_shown)
 		return;
 
+	if (!button->priv->window)
+		face_tool_button_build_popup_window (button);
+
 	activate_time = gtk_get_current_event_time ();
 	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
 		keyboard = device;
@@ -538,6 +548,14 @@ face_tool_button_iface_init (GtkhtmlFaceChooserIface *iface)
 static void
 face_tool_button_init (GtkhtmlFaceToolButton *button)
 {
+	button->priv = G_TYPE_INSTANCE_GET_PRIVATE (
+		button, GTKHTML_TYPE_FACE_TOOL_BUTTON,
+		GtkhtmlFaceToolButtonPrivate);
+}
+
+static void
+face_tool_button_build_popup_window (GtkhtmlFaceToolButton *button)
+{
 	GtkhtmlFaceChooser *chooser;
 	GtkWidget *toplevel;
 	GtkWidget *container;
@@ -546,25 +564,21 @@ face_tool_button_init (GtkhtmlFaceToolButton *button)
 	GList *list, *iter;
 	gint ii;
 
-	button->priv = G_TYPE_INSTANCE_GET_PRIVATE (
-		button, GTKHTML_TYPE_FACE_TOOL_BUTTON,
-		GtkhtmlFaceToolButtonPrivate);
-
-	/* Build the pop-up window. */
+	g_return_if_fail (button->priv->window == NULL);
 
 	window = gtk_window_new (GTK_WINDOW_POPUP);
 	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
 	gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
 	gtk_window_set_type_hint (
 		GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_COMBO);
-	if (gtk_widget_is_toplevel (toplevel)) {
+	if (GTK_IS_WINDOW (toplevel)) {
 		gtk_window_group_add_window (
 			gtk_window_get_group (GTK_WINDOW (toplevel)),
 			GTK_WINDOW (window));
 		gtk_window_set_transient_for (
 			GTK_WINDOW (window), GTK_WINDOW (toplevel));
 	}
-	button->priv->window = g_object_ref (window);
+	button->priv->window = window;
 
 	g_signal_connect_swapped (
 		window, "show",



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