From 55e68bc2ea2200090527c791be8aa126742a776d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 28 Jan 2015 05:14:47 +0100 Subject: [PATCH] cssnode: Track invalid flag Remove it from GtkStyleContext. --- gtk/gtkcssnode.c | 26 ++++++++++++++++++++++++++ gtk/gtkcssnodeprivate.h | 6 ++++++ gtk/gtkcsspathnode.c | 8 ++++++++ gtk/gtkcsstransientnode.c | 8 ++++++++ gtk/gtkcsswidgetnode.c | 24 +++++++++++++++++++----- gtk/gtkstylecontext.c | 34 ++-------------------------------- gtk/gtkstylecontextprivate.h | 2 -- 7 files changed, 69 insertions(+), 39 deletions(-) diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c index fd4c88feab..891cf1f920 100644 --- a/gtk/gtkcssnode.c +++ b/gtk/gtkcssnode.c @@ -23,6 +23,16 @@ G_DEFINE_TYPE (GtkCssNode, gtk_css_node, G_TYPE_OBJECT) +void +gtk_css_node_set_invalid (GtkCssNode *node, + gboolean invalid) +{ + if (node->invalid == invalid) + return; + + GTK_CSS_NODE_GET_CLASS (node)->set_invalid (node, invalid); +} + static void gtk_css_node_dispose (GObject *object) { @@ -54,6 +64,16 @@ gtk_css_node_real_invalidate (GtkCssNode *cssnode, { } +static void +gtk_css_node_real_set_invalid (GtkCssNode *node, + gboolean invalid) +{ + node->invalid = invalid; + + if (invalid && node->parent) + gtk_css_node_set_invalid (node->parent, invalid); +} + static GtkWidgetPath * gtk_css_node_real_create_widget_path (GtkCssNode *cssnode) { @@ -75,6 +95,7 @@ gtk_css_node_class_init (GtkCssNodeClass *klass) object_class->finalize = gtk_css_node_finalize; klass->invalidate = gtk_css_node_real_invalidate; + klass->set_invalid = gtk_css_node_real_set_invalid; klass->create_widget_path = gtk_css_node_real_create_widget_path; klass->get_widget_path = gtk_css_node_real_get_widget_path; } @@ -137,6 +158,9 @@ gtk_css_node_set_parent (GtkCssNode *node, if (parent->first_child == NULL) parent->first_child = node; } + + if (node->invalid) + gtk_css_node_set_invalid (parent, TRUE); } gtk_css_node_invalidate (node, GTK_CSS_CHANGE_ANY_PARENT | GTK_CSS_CHANGE_ANY_SIBLING); @@ -330,6 +354,8 @@ gtk_css_node_invalidate (GtkCssNode *cssnode, GtkCssChange change) { GTK_CSS_NODE_GET_CLASS (cssnode)->invalidate (cssnode, change); + + gtk_css_node_set_invalid (cssnode, TRUE); } GtkWidgetPath * diff --git a/gtk/gtkcssnodeprivate.h b/gtk/gtkcssnodeprivate.h index c00c8754da..873ba67ba1 100644 --- a/gtk/gtkcssnodeprivate.h +++ b/gtk/gtkcssnodeprivate.h @@ -46,6 +46,8 @@ struct _GtkCssNode GtkCssNodeDeclaration *decl; GtkCssStyle *style; + + guint invalid :1; /* set if node or a child is invalid */ }; struct _GtkCssNodeClass @@ -56,6 +58,8 @@ struct _GtkCssNodeClass const GtkWidgetPath * (* get_widget_path) (GtkCssNode *cssnode); void (* invalidate) (GtkCssNode *cssnode, GtkCssChange change); + void (* set_invalid) (GtkCssNode *node, + gboolean invalid); }; GType gtk_css_node_get_type (void) G_GNUC_CONST; @@ -108,6 +112,8 @@ void gtk_css_node_set_style (GtkCssNode * void gtk_css_node_invalidate (GtkCssNode *cssnode, GtkCssChange change); +void gtk_css_node_set_invalid (GtkCssNode *node, + gboolean invalid); GtkWidgetPath * gtk_css_node_create_widget_path (GtkCssNode *cssnode); const GtkWidgetPath * gtk_css_node_get_widget_path (GtkCssNode *cssnode); diff --git a/gtk/gtkcsspathnode.c b/gtk/gtkcsspathnode.c index 2463dc0913..52c5a4a9c0 100644 --- a/gtk/gtkcsspathnode.c +++ b/gtk/gtkcsspathnode.c @@ -39,6 +39,13 @@ gtk_css_path_node_invalidate (GtkCssNode *node, } } +static void +gtk_css_path_node_set_invalid (GtkCssNode *node, + gboolean invalid) +{ + /* path nodes are always valid */ +} + static GtkWidgetPath * gtk_css_path_node_real_create_widget_path (GtkCssNode *node) { @@ -76,6 +83,7 @@ gtk_css_path_node_class_init (GtkCssPathNodeClass *klass) GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass); node_class->invalidate = gtk_css_path_node_invalidate; + node_class->set_invalid = gtk_css_path_node_set_invalid; node_class->create_widget_path = gtk_css_path_node_real_create_widget_path; node_class->get_widget_path = gtk_css_path_node_real_get_widget_path; } diff --git a/gtk/gtkcsstransientnode.c b/gtk/gtkcsstransientnode.c index 726a4854b5..ef553f67c9 100644 --- a/gtk/gtkcsstransientnode.c +++ b/gtk/gtkcsstransientnode.c @@ -29,6 +29,13 @@ gtk_css_transient_node_invalidate (GtkCssNode *node, gtk_css_node_set_style (node, NULL); } +static void +gtk_css_transient_node_set_invalid (GtkCssNode *node, + gboolean invalid) +{ + /* transient nodes are always valid */ +} + static GtkWidgetPath * gtk_css_transient_node_create_widget_path (GtkCssNode *node) { @@ -65,6 +72,7 @@ gtk_css_transient_node_class_init (GtkCssTransientNodeClass *klass) GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass); node_class->invalidate = gtk_css_transient_node_invalidate; + node_class->set_invalid = gtk_css_transient_node_set_invalid; node_class->create_widget_path = gtk_css_transient_node_create_widget_path; node_class->get_widget_path = gtk_css_transient_node_get_widget_path; } diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c index dd0a105045..e49a5609ed 100644 --- a/gtk/gtkcsswidgetnode.c +++ b/gtk/gtkcsswidgetnode.c @@ -18,6 +18,8 @@ #include "config.h" #include "gtkcsswidgetnodeprivate.h" + +#include "gtkcontainerprivate.h" #include "gtkprivate.h" #include "gtkstylecontextprivate.h" #include "gtkwidgetprivate.h" @@ -29,15 +31,26 @@ gtk_css_widget_node_invalidate (GtkCssNode *node, GtkCssChange change) { GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node); - GtkStyleContext *context; widget_node->pending_changes |= change; +} - if (widget_node->widget == NULL) - return; +static void +gtk_css_widget_node_set_invalid (GtkCssNode *node, + gboolean invalid) +{ + GtkCssWidgetNode *widget_node = GTK_CSS_WIDGET_NODE (node); - context = gtk_widget_get_style_context (widget_node->widget); - gtk_style_context_set_invalid (context, TRUE); + GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->set_invalid (node, invalid); + + G_GNUC_BEGIN_IGNORE_DEPRECATIONS + if (invalid && + gtk_css_node_get_parent (node) == NULL && + GTK_IS_RESIZE_CONTAINER (widget_node->widget)) + { + _gtk_container_queue_restyle (GTK_CONTAINER (widget_node->widget)); + } + G_GNUC_END_IGNORE_DEPRECATIONS } static GtkWidgetPath * @@ -80,6 +93,7 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass) GtkCssNodeClass *node_class = GTK_CSS_NODE_CLASS (klass); node_class->invalidate = gtk_css_widget_node_invalidate; + node_class->set_invalid = gtk_css_widget_node_set_invalid; node_class->create_widget_path = gtk_css_widget_node_create_widget_path; node_class->get_widget_path = gtk_css_widget_node_get_widget_path; } diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index a25b6f0825..32f1fc7cbc 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -163,7 +163,6 @@ struct _GtkStyleContextPrivate const GtkBitmask *invalidating_context; guint animating : 1; - guint invalid : 1; }; enum { @@ -838,33 +837,6 @@ gtk_style_context_lookup_style_for_state (GtkStyleContext *context, return values; } -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) - { - GtkWidget *widget; - - G_GNUC_BEGIN_IGNORE_DEPRECATIONS; - if (GTK_IS_CSS_WIDGET_NODE (priv->cssnode) && - GTK_IS_RESIZE_CONTAINER (widget = gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (priv->cssnode)))) - _gtk_container_queue_restyle (GTK_CONTAINER (widget)); - else if (priv->parent) - gtk_style_context_set_invalid (priv->parent, TRUE); - G_GNUC_END_IGNORE_DEPRECATIONS; - } -} - /** * gtk_style_context_new: * @@ -1505,8 +1477,6 @@ 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); gtk_css_node_set_parent (gtk_style_context_get_root (context), gtk_style_context_get_root (parent)); } @@ -2883,10 +2853,10 @@ _gtk_style_context_validate (GtkStyleContext *context, if (G_UNLIKELY (gtk_get_debug_flags () & GTK_DEBUG_NO_CSS_CACHE)) change = GTK_CSS_CHANGE_ANY; - if (!priv->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes)) + if (!cssnode->invalid && change == 0 && _gtk_bitmask_is_empty (parent_changes)) return; - gtk_style_context_set_invalid (context, FALSE); + gtk_css_node_set_invalid (cssnode, FALSE); current = gtk_css_node_get_style (cssnode); if (current == NULL) diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h index 69996243e8..a520bf73b2 100644 --- a/gtk/gtkstylecontextprivate.h +++ b/gtk/gtkstylecontextprivate.h @@ -48,8 +48,6 @@ void _gtk_style_context_validate (GtkStyleContext *c const GtkBitmask*parent_changes); void _gtk_style_context_queue_invalidate (GtkStyleContext *context, GtkCssChange change); -void gtk_style_context_set_invalid (GtkStyleContext *context, - gboolean invalid); gboolean _gtk_style_context_check_region_name (const gchar *str); gboolean _gtk_style_context_resolve_color (GtkStyleContext *context,