From 899a381d31fa8f94466bc38e4d77a7f0d9498b9f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 27 Dec 2011 20:41:25 +0100 Subject: [PATCH] stylecontext: Separate properties by states We don't want to mix states the wrong way. And the current approach does that. --- gtk/gtkstylecontext.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index eaff91bccc..d4f909a818 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -513,7 +513,7 @@ style_info_hash (gconstpointer elem) hash <<= 5; } - return hash; + return hash ^ info->state_flags; } static gboolean @@ -525,6 +525,9 @@ style_info_equal (gconstpointer elem1, info1 = elem1; info2 = elem2; + if (info1->state_flags != info2->state_flags) + return FALSE; + if (info1->junction_sides != info2->junction_sides) return FALSE; @@ -1015,15 +1018,23 @@ style_data_lookup (GtkStyleContext *context, { GtkStyleContextPrivate *priv; StyleData *data; + gboolean state_mismatch; priv = context->priv; + state_mismatch = ((GtkStyleInfo *) priv->info_stack->data)->state_flags != state; /* Current data in use is cached, just return it */ - if (priv->current_data) + if (priv->current_data && !state_mismatch) return priv->current_data; g_assert (priv->widget_path != NULL); + if (G_UNLIKELY (state_mismatch)) + { + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + } + data = g_hash_table_lookup (priv->style_data, priv->info_stack->data); if (!data) @@ -1043,17 +1054,25 @@ style_data_lookup (GtkStyleContext *context, gtk_widget_path_free (path); } - priv->current_data = data; + if (G_UNLIKELY (state_mismatch)) + { + gtk_style_context_restore (context); + priv->current_data = NULL; + } + else + { + priv->current_data = data; - if (priv->theming_engine) - g_object_unref (priv->theming_engine); + if (priv->theming_engine) + g_object_unref (priv->theming_engine); - gtk_style_properties_get (data->store, 0, - "engine", &priv->theming_engine, - NULL); + gtk_style_properties_get (data->store, 0, + "engine", &priv->theming_engine, + NULL); - if (!priv->theming_engine) - priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL)); + if (!priv->theming_engine) + priv->theming_engine = g_object_ref (gtk_theming_engine_load (NULL)); + } return data; }