[gtk+/wip/css: 8/154] stylecontext: Separate properties by states



commit 92875ac7227cd9e334ead429e602e1c30e0ae0f7
Author: Benjamin Otte <otte redhat com>
Date:   Tue Dec 27 20:41:25 2011 +0100

    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 files changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index eaff91b..d4f909a 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;
 }



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