[gtk/matthiasc/css-change-tracking-3: 6/6] cssmatcher: Change get_state to has_state



commit 93b5b487ae42bf75ab234449c7583f8cbd7c2874
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jan 16 19:23:45 2020 -0500

    cssmatcher: Change get_state to has_state
    
    This matches all the other vfuncs, and it gets us
    out of keeping several big state flag enumerations
    in sync.
    
    Update all callers.

 gtk/gtkcssmatcher.c        | 84 ++++++++++++++++++----------------------------
 gtk/gtkcssmatcherprivate.h | 10 +++---
 gtk/gtkcssselector.c       |  2 +-
 3 files changed, 39 insertions(+), 57 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index 1ceffa95da..86e5540a47 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -72,19 +72,26 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
   return TRUE;
 }
 
-static GtkStateFlags
-gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
+static gboolean
+gtk_css_matcher_widget_path_has_state (const GtkCssMatcher *matcher,
+                                       GtkStateFlags        state)
 {
-  const GtkWidgetPath *siblings;
+  GtkStateFlags path_state;
   
   if (matcher->path.decl)
-    return gtk_css_node_declaration_get_state (matcher->path.decl);
-
-  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
-  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, 
matcher->path.index))
-    return gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index);
+    path_state = gtk_css_node_declaration_get_state (matcher->path.decl);
   else
-    return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
+    {
+      const GtkWidgetPath *siblings;
+
+      siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+      if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index 
(matcher->path.path, matcher->path.index))
+        path_state = gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index);
+      else
+        path_state = gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
+    }
+
+  return (path_state & state) == state;
 }
 
 static gboolean
@@ -186,7 +193,7 @@ 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_state,
   gtk_css_matcher_widget_path_has_name,
   gtk_css_matcher_widget_path_has_class,
   gtk_css_matcher_widget_path_has_id,
@@ -259,10 +266,11 @@ gtk_css_matcher_node_get_previous (GtkCssMatcher       *matcher,
   return gtk_css_node_init_matcher (node, matcher);
 }
 
-static GtkStateFlags
-gtk_css_matcher_node_get_state (const GtkCssMatcher *matcher)
+static gboolean
+gtk_css_matcher_node_has_state (const GtkCssMatcher *matcher,
+                                GtkStateFlags        state)
 {
-  return matcher->node.node_state;
+  return (matcher->node.node_state & state) == state;
 }
 
 static gboolean
@@ -370,7 +378,7 @@ 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_state,
   gtk_css_matcher_node_has_name,
   gtk_css_matcher_node_has_class,
   gtk_css_matcher_node_has_id,
@@ -411,25 +419,11 @@ gtk_css_matcher_any_get_previous (GtkCssMatcher       *matcher,
   return TRUE;
 }
 
-static GtkStateFlags
-gtk_css_matcher_any_get_state (const GtkCssMatcher *matcher)
+static gboolean
+gtk_css_matcher_any_has_state (const GtkCssMatcher *matcher,
+                               GtkStateFlags        state)
 {
-  /* XXX: This gets tricky when we implement :not() */
-
-  return GTK_STATE_FLAG_ACTIVE |
-         GTK_STATE_FLAG_PRELIGHT |
-         GTK_STATE_FLAG_SELECTED |
-         GTK_STATE_FLAG_INSENSITIVE |
-         GTK_STATE_FLAG_INCONSISTENT |
-         GTK_STATE_FLAG_FOCUSED |
-         GTK_STATE_FLAG_BACKDROP |
-         GTK_STATE_FLAG_DIR_LTR |
-         GTK_STATE_FLAG_DIR_RTL |
-         GTK_STATE_FLAG_LINK |
-         GTK_STATE_FLAG_VISITED |
-         GTK_STATE_FLAG_CHECKED |
-         GTK_STATE_FLAG_DROP_ACTIVE |
-         GTK_STATE_FLAG_FOCUS_VISIBLE;
+  return TRUE;
 }
 
 static gboolean
@@ -473,7 +467,7 @@ 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_state,
   gtk_css_matcher_any_has_name,
   gtk_css_matcher_any_has_class,
   gtk_css_matcher_any_has_id,
@@ -507,25 +501,11 @@ gtk_css_matcher_superset_get_previous (GtkCssMatcher       *matcher,
   return TRUE;
 }
 
-static GtkStateFlags
-gtk_css_matcher_superset_get_state (const GtkCssMatcher *matcher)
+static gboolean
+gtk_css_matcher_superset_has_state (const GtkCssMatcher *matcher,
+                                    GtkStateFlags        state)
 {
-  /* XXX: This gets tricky when we implement :not() */
-
-  return GTK_STATE_FLAG_ACTIVE |
-         GTK_STATE_FLAG_PRELIGHT |
-         GTK_STATE_FLAG_SELECTED |
-         GTK_STATE_FLAG_INSENSITIVE |
-         GTK_STATE_FLAG_INCONSISTENT |
-         GTK_STATE_FLAG_FOCUSED |
-         GTK_STATE_FLAG_BACKDROP |
-         GTK_STATE_FLAG_DIR_LTR |
-         GTK_STATE_FLAG_DIR_RTL |
-         GTK_STATE_FLAG_LINK |
-         GTK_STATE_FLAG_VISITED |
-         GTK_STATE_FLAG_CHECKED |
-         GTK_STATE_FLAG_DROP_ACTIVE |
-         GTK_STATE_FLAG_FOCUS_VISIBLE;
+  return TRUE;
 }
 
 static gboolean
@@ -571,7 +551,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
   GTK_CSS_MATCHER_TYPE_SUPERSET,
   gtk_css_matcher_superset_get_parent,
   gtk_css_matcher_superset_get_previous,
-  gtk_css_matcher_superset_get_state,
+  gtk_css_matcher_superset_has_state,
   gtk_css_matcher_superset_has_name,
   gtk_css_matcher_superset_has_class,
   gtk_css_matcher_superset_has_id,
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 2e7f70a131..094957bdaa 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -43,7 +43,8 @@ struct _GtkCssMatcherClass {
   gboolean        (* get_previous)                (GtkCssMatcher          *matcher,
                                                    const GtkCssMatcher    *next);
 
-  GtkStateFlags   (* get_state)                   (const GtkCssMatcher   *matcher);
+  gboolean        (* has_state)                   (const GtkCssMatcher   *matcher,
+                                                   GtkStateFlags          state);
   gboolean        (* has_name)                    (const GtkCssMatcher   *matcher,
                                                    /*interned*/const char*name);
   gboolean        (* has_class)                   (const GtkCssMatcher   *matcher,
@@ -116,10 +117,11 @@ _gtk_css_matcher_get_previous (GtkCssMatcher       *matcher,
   return next->klass->get_previous (matcher, next);
 }
 
-static inline GtkStateFlags
-_gtk_css_matcher_get_state (const GtkCssMatcher *matcher)
+static inline gboolean
+_gtk_css_matcher_has_state (const GtkCssMatcher *matcher,
+                            GtkStateFlags        state)
 {
-  return matcher->klass->get_state (matcher);
+  return matcher->klass->has_state (matcher, state);
 }
 
 static inline gboolean
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index e260cf159c..8957e49413 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -711,7 +711,7 @@ static gboolean
 match_pseudoclass_state (const GtkCssSelector *selector,
                          const GtkCssMatcher  *matcher)
 {
-  return (_gtk_css_matcher_get_state (matcher) & selector->state.state) == selector->state.state;
+  return _gtk_css_matcher_has_state (matcher, selector->state.state);
 }
 
 static guint


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