stylecontext: Get rid of stylecontext argument

... to a bunch of functions.

This requires a tiny change to the heuristics for the style cache - we
now cache styles when they have the same style provider as their parent
instead of when they have the default provider - but that change doesn't
have any effect in practice.
This commit is contained in:
Benjamin Otte 2015-02-01 07:33:40 +01:00
parent 03ac5f310b
commit 637a4bda5c

View File

@ -283,8 +283,7 @@ gtk_style_context_clear_property_cache (GtkStyleContext *context)
} }
static GtkCssStyle * static GtkCssStyle *
gtk_css_node_get_parent_style (GtkStyleContext *context, gtk_css_node_get_parent_style (GtkCssNode *cssnode)
GtkCssNode *cssnode)
{ {
GtkCssNode *parent; GtkCssNode *parent;
@ -627,16 +626,22 @@ gtk_style_context_has_custom_cascade (GtkStyleContext *context)
} }
static gboolean static gboolean
may_use_global_parent_cache (GtkStyleContext *context) may_use_global_parent_cache (GtkCssNode *node)
{ {
if (gtk_style_context_has_custom_cascade (context)) GtkCssNode *parent;
parent = gtk_css_node_get_parent (node);
if (parent == NULL)
return FALSE;
if (gtk_css_node_get_style_provider (node) != gtk_css_node_get_style_provider (parent))
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
static GtkCssStyle * static GtkCssStyle *
lookup_in_global_parent_cache (GtkStyleContext *context, lookup_in_global_parent_cache (GtkCssNode *node,
GtkCssStyle *parent, GtkCssStyle *parent,
const GtkCssNodeDeclaration *decl) const GtkCssNodeDeclaration *decl)
{ {
@ -644,7 +649,7 @@ lookup_in_global_parent_cache (GtkStyleContext *context,
GtkCssStyle *style; GtkCssStyle *style;
if (parent == NULL || if (parent == NULL ||
!may_use_global_parent_cache (context)) !may_use_global_parent_cache (node))
return NULL; return NULL;
cache = g_object_get_data (G_OBJECT (parent), "gtk-global-cache"); cache = g_object_get_data (G_OBJECT (parent), "gtk-global-cache");
@ -679,7 +684,7 @@ may_be_stored_in_parent_cache (GtkCssStyle *style)
} }
static void static void
store_in_global_parent_cache (GtkStyleContext *context, store_in_global_parent_cache (GtkCssNode *node,
GtkCssStyle *parent, GtkCssStyle *parent,
const GtkCssNodeDeclaration *decl, const GtkCssNodeDeclaration *decl,
GtkCssStyle *style) GtkCssStyle *style)
@ -689,7 +694,7 @@ store_in_global_parent_cache (GtkStyleContext *context,
g_assert (GTK_IS_CSS_STATIC_STYLE (style)); g_assert (GTK_IS_CSS_STATIC_STYLE (style));
if (parent == NULL || if (parent == NULL ||
!may_use_global_parent_cache (context)) !may_use_global_parent_cache (node))
return; return;
if (!may_be_stored_in_parent_cache (style)) if (!may_be_stored_in_parent_cache (style))
@ -711,10 +716,9 @@ store_in_global_parent_cache (GtkStyleContext *context,
} }
static GtkCssStyle * static GtkCssStyle *
update_properties (GtkStyleContext *context, update_properties (GtkCssNode *cssnode,
GtkCssNode *cssnode, GtkCssStyle *style,
GtkCssStyle *style, const GtkBitmask *parent_changes)
const GtkBitmask *parent_changes)
{ {
const GtkCssNodeDeclaration *decl; const GtkCssNodeDeclaration *decl;
GtkCssMatcher matcher; GtkCssMatcher matcher;
@ -722,10 +726,10 @@ update_properties (GtkStyleContext *context,
GtkCssStyle *parent; GtkCssStyle *parent;
GtkCssStyle *result; GtkCssStyle *result;
parent = gtk_css_node_get_parent_style (context, cssnode); parent = gtk_css_node_get_parent_style (cssnode);
decl = gtk_css_node_get_declaration (cssnode); decl = gtk_css_node_get_declaration (cssnode);
result = lookup_in_global_parent_cache (context, parent, decl); result = lookup_in_global_parent_cache (cssnode, parent, decl);
if (result) if (result)
return g_object_ref (result); return g_object_ref (result);
@ -750,10 +754,9 @@ update_properties (GtkStyleContext *context,
} }
static GtkCssStyle * static GtkCssStyle *
build_properties (GtkStyleContext *context, build_properties (GtkCssNode *cssnode,
GtkCssNode *cssnode, gboolean override_state,
gboolean override_state, GtkStateFlags state)
GtkStateFlags state)
{ {
const GtkCssNodeDeclaration *decl; const GtkCssNodeDeclaration *decl;
GtkCssMatcher matcher; GtkCssMatcher matcher;
@ -762,9 +765,9 @@ build_properties (GtkStyleContext *context,
GtkCssStyle *style; GtkCssStyle *style;
decl = gtk_css_node_get_declaration (cssnode); decl = gtk_css_node_get_declaration (cssnode);
parent = gtk_css_node_get_parent_style (context, cssnode); parent = gtk_css_node_get_parent_style (cssnode);
style = lookup_in_global_parent_cache (context, parent, decl); style = lookup_in_global_parent_cache (cssnode, parent, decl);
if (style) if (style)
return g_object_ref (style); return g_object_ref (style);
@ -783,7 +786,7 @@ build_properties (GtkStyleContext *context,
gtk_widget_path_free (path); gtk_widget_path_free (path);
store_in_global_parent_cache (context, parent, decl, style); store_in_global_parent_cache (cssnode, parent, decl, style);
return style; return style;
} }
@ -803,7 +806,7 @@ gtk_style_context_lookup_style (GtkStyleContext *context)
if (values) if (values)
return values; return values;
values = build_properties (context, cssnode, FALSE, 0); values = build_properties (cssnode, FALSE, 0);
gtk_css_node_set_style (cssnode, values); gtk_css_node_set_style (cssnode, values);
g_object_unref (values); g_object_unref (values);
@ -826,8 +829,7 @@ gtk_style_context_lookup_style_for_state (GtkStyleContext *context,
decl = gtk_css_node_dup_declaration (context->priv->cssnode); decl = gtk_css_node_dup_declaration (context->priv->cssnode);
gtk_css_node_declaration_set_state (&decl, state); gtk_css_node_declaration_set_state (&decl, state);
values = build_properties (context, values = build_properties (context->priv->cssnode,
context->priv->cssnode,
TRUE, state); TRUE, state);
gtk_css_node_declaration_unref (decl); gtk_css_node_declaration_unref (decl);
@ -2821,7 +2823,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
{ {
GtkCssStyle *style, *static_style; GtkCssStyle *style, *static_style;
static_style = build_properties (context, cssnode, FALSE, 0); static_style = build_properties (cssnode, FALSE, 0);
style = gtk_css_animated_style_new (static_style, style = gtk_css_animated_style_new (static_style,
priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL, priv->parent ? gtk_style_context_lookup_style (priv->parent) : NULL,
timestamp, timestamp,
@ -2845,8 +2847,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
{ {
GtkCssStyle *new_base; GtkCssStyle *new_base;
new_base = update_properties (context, new_base = update_properties (cssnode,
cssnode,
GTK_CSS_ANIMATED_STYLE (current)->style, GTK_CSS_ANIMATED_STYLE (current)->style,
parent_changes); parent_changes);
new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current), new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (current),
@ -2856,8 +2857,7 @@ _gtk_style_context_validate (GtkStyleContext *context,
} }
else else
{ {
new_values = update_properties (context, new_values = update_properties (cssnode,
cssnode,
current, current,
parent_changes); parent_changes);
} }
@ -2916,8 +2916,7 @@ gtk_style_context_invalidate (GtkStyleContext *context)
gtk_css_node_set_style (context->priv->cssnode, NULL); gtk_css_node_set_style (context->priv->cssnode, NULL);
root = gtk_style_context_get_root (context); root = gtk_style_context_get_root (context);
style = build_properties (context, style = build_properties (root,
root,
FALSE, FALSE,
0); 0);
gtk_css_node_set_style (root, style); gtk_css_node_set_style (root, style);