[gtk/wip/otte/css: 27/48] css: Move utility function



commit c2d69643a8151424d422e7784e69ae9f522cb6f4
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jan 27 03:44:05 2020 +0100

    css: Move utility function
    
    The function was not selector-specific, so putting it with all the other
    utility functions makes more sense.
    
    Also use the utility function in the node declaration printing.

 gtk/gtkcssnodedeclaration.c | 21 ++++-----------------
 gtk/gtkcssselector.c        | 30 ------------------------------
 gtk/gtkcssselectorprivate.h |  2 --
 gtk/gtkcsstypes.c           | 30 ++++++++++++++++++++++++++++++
 gtk/gtkcsstypesprivate.h    |  5 +++++
 5 files changed, 39 insertions(+), 49 deletions(-)
---
diff --git a/gtk/gtkcssnodedeclaration.c b/gtk/gtkcssnodedeclaration.c
index 0d9a28154d..63a9cb40ee 100644
--- a/gtk/gtkcssnodedeclaration.c
+++ b/gtk/gtkcssnodedeclaration.c
@@ -447,21 +447,6 @@ 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;
   char **classnames;
@@ -492,12 +477,14 @@ gtk_css_node_declaration_print (const GtkCssNodeDeclaration *decl,
     }
   g_free (classnames);
 
-  for (i = 0; i < G_N_ELEMENTS (state_names); i++)
+  for (i = 0; i < sizeof (GtkStateFlags) * 8; i++)
     {
       if (decl->state & (1 << i))
         {
+          const char *name = gtk_css_pseudoclass_name (1 << i);
+          g_assert (name);
           g_string_append_c (string, ':');
-          g_string_append (string, state_names[i]);
+          g_string_append (string, name);
         }
     }
 }
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index 39552dfd0e..a27c111e93 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -675,36 +675,6 @@ comp_id (const GtkCssSelector *a,
 
 DEFINE_SIMPLE_SELECTOR(id, ID, print_id, match_id, hash_id, comp_id, TRUE, FALSE, FALSE, FALSE)
 
-const gchar *
-gtk_css_pseudoclass_name (GtkStateFlags state)
-{
-  static const char * state_names[] = {
-    "active",
-    "hover",
-    "selected",
-    "disabled",
-    "indeterminate",
-    "focus",
-    "backdrop",
-    "dir(ltr)",
-    "dir(rtl)",
-    "link",
-    "visited",
-    "checked",
-    "drop(active)",
-    "focus(visible)"
-  };
-  guint i;
-
-  for (i = 0; i < G_N_ELEMENTS (state_names); i++)
-    {
-      if (state == (1 << i))
-        return state_names[i];
-    }
-
-  return NULL;
-}
-
 /* PSEUDOCLASS FOR STATE */
 static void
 print_pseudoclass_state (const GtkCssSelector *selector,
diff --git a/gtk/gtkcssselectorprivate.h b/gtk/gtkcssselectorprivate.h
index 6f35917c6e..b8673edda5 100644
--- a/gtk/gtkcssselectorprivate.h
+++ b/gtk/gtkcssselectorprivate.h
@@ -59,8 +59,6 @@ void                       _gtk_css_selector_tree_builder_add   (GtkCssSelectorT
 GtkCssSelectorTree *       _gtk_css_selector_tree_builder_build (GtkCssSelectorTreeBuilder *builder);
 void                       _gtk_css_selector_tree_builder_free  (GtkCssSelectorTreeBuilder *builder);
 
-const char *gtk_css_pseudoclass_name (GtkStateFlags flags);
-
 G_END_DECLS
 
 #endif /* __GTK_CSS_SELECTOR_PRIVATE_H__ */
diff --git a/gtk/gtkcsstypes.c b/gtk/gtkcsstypes.c
index d304a42f37..66b3415d81 100644
--- a/gtk/gtkcsstypes.c
+++ b/gtk/gtkcsstypes.c
@@ -257,3 +257,33 @@ gtk_css_change_to_string (GtkCssChange change)
   return g_string_free (string, FALSE);
 }
 
+const gchar *
+gtk_css_pseudoclass_name (GtkStateFlags state)
+{
+  static const char * state_names[] = {
+    "active",
+    "hover",
+    "selected",
+    "disabled",
+    "indeterminate",
+    "focus",
+    "backdrop",
+    "dir(ltr)",
+    "dir(rtl)",
+    "link",
+    "visited",
+    "checked",
+    "drop(active)",
+    "focus(visible)"
+  };
+  guint i;
+
+  for (i = 0; i < G_N_ELEMENTS (state_names); i++)
+    {
+      if (state == (1 << i))
+        return state_names[i];
+    }
+
+  return NULL;
+}
+
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 5a6978a2ed..156e3763a8 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -21,6 +21,8 @@
 #include <glib-object.h>
 #include <gsk/gsk.h>
 
+#include <gtk/gtkenums.h>
+
 G_BEGIN_DECLS
 
 typedef union _GtkCssMatcher GtkCssMatcher;
@@ -456,6 +458,9 @@ char *                  gtk_css_change_to_string                 (GtkCssChange
 void                    gtk_css_change_print                     (GtkCssChange       change,
                                                                   GString           *string);
 
+const char *            gtk_css_pseudoclass_name                 (GtkStateFlags      flags);
+
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_TYPES_PRIVATE_H__ */


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