[gtk+/wip/otte/gadget: 4/30] cssmatcher: Marshal name to matcher



commit cbab9b5d06e7e68aac519534c7c8c16e05562c43
Author: Benjamin Otte <otte redhat com>
Date:   Sat Sep 5 06:39:10 2015 +0200

    cssmatcher: Marshal name to matcher
    
    ... and use it in the node matcher.
    
    Also rename function from _gtk_css_matcher_get_type() to
    _gtk_css_matcher_get_name().

 gtk/gtkcssmatcher.c        |   40 ++++++++++++++++++++++++++--------------
 gtk/gtkcssmatcherprivate.h |   10 ++++++----
 gtk/gtkcssselector.c       |    2 +-
 3 files changed, 33 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcssmatcher.c b/gtk/gtkcssmatcher.c
index d371bd8..cb9f733 100644
--- a/gtk/gtkcssmatcher.c
+++ b/gtk/gtkcssmatcher.c
@@ -73,11 +73,15 @@ gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_widget_path_has_type (const GtkCssMatcher *matcher,
-                                      GType                type)
+gtk_css_matcher_widget_path_has_name (const GtkCssMatcher     *matcher,
+                                      /*interned*/ const char *name,
+                                      GType                    type)
 {
   const GtkWidgetPath *siblings;
 
+  if (type == 0)
+    return FALSE;
+
   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 g_type_is_a (gtk_widget_path_iter_get_object_type (siblings, matcher->path.sibling_index), type);
@@ -215,7 +219,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_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_type,
+  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_regions,
@@ -296,10 +300,16 @@ gtk_css_matcher_node_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_node_has_type (const GtkCssMatcher *matcher,
-                               GType                type)
+gtk_css_matcher_node_has_name (const GtkCssMatcher     *matcher,
+                               /*interned*/ const char *name,
+                               GType                    type)
 {
-  return g_type_is_a (gtk_css_node_get_widget_type (matcher->node.node), type);
+  const char *node_name = gtk_css_node_get_name (matcher->node.node);
+
+  if (node_name == NULL)
+    return g_type_is_a (gtk_css_node_get_widget_type (matcher->node.node), type);
+  
+  return node_name == name;
 }
 
 static gboolean
@@ -401,7 +411,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_NODE = {
   gtk_css_matcher_node_get_parent,
   gtk_css_matcher_node_get_previous,
   gtk_css_matcher_node_get_state,
-  gtk_css_matcher_node_has_type,
+  gtk_css_matcher_node_has_name,
   gtk_css_matcher_node_has_class,
   gtk_css_matcher_node_has_id,
   gtk_css_matcher_node_has_regions,
@@ -450,8 +460,9 @@ gtk_css_matcher_any_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_any_has_type (const GtkCssMatcher *matcher,
-                              GType                type)
+gtk_css_matcher_any_has_name (const GtkCssMatcher     *matcher,
+                              /*interned*/ const char *name,
+                              GType                    type)
 {
   return TRUE;
 }
@@ -497,7 +508,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_ANY = {
   gtk_css_matcher_any_get_parent,
   gtk_css_matcher_any_get_previous,
   gtk_css_matcher_any_get_state,
-  gtk_css_matcher_any_has_type,
+  gtk_css_matcher_any_has_name,
   gtk_css_matcher_any_has_class,
   gtk_css_matcher_any_has_id,
   gtk_css_matcher_any_has_regions,
@@ -547,11 +558,12 @@ gtk_css_matcher_superset_get_state (const GtkCssMatcher *matcher)
 }
 
 static gboolean
-gtk_css_matcher_superset_has_type (const GtkCssMatcher *matcher,
-                                   GType                type)
+gtk_css_matcher_superset_has_name (const GtkCssMatcher     *matcher,
+                                   /*interned*/ const char *name,
+                                   GType                    type)
 {
   if (matcher->superset.relevant & GTK_CSS_CHANGE_NAME)
-    return _gtk_css_matcher_has_type (matcher->superset.subset, type);
+    return _gtk_css_matcher_has_name (matcher->superset.subset, name, type);
   else
     return TRUE;
 }
@@ -617,7 +629,7 @@ static const GtkCssMatcherClass GTK_CSS_MATCHER_SUPERSET = {
   gtk_css_matcher_superset_get_parent,
   gtk_css_matcher_superset_get_previous,
   gtk_css_matcher_superset_get_state,
-  gtk_css_matcher_superset_has_type,
+  gtk_css_matcher_superset_has_name,
   gtk_css_matcher_superset_has_class,
   gtk_css_matcher_superset_has_id,
   gtk_css_matcher_superset_has_regions,
diff --git a/gtk/gtkcssmatcherprivate.h b/gtk/gtkcssmatcherprivate.h
index 1a788f3..dce57b2 100644
--- a/gtk/gtkcssmatcherprivate.h
+++ b/gtk/gtkcssmatcherprivate.h
@@ -36,7 +36,8 @@ struct _GtkCssMatcherClass {
                                                    const GtkCssMatcher    *next);
 
   GtkStateFlags   (* get_state)                   (const GtkCssMatcher   *matcher);
-  gboolean        (* has_type)                    (const GtkCssMatcher   *matcher,
+  gboolean        (* has_name)                    (const GtkCssMatcher   *matcher,
+                                                   /*interned*/const char*name,
                                                    GType                  type);
   gboolean        (* has_class)                   (const GtkCssMatcher   *matcher,
                                                    GQuark                 class_name);
@@ -111,10 +112,11 @@ _gtk_css_matcher_get_state (const GtkCssMatcher *matcher)
 }
 
 static inline gboolean
-_gtk_css_matcher_has_type (const GtkCssMatcher *matcher,
-                           GType type)
+_gtk_css_matcher_has_name (const GtkCssMatcher     *matcher,
+                           /*interned*/ const char *name,
+                           GType                    type)
 {
-  return matcher->klass->has_type (matcher, type);
+  return matcher->klass->has_name (matcher, name, type);
 }
 
 static inline gboolean
diff --git a/gtk/gtkcssselector.c b/gtk/gtkcssselector.c
index e987aa1..ea4f252 100644
--- a/gtk/gtkcssselector.c
+++ b/gtk/gtkcssselector.c
@@ -690,7 +690,7 @@ static gboolean
 match_name (const GtkCssSelector *selector,
             const GtkCssMatcher  *matcher)
 {
-  return _gtk_css_matcher_has_type (matcher, selector->name.reference->type);
+  return _gtk_css_matcher_has_name (matcher, selector->name.reference->name, selector->name.reference->type);
 }
 
 static guint


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