[gtk+] Move node printing to GtkCssNodeDeclaration



commit 0c52eca34cd1edeb51b930f756652e359ed6ee10
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 3 14:02:00 2016 -0500

    Move node printing to GtkCssNodeDeclaration
    
    The node declaration has all the information we are printing
    here (except for visibility). At the same time, redo the format
    to print the information in selector format, and indicate
    (in)visibility by enclosing the selector in square brackets.

 gtk/gtkcssnode.c                   |   91 ++++--------------------------------
 gtk/gtkcssnodedeclaration.c        |   50 ++++++++++++++++++++
 gtk/gtkcssnodedeclarationprivate.h |    4 ++
 3 files changed, 63 insertions(+), 82 deletions(-)
---
diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index 916b83b..a828d9f 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -1523,80 +1523,6 @@ gtk_css_node_get_style_provider (GtkCssNode *cssnode)
   return GTK_STYLE_PROVIDER_PRIVATE (_gtk_settings_get_style_cascade (gtk_settings_get_default (), 1));
 }
 
-static void
-append_id (GtkCssNode *cssnode,
-           GString    *string)
-{
-  const char *id;
-
-  id = gtk_css_node_get_id (cssnode);
-  if (id)
-    {
-      g_string_append (string, " id=");
-      g_string_append (string, id);
-    }
-}
-
-static void
-append_visible (GtkCssNode *cssnode,
-                GString    *string)
-{
-  g_string_append_printf (string, " visible=%d", gtk_css_node_get_visible (cssnode));
-}
-
-static void
-append_state (GtkCssNode *cssnode,
-              GString    *string)
-
-{
-  GtkStateFlags state;
-
-  state = gtk_css_node_get_state (cssnode);
-  if (state)
-    {
-      GFlagsClass *fclass;
-      gint i;
-      gboolean first = TRUE;
-
-      g_string_append (string, " state=");
-      fclass = g_type_class_ref (GTK_TYPE_STATE_FLAGS);
-      for (i = 0; i < fclass->n_values; i++)
-        {
-          if (state & fclass->values[i].value)
-            {
-              if (first)
-                first = FALSE;
-              else
-                g_string_append_c (string, '|');
-              g_string_append (string, fclass->values[i].value_nick);
-            }
-        }
-      g_type_class_unref (fclass);
-    }
-}
-
-static void
-append_classes (GtkCssNode *cssnode,
-                GString    *string)
-{
-  const GQuark *classes;
-  guint n_classes;
-
-  classes = gtk_css_node_list_classes (cssnode, &n_classes);
-  if (n_classes > 0)
-    {
-      int i;
-
-      g_string_append (string, " classes=");
-      for (i = 0; i < n_classes; i++)
-        {
-          if (i > 0)
-            g_string_append_c (string, ',');
-          g_string_append (string, g_quark_to_string (classes[i]));
-        }
-    }
-}
-
 static gboolean
 gtk_css_node_has_initial_value (GtkCssNode          *cssnode,
                                 GtkCssStyleProperty *prop)
@@ -1690,14 +1616,15 @@ gtk_css_node_print (GtkCssNode                *cssnode,
   GtkCssNode *node;
 
   g_string_append_printf (string, "%*s", indent, "");
-  if (gtk_css_node_get_name (cssnode))
-    g_string_append (string, gtk_css_node_get_name (cssnode));
-  else
-    g_string_append (string, g_type_name (gtk_css_node_get_widget_type (cssnode)));
-  append_id (cssnode, string);
-  append_visible (cssnode, string);
-  append_state (cssnode, string);
-  append_classes (cssnode, string);
+
+  if (!cssnode->visible)
+    g_string_append_c (string, '[');
+
+  gtk_css_node_declaration_print (cssnode->decl, string);
+
+  if (!cssnode->visible)
+    g_string_append_c (string, ']');
+
   g_string_append_c (string, '\n');
 
   append_style (cssnode, flags, string, indent + 2);
diff --git a/gtk/gtkcssnodedeclaration.c b/gtk/gtkcssnodedeclaration.c
index bc139ff..78441c8 100644
--- a/gtk/gtkcssnodedeclaration.c
+++ b/gtk/gtkcssnodedeclaration.c
@@ -648,3 +648,53 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   gtk_widget_path_iter_set_state (path, pos, decl->state);
 }
 
+/* Append the declaration to the string, in selector format */
+void
+gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl,
+                                GString                     *string)
+{
+  static const char *state_names[] = {
+    "active",
+    "hover",
+    "selected",
+    "disabled",
+    "indeterminate",
+    "focus",
+    "backdrop",
+    "dir(ltr)",
+    "dir(rtl)",
+    "link",
+    "visited",
+    "checked",
+    "drop(active)"
+  };
+  const GQuark *classes;
+  guint i;
+
+  if (decl->name)
+    g_string_append (string, decl->name);
+  else
+    g_string_append (string, g_type_name (decl->type));
+
+  if (decl->id)
+    {
+      g_string_append_c (string, '#');
+      g_string_append (string, decl->id);
+    }
+
+  classes = get_classes (decl);
+  for (i = 0; i < decl->n_classes; i++)
+    {
+      g_string_append_c (string, '.');
+      g_string_append (string, g_quark_to_string (classes[i]));
+    }
+
+  for (i = 0; i < G_N_ELEMENTS (state_names); i++)
+    {
+      if (decl->state & (1 << i))
+        {
+          g_string_append_c (string, ':');
+          g_string_append (string, state_names[i]);
+        }
+    }
+}
diff --git a/gtk/gtkcssnodedeclarationprivate.h b/gtk/gtkcssnodedeclarationprivate.h
index a72111a..7760da1 100644
--- a/gtk/gtkcssnodedeclarationprivate.h
+++ b/gtk/gtkcssnodedeclarationprivate.h
@@ -72,6 +72,10 @@ gboolean                gtk_css_node_declaration_equal                  (gconstp
 void                    gtk_css_node_declaration_add_to_widget_path     (const GtkCssNodeDeclaration   *decl,
                                                                          GtkWidgetPath                 *path,
                                                                          guint                          pos);
+
+void                    gtk_css_node_declaration_print                  (const GtkCssNodeDeclaration   *decl,
+                                                                         GString                       
*string);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_NODE_DECLARATION_PRIVATE_H__ */


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