[gtk/matthiasc/css-change-tracking-3: 5/6] Allow printing css matchers



commit 7588655a42d04f83f2f8819f652c86115701e928
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 15 02:03:08 2020 -0500

    Allow printing css matchers
    
    This can help in debugging css matching.

 gtk/gtkcssmatcher.c        | 59 ++++++++++++++++++++++++++++++++++++++++++----
 gtk/gtkcssmatcherprivate.h |  7 +++++-
 2 files changed, 61 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 8665d9f2a1..1ceffa95da 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -23,6 +23,21 @@
 #include "gtkcssnodeprivate.h"
 #include "gtkwidgetpath.h"
 
+void
+gtk_css_matcher_print (const GtkCssMatcher *matcher,
+                       GString             *string)
+{
+  matcher->klass->print (matcher, string);
+}
+
+char *
+gtk_css_matcher_to_string (const GtkCssMatcher *matcher)
+{
+  GString *string = g_string_new ("");
+  gtk_css_matcher_print (matcher, string);
+  return g_string_free (string, FALSE);
+}
+
 /* GTK_CSS_MATCHER_WIDGET_PATH */
 
 static gboolean
@@ -158,6 +173,15 @@ gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
   return x / a >= 0;
 }
 
+static void
+gtk_css_matcher_widget_path_print (const GtkCssMatcher *matcher,
+                                   GString             *string)
+{
+  char *s = gtk_widget_path_to_string (matcher->path.path);
+  g_string_append (string, s);
+  g_free (s);
+}
+
 static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
   GTK_CSS_MATCHER_TYPE_WIDGET_PATH,
   gtk_css_matcher_widget_path_get_parent,
@@ -166,7 +190,8 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
   gtk_css_matcher_widget_path_has_name,
   gtk_css_matcher_widget_path_has_class,
   gtk_css_matcher_widget_path_has_id,
-  gtk_css_matcher_widget_path_has_position
+  gtk_css_matcher_widget_path_has_position,
+  gtk_css_matcher_widget_path_print
 };
 
 gboolean
@@ -334,6 +359,13 @@ gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
                                          a, b);
 }
 
+static void
+gtk_css_matcher_node_print (const GtkCssMatcher *matcher,
+                            GString             *string)
+{
+  gtk_css_node_print (matcher->node.node, 0, string, 0);
+}
+
 static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
   GTK_CSS_MATCHER_TYPE_NODE,
   gtk_css_matcher_node_get_parent,
@@ -342,7 +374,8 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
   gtk_css_matcher_node_has_name,
   gtk_css_matcher_node_has_class,
   gtk_css_matcher_node_has_id,
-  gtk_css_matcher_node_has_position
+  gtk_css_matcher_node_has_position,
+  gtk_css_matcher_node_print
 };
 
 void
@@ -429,6 +462,13 @@ gtk_css_matcher_any_has_position (const GtkCssMatcher *matcher,
   return TRUE;
 }
 
+static void
+gtk_css_matcher_any_print (const GtkCssMatcher *matcher,
+                           GString             *string)
+{
+  g_string_append (string, "ANY");
+}
+
 static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
   GTK_CSS_MATCHER_TYPE_ANY,
   gtk_css_matcher_any_get_parent,
@@ -437,7 +477,8 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
   gtk_css_matcher_any_has_name,
   gtk_css_matcher_any_has_class,
   gtk_css_matcher_any_has_id,
-  gtk_css_matcher_any_has_position
+  gtk_css_matcher_any_has_position,
+  gtk_css_matcher_any_print
 };
 
 void
@@ -517,6 +558,15 @@ gtk_css_matcher_superset_has_position (const GtkCssMatcher *matcher,
   return TRUE;
 }
 
+static void
+gtk_css_matcher_superset_print (const GtkCssMatcher *matcher,
+                                GString             *string)
+{
+  g_string_append (string, "SUPERSET(");
+  gtk_css_matcher_print (matcher->superset.subset, string);
+  g_string_append (string, ")");
+}
+
 static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
   GTK_CSS_MATCHER_TYPE_SUPERSET,
   gtk_css_matcher_superset_get_parent,
@@ -525,7 +575,8 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
   gtk_css_matcher_superset_has_name,
   gtk_css_matcher_superset_has_class,
   gtk_css_matcher_superset_has_id,
-  gtk_css_matcher_superset_has_position
+  gtk_css_matcher_superset_has_position,
+  gtk_css_matcher_superset_print
 };
 
 void
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 2a211ec424..2e7f70a131 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -54,6 +54,8 @@ struct _GtkCssMatcherClass {
                                                    gboolean               forward,
                                                    int                    a,
                                                    int                    b);
+  void            (* print)                       (const GtkCssMatcher   *matcher,
+                                                   GString               *string);
 };
 
 struct _GtkCssMatcherWidgetPath {
@@ -95,6 +97,10 @@ void              _gtk_css_matcher_any_init       (GtkCssMatcher          *match
 void              _gtk_css_matcher_superset_init  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *subset);
 
+void              gtk_css_matcher_print           (const GtkCssMatcher    *matcher,
+                                                   GString                *string);
+char *            gtk_css_matcher_to_string       (const GtkCssMatcher    *matcher);
+
 
 static inline gboolean
 _gtk_css_matcher_get_parent (GtkCssMatcher       *matcher,
@@ -152,7 +158,6 @@ _gtk_css_matcher_matches_any (const GtkCssMatcher *matcher)
   return matcher->klass->type == GTK_CSS_MATCHER_TYPE_ANY;
 }
 
-
 G_END_DECLS
 
 #endif /* __GTK_CSS_MATCHER_PRIVATE_H__ */


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