Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
stylecontext: Redo handling of differing state
Instead of passing an "override_state" flag, create a new CssNode just
for this simple lookup.
  • Loading branch information
Benjamin Otte committed Mar 18, 2015
1 parent 637a4bd commit c4b88e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 0 additions & 6 deletions gtk/gtkcssnode.c
Expand Up @@ -365,12 +365,6 @@ gtk_css_node_get_declaration (GtkCssNode *cssnode)
return cssnode->decl;
}

GtkCssNodeDeclaration *
gtk_css_node_dup_declaration (GtkCssNode *cssnode)
{
return gtk_css_node_declaration_ref (cssnode->decl);
}

void
gtk_css_node_invalidate (GtkCssNode *cssnode,
GtkCssChange change)
Expand Down
1 change: 0 additions & 1 deletion gtk/gtkcssnodeprivate.h
Expand Up @@ -108,7 +108,6 @@ GList * gtk_css_node_list_regions (GtkCssNode *

const GtkCssNodeDeclaration *
gtk_css_node_get_declaration (GtkCssNode *cssnode);
GtkCssNodeDeclaration * gtk_css_node_dup_declaration (GtkCssNode *cssnode);


GtkCssStyle * gtk_css_node_get_style (GtkCssNode *cssnode);
Expand Down
43 changes: 26 additions & 17 deletions gtk/gtkstylecontext.c
Expand Up @@ -754,9 +754,7 @@ update_properties (GtkCssNode *cssnode,
}

static GtkCssStyle *
build_properties (GtkCssNode *cssnode,
gboolean override_state,
GtkStateFlags state)
build_properties (GtkCssNode *cssnode)
{
const GtkCssNodeDeclaration *decl;
GtkCssMatcher matcher;
Expand All @@ -772,8 +770,6 @@ build_properties (GtkCssNode *cssnode,
return g_object_ref (style);

path = gtk_css_node_create_widget_path (cssnode);
if (override_state)
gtk_widget_path_iter_set_state (path, -1, state);

if (_gtk_css_matcher_init (&matcher, path))
style = gtk_css_static_style_new_compute (gtk_css_node_get_style_provider (cssnode),
Expand Down Expand Up @@ -806,7 +802,7 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
if (values)
return values;

values = build_properties (cssnode, FALSE, 0);
values = build_properties (cssnode);

gtk_css_node_set_style (cssnode, values);
g_object_unref (values);
Expand All @@ -818,20 +814,35 @@ static GtkCssStyle *
gtk_style_context_lookup_style_for_state (GtkStyleContext *context,
GtkStateFlags state)
{
GtkCssNodeDeclaration *decl;
GtkCssNode *node;
GtkCssStyle *values;

if (gtk_css_node_get_state (context->priv->cssnode) == state)
return g_object_ref (gtk_style_context_lookup_style (context));

if (g_getenv ("GTK_STYLE_CONTEXT_WARNING"))
g_warning ("State does not match current state");
{
GtkCssNode *root = gtk_style_context_get_root (context);

if (GTK_IS_CSS_WIDGET_NODE (root))
{
GtkWidget *widget = gtk_css_widget_node_get_widget (GTK_CSS_WIDGET_NODE (root));
g_warning ("State %u for %s %p doesn't match state %u set via gtk_style_context_set_state ()",
state, gtk_widget_get_name (widget), widget, gtk_css_node_get_state (context->priv->cssnode));
}
else
{
g_warning ("State %u for context %p doesn't match state %u set via gtk_style_context_set_state ()",
state, context, gtk_css_node_get_state (context->priv->cssnode));
}
}

decl = gtk_css_node_dup_declaration (context->priv->cssnode);
gtk_css_node_declaration_set_state (&decl, state);
values = build_properties (context->priv->cssnode,
TRUE, state);
gtk_css_node_declaration_unref (decl);
node = gtk_css_transient_node_new (context->priv->cssnode);
gtk_css_node_set_parent (node, gtk_css_node_get_parent (context->priv->cssnode));
gtk_css_node_set_state (node, state);
values = build_properties (node);
gtk_css_node_set_parent (node, NULL);
g_object_unref (node);

return values;
}
Expand Down Expand Up @@ -2823,7 +2834,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
{
GtkCssStyle *style, *static_style;

static_style = build_properties (cssnode, FALSE, 0);
static_style = build_properties (cssnode);
style = gtk_css_animated_style_new (static_style,
priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL,
timestamp,
Expand Down Expand Up @@ -2916,9 +2927,7 @@ gtk_style_context_invalidate (GtkStyleContext *context)
gtk_css_node_set_style (context->priv->cssnode, NULL);

root = gtk_style_context_get_root (context);
style = build_properties (root,
FALSE,
0);
style = build_properties (root);
gtk_css_node_set_style (root, style);
g_object_unref (style);

Expand Down

0 comments on commit c4b88e0

Please sign in to comment.