[gtk+] cssmatcher: Handle case of empty widget path



commit b4195cb408ed59aa768423e382740f685cf15e60
Author: Benjamin Otte <otte redhat com>
Date:   Mon Apr 30 21:28:57 2012 +0200

    cssmatcher: Handle case of empty widget path
    
    This is tested by the stylecontext test, but doesn't appear in practice.

 gtk/gtkcssmatcher.c        |    7 ++++++-
 gtk/gtkcssmatcherprivate.h |    4 ++--
 gtk/gtkcssprovider.c       |   33 ++++++++++++++++++---------------
 gtk/gtkstylecontext.c      |   16 +++++++++-------
 4 files changed, 35 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index e67c9ef..c656ef4 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -187,16 +187,21 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
   gtk_css_matcher_widget_path_has_position,
 };
 
-void
+gboolean
 _gtk_css_matcher_init (GtkCssMatcher       *matcher,
                        const GtkWidgetPath *path,
                        GtkStateFlags        state)
 {
+  if (gtk_widget_path_length (path) == 0)
+    return FALSE;
+
   matcher->path.klass = &GTK_CSS_MATCHER_WIDGET_PATH;
   matcher->path.path = path;
   matcher->path.state_flags = state;
   matcher->path.index = gtk_widget_path_length (path) - 1;
   matcher->path.sibling_index = gtk_widget_path_iter_get_sibling_index (path, matcher->path.index);
+
+  return TRUE;
 }
 
 /* GTK_CSS_MATCHER_WIDGET_ANY */
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 121e286..1b4c632 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -72,9 +72,9 @@ union _GtkCssMatcher {
   GtkCssMatcherSuperset     superset;
 };
 
-void              _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
+gboolean          _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
                                                    const GtkWidgetPath    *path,
-                                                   GtkStateFlags           state);
+                                                   GtkStateFlags           state) G_GNUC_WARN_UNUSED_RESULT;
 void              _gtk_css_matcher_any_init       (GtkCssMatcher          *matcher);
 void              _gtk_css_matcher_superset_init  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *subset,
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 7241a1d..128edc3 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1485,25 +1485,26 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
   props = gtk_style_properties_new ();
 
   css_provider_dump_symbolic_colors (css_provider, props);
-  _gtk_css_matcher_init (&matcher, path, 0);
-
-  for (i = 0; i < priv->rulesets->len; i++)
+  if (_gtk_css_matcher_init (&matcher, path, 0))
     {
-      GtkCssRuleset *ruleset;
+      for (i = 0; i < priv->rulesets->len; i++)
+        {
+          GtkCssRuleset *ruleset;
 
-      ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
+          ruleset = &g_array_index (priv->rulesets, GtkCssRuleset, i);
 
-      if (ruleset->styles == NULL)
-        continue;
+          if (ruleset->styles == NULL)
+            continue;
 
-      if (!gtk_css_ruleset_matches (ruleset, &matcher))
-        continue;
+          if (!gtk_css_ruleset_matches (ruleset, &matcher))
+            continue;
 
-      for (j = 0; j < ruleset->n_styles; j++)
-	_gtk_style_properties_set_property_by_property (props,
-							GTK_CSS_STYLE_PROPERTY (ruleset->styles[i].property),
-							_gtk_css_selector_get_state_flags (ruleset->selector),
-							ruleset->styles[i].value);
+          for (j = 0; j < ruleset->n_styles; j++)
+            _gtk_style_properties_set_property_by_property (props,
+                                                            GTK_CSS_STYLE_PROPERTY (ruleset->styles[i].property),
+                                                            _gtk_css_selector_get_state_flags (ruleset->selector),
+                                                            ruleset->styles[i].value);
+        }
     }
 
   return props;
@@ -1524,10 +1525,12 @@ gtk_css_provider_get_style_property (GtkStyleProvider *provider,
   gchar *prop_name;
   gint i;
 
+  if (!_gtk_css_matcher_init (&matcher, path, state))
+    return FALSE;
+
   prop_name = g_strdup_printf ("-%s-%s",
                                g_type_name (pspec->owner_type),
                                pspec->name);
-  _gtk_css_matcher_init (&matcher, path, state);
 
   for (i = priv->rulesets->len - 1; i >= 0; i--)
     {
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index f18c8ab..5fd398e 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -905,12 +905,12 @@ build_properties (GtkStyleContext *context,
 
   priv = context->priv;
 
-  _gtk_css_matcher_init (&matcher, path, state);
   lookup = _gtk_css_lookup_new ();
 
-  _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                                      &matcher,
-                                      lookup);
+  if (_gtk_css_matcher_init (&matcher, path, state))
+    _gtk_style_provider_private_lookup (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
+                                        &matcher,
+                                        lookup);
 
   style_data->store = _gtk_css_computed_values_new ();
   _gtk_css_lookup_resolve (lookup, context, style_data->store);
@@ -3061,10 +3061,12 @@ _gtk_style_context_validate (GtkStyleContext *context,
           GtkCssMatcher matcher;
 
           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),
+                                                                             &matcher);
+          else
+            priv->relevant_changes = 0;
 
-          priv->relevant_changes = _gtk_style_provider_private_get_change (GTK_STYLE_PROVIDER_PRIVATE (priv->cascade),
-                                                                           &matcher);
           priv->relevant_changes &= ~GTK_STYLE_CONTEXT_RADICAL_CHANGE;
 
           gtk_widget_path_unref (path);



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