[gtk+/wip/cssvalue: 33/141] stylecontext: Really queue style changes



commit b7eb21dc49777af0e843a9a0acce1d600f78d09b
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 23 03:01:16 2012 +0100

    stylecontext: Really queue style changes
    
    Instead of instantly applying a new style, just mark the context as
    invalid. Only apply the new style at layout time.

 gtk/gtkcontainer.c           |    3 ++
 gtk/gtkstylecontext.c        |   69 +++++++++++++++++++++++++++++++++++++----
 gtk/gtkstylecontextprivate.h |    2 +
 3 files changed, 67 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 275ee28..c5838ce 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -46,6 +46,7 @@
 #include "gtkwindow.h"
 #include "gtkassistant.h"
 #include "gtkintl.h"
+#include "gtkstylecontextprivate.h"
 #include "gtkwidgetpath.h"
 #include "a11y/gtkcontaineraccessible.h"
 
@@ -1768,6 +1769,8 @@ gtk_container_check_resize (GtkContainer *container)
 {
   g_return_if_fail (GTK_IS_CONTAINER (container));
 
+  _gtk_style_context_validate (gtk_widget_get_style_context (GTK_WIDGET (container)), 0);
+
   g_signal_emit (container, container_signals[CHECK_RESIZE], 0);
 }
 
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 31bc366..495e31b 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -381,9 +381,11 @@ struct _GtkStyleContextPrivate
   GtkTextDirection direction;
 
   GtkCssChange relevant_changes;
+  GtkCssChange pending_changes;
 
   guint animations_invalidated : 1;
   guint invalidating_context : 1;
+  guint invalid : 1;
 };
 
 enum {
@@ -1022,6 +1024,28 @@ style_data_lookup (GtkStyleContext *context,
   return data;
 }
 
+static void
+gtk_style_context_set_invalid (GtkStyleContext *context,
+                               gboolean         invalid)
+{
+  GtkStyleContextPrivate *priv;
+  
+  priv = context->priv;
+
+  if (priv->invalid == invalid)
+    return;
+
+  priv->invalid = invalid;
+
+  if (invalid)
+    {
+      if (priv->widget)
+        gtk_widget_queue_resize (priv->widget);
+      if (priv->parent)
+        gtk_style_context_set_invalid (priv->parent, TRUE);
+    }
+}
+
 /* returns TRUE if someone called gtk_style_context_save() but hasn't
  * called gtk_style_context_restore() yet.
  * In those situations we don't invalidate the context when somebody
@@ -1624,6 +1648,8 @@ gtk_style_context_set_parent (GtkStyleContext *context,
     {
       parent->priv->children = g_slist_prepend (parent->priv->children, context);
       g_object_ref (parent);
+      if (priv->invalid)
+        gtk_style_context_set_invalid (parent, TRUE);
     }
 
   if (priv->parent)
@@ -3246,19 +3272,24 @@ store_animation_region (GtkStyleContext *context,
 }
 
 void
-_gtk_style_context_queue_invalidate (GtkStyleContext *context,
-                                     GtkCssChange     change)
+_gtk_style_context_validate (GtkStyleContext *context,
+                             GtkCssChange     change)
 {
   GtkStyleContextPrivate *priv;
+  GSList *list;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
-  g_return_if_fail (change != 0);
 
   priv = context->priv;
 
-  if (priv->widget == NULL && priv->widget_path == NULL)
+  change |= priv->pending_changes;
+
+  if (!priv->invalid && change == 0)
     return;
 
+  priv->pending_changes = 0;
+  gtk_style_context_set_invalid (context, FALSE);
+
   /* Try to avoid invalidating if we can */
   if (change & GTK_STYLE_CONTEXT_RADICAL_CHANGE)
     {
@@ -3280,12 +3311,36 @@ _gtk_style_context_queue_invalidate (GtkStyleContext *context,
 
           gtk_widget_path_unref (path);
         }
+    }
 
-      if ((priv->relevant_changes & change) == 0)
-        return;
+  if (priv->relevant_changes & change)
+    {
+      gtk_style_context_invalidate (context);
     }
 
-  gtk_style_context_invalidate (context);
+  change = _gtk_css_change_for_child (change);
+  for (list = priv->children; list; list = list->next)
+    {
+      _gtk_style_context_validate (list->data, change);
+    }
+}
+
+void
+_gtk_style_context_queue_invalidate (GtkStyleContext *context,
+                                     GtkCssChange     change)
+{
+  GtkStyleContextPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
+  g_return_if_fail (change != 0);
+
+  priv = context->priv;
+
+  if (priv->widget == NULL && priv->widget_path == NULL)
+    return;
+
+  priv->pending_changes |= change;
+  gtk_style_context_set_invalid (context, TRUE);
 }
 
 /**
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 41789cd..759929e 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -35,6 +35,8 @@ const GValue * _gtk_style_context_peek_style_property        (GtkStyleContext *c
                                                               GType            widget_type,
                                                               GtkStateFlags    state,
                                                               GParamSpec      *pspec);
+void           _gtk_style_context_validate                   (GtkStyleContext *context,
+                                                              GtkCssChange     change);
 void           _gtk_style_context_queue_invalidate           (GtkStyleContext *context,
                                                               GtkCssChange     change);
 void           _gtk_style_context_invalidate_animation_areas (GtkStyleContext *context);



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