cssmatcher: Handle case of empty widget path

This is tested by the stylecontext test, but doesn't appear in practice.
This commit is contained in:
Benjamin Otte
2012-04-30 21:28:57 +02:00
parent 6c63842e68
commit b4195cb408
4 changed files with 35 additions and 25 deletions

View File

@ -187,16 +187,21 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
gtk_css_matcher_widget_path_has_position, gtk_css_matcher_widget_path_has_position,
}; };
void gboolean
_gtk_css_matcher_init (GtkCssMatcher *matcher, _gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path, const GtkWidgetPath *path,
GtkStateFlags state) GtkStateFlags state)
{ {
if (gtk_widget_path_length (path) == 0)
return FALSE;
matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH; matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
matcher->path.path = path; matcher->path.path = path;
matcher->path.state_flags = state; matcher->path.state_flags = state;
matcher->path.index = gtk_widget_path_length (path) - 1; matcher->path.index = gtk_widget_path_length (path) - 1;
matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index); matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
return TRUE;
} }
/* GTK_CSS_MATCHER_WIDGET_ANY */ /* GTK_CSS_MATCHER_WIDGET_ANY */

View File

@ -72,9 +72,9 @@ union _GtkCssMatcher {
GtkCssMatcherSuperset superset; GtkCssMatcherSuperset superset;
}; };
void _gtk_css_matcher_init (GtkCssMatcher *matcher, gboolean _gtk_css_matcher_init (GtkCssMatcher *matcher,
const GtkWidgetPath *path, const GtkWidgetPath *path,
GtkStateFlags state); GtkStateFlags state) G_GNUC_WARN_UNUSED_RESULT;
void _gtk_css_matcher_any_init (GtkCssMatcher *matcher); void _gtk_css_matcher_any_init (GtkCssMatcher *matcher);
void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher, void _gtk_css_matcher_superset_init (GtkCssMatcher *matcher,
const GtkCssMatcher *subset, const GtkCssMatcher *subset,

View File

@ -1485,8 +1485,8 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
props = gtk_style_properties_new (); props = gtk_style_properties_new ();
css_provider_dump_symbolic_colors (css_provider, props); css_provider_dump_symbolic_colors (css_provider, props);
_gtk_css_matcher_init (&matcher, path, 0); if (_gtk_css_matcher_init (&matcher, path, 0))
{
for (i = 0; i < priv->rulesets->len; i++) for (i = 0; i < priv->rulesets->len; i++)
{ {
GtkCssRuleset *ruleset; GtkCssRuleset *ruleset;
@ -1505,6 +1505,7 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
_gtk_css_selector_get_state_flags (ruleset->selector), _gtk_css_selector_get_state_flags (ruleset->selector),
ruleset->styles[i].value); ruleset->styles[i].value);
} }
}
return props; return props;
} }
@ -1524,10 +1525,12 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
gchar *prop_name; gchar *prop_name;
gint i; gint i;
if (!_gtk_css_matcher_init (&matcher, path, state))
return FALSE;
prop_name = g_strdup_printf ("-%s-%s", prop_name = g_strdup_printf ("-%s-%s",
g_type_name (pspec->owner_type), g_type_name (pspec->owner_type),
pspec->name); pspec->name);
_gtk_css_matcher_init (&matcher, path, state);
for (i = priv->rulesets->len - 1; i >= 0; i--) for (i = priv->rulesets->len - 1; i >= 0; i--)
{ {

View File

@ -905,9 +905,9 @@ build_properties (GtkStyleContext *context,
priv = context->priv; priv = context->priv;
_gtk_css_matcher_init (&matcher, path, state);
lookup = _gtk_css_lookup_new (); lookup = _gtk_css_lookup_new ();
if (_gtk_css_matcher_init (&matcher, path, state))
_gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
&matcher, &matcher,
lookup); lookup);
@ -3061,10 +3061,12 @@ _gtk_style_context_validate (GtkStyleContext *context,
GtkCssMatcher matcher; GtkCssMatcher matcher;
path = create_query_path (context); path = create_query_path (context);
_gtk_css_matcher_init (&matcher, path, priv->info->state_flags); if (_gtk_css_matcher_init (&matcher, path, priv->info->state_flags))
priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade), priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
&matcher); &matcher);
else
priv->relevant_changes = 0;
priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE; priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
gtk_widget_path_unref (path); gtk_widget_path_unref (path);