[gtk/matthiasc/css-change: 4/11] cssmatcher: Add a type enum



commit c623b3055d0abec3f7125fb5340f3d61f512acc9
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 14 22:29:56 2020 -0500

    cssmatcher: Add a type enum
    
    For now, this just replaces the is_any boolean
    by a type field in the class, and does away with
    the unused Superset struct.supserset matcher fixup

 gtk/gtkcssmatcher.c        | 36 +++++++++++++++++++++++++-----------
 gtk/gtkcssmatcherprivate.h | 17 ++++++++---------
 2 files changed, 33 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 0fee1ea6c3..7c24147443 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -160,14 +160,14 @@ gtk_css_matcher_widget_path_has_position (const GtkCssMatcher *matcher,
 }
 
 static const GtkCssMatcherClass GTK_CSS_MATCHER_WIDGET_PATH = {
+  GTK_CSS_MATCHER_TYPE_WIDGET_PATH,
   gtk_css_matcher_widget_path_get_parent,
   gtk_css_matcher_widget_path_get_previous,
   gtk_css_matcher_widget_path_get_state,
   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,
-  FALSE
+  gtk_css_matcher_widget_path_has_position
 };
 
 gboolean
@@ -336,14 +336,14 @@ gtk_css_matcher_node_has_position (const GtkCssMatcher *matcher,
 }
 
 static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
+  GTK_CSS_MATCHER_TYPE_NODE,
   gtk_css_matcher_node_get_parent,
   gtk_css_matcher_node_get_previous,
   gtk_css_matcher_node_get_state,
   gtk_css_matcher_node_has_name,
   gtk_css_matcher_node_has_class,
   gtk_css_matcher_node_has_id,
-  gtk_css_matcher_node_has_position,
-  FALSE
+  gtk_css_matcher_node_has_position
 };
 
 void
@@ -421,14 +421,14 @@ gtk_css_matcher_any_has_position (const GtkCssMatcher *matcher,
 }
 
 static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
+  GTK_CSS_MATCHER_TYPE_ANY,
   gtk_css_matcher_any_get_parent,
   gtk_css_matcher_any_get_previous,
   gtk_css_matcher_any_get_state,
   gtk_css_matcher_any_has_name,
   gtk_css_matcher_any_has_class,
   gtk_css_matcher_any_has_id,
-  gtk_css_matcher_any_has_position,
-  TRUE
+  gtk_css_matcher_any_has_position
 };
 
 void
@@ -496,15 +496,15 @@ gtk_css_matcher_superset_has_position (const GtkCssMatcher *matcher,
   return TRUE;
 }
 
-static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET2 = {
+static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
+  0,
   gtk_css_matcher_superset_get_parent,
   gtk_css_matcher_superset_get_previous,
   gtk_css_matcher_superset_get_state,
   gtk_css_matcher_superset_has_name,
   gtk_css_matcher_superset_has_class,
   gtk_css_matcher_superset_has_id,
-  gtk_css_matcher_superset_has_position,
-  FALSE
+  gtk_css_matcher_superset_has_position
 };
 
 void
@@ -516,7 +516,22 @@ _gtk_css_matcher_superset_init (GtkCssMatcher       *matcher,
   g_return_if_fail (subset != NULL);
   g_return_if_fail ((relevant & ~(GTK_CSS_CHANGE_CLASS | GTK_CSS_CHANGE_NAME | GTK_CSS_CHANGE_POSITION | 
GTK_CSS_CHANGE_STATE)) == 0);
 
-  *klass = GTK_CSS_MATCHER_SUPERSET2;
+  switch (subset->klass->type)
+    {
+    case GTK_CSS_MATCHER_TYPE_NODE:
+      matcher->node = subset->node;
+      break;
+    case GTK_CSS_MATCHER_TYPE_WIDGET_PATH:
+      matcher->path = subset->path;
+      break;
+    case GTK_CSS_MATCHER_TYPE_ANY:
+      break;
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  *klass = GTK_CSS_MATCHER_SUPERSET;
 
   if (relevant & GTK_CSS_CHANGE_CLASS)
     klass->has_class = subset->klass->has_class;
@@ -529,6 +544,5 @@ _gtk_css_matcher_superset_init (GtkCssMatcher       *matcher,
   if (relevant & GTK_CSS_CHANGE_STATE)
     klass->get_state = subset->klass->get_state;
 
-  *matcher = *subset;
   matcher->klass = klass;
 }
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 6f5e9d195c..3b4c4a1d5a 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -29,7 +29,14 @@ typedef struct _GtkCssMatcherSuperset GtkCssMatcherSuperset;
 typedef struct _GtkCssMatcherWidgetPath GtkCssMatcherWidgetPath;
 typedef struct _GtkCssMatcherClass GtkCssMatcherClass;
 
+typedef enum {
+  GTK_CSS_MATCHER_TYPE_NODE,
+  GTK_CSS_MATCHER_TYPE_WIDGET_PATH,
+ GTK_CSS_MATCHER_TYPE_ANY
+} GtkCssMatcherType;
+
 struct _GtkCssMatcherClass {
+  GtkCssMatcherType type;
   gboolean        (* get_parent)                  (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *child);
   gboolean        (* get_previous)                (GtkCssMatcher          *matcher,
@@ -46,7 +53,6 @@ struct _GtkCssMatcherClass {
                                                    gboolean               forward,
                                                    int                    a,
                                                    int                    b);
-  gboolean is_any;
 };
 
 struct _GtkCssMatcherWidgetPath {
@@ -67,17 +73,10 @@ struct _GtkCssMatcherNode {
   guint                     n_classes;
 };
 
-struct _GtkCssMatcherSuperset {
-  const GtkCssMatcherClass *klass;
-  const GtkCssMatcher      *subset;
-  GtkCssChange              relevant;
-};
-
 union _GtkCssMatcher {
   const GtkCssMatcherClass *klass;
   GtkCssMatcherWidgetPath   path;
   GtkCssMatcherNode         node;
-  GtkCssMatcherSuperset     superset;
 };
 
 gboolean          _gtk_css_matcher_init           (GtkCssMatcher          *matcher,
@@ -145,7 +144,7 @@ _gtk_css_matcher_has_position (const GtkCssMatcher *matcher,
 static inline gboolean
 _gtk_css_matcher_matches_any (const GtkCssMatcher *matcher)
 {
-  return matcher->klass->is_any;
+  return matcher->klass->type == GTK_CSS_MATCHER_TYPE_ANY;
 }
 
 


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