[gtk+/gtk-style-context: 172/191] GtkCssProvider: Parse and compare widget names.



commit 27ab29b4c88a6275c5ef6ad35a460bdbaa8bb8ad
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Aug 4 11:44:32 2010 +0200

    GtkCssProvider: Parse and compare widget names.

 gtk/gtkcssprovider.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index ebff9f3..a3c83a4 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -233,6 +233,21 @@ selector_path_prepend_region (SelectorPath       *path,
 }
 
 static void
+selector_path_prepend_name (SelectorPath *path,
+                            const gchar  *name)
+{
+  SelectorElement *elem;
+
+  elem = g_slice_new (SelectorElement);
+  elem->combinator = COMBINATOR_DESCENDANT;
+  elem->elem_type = SELECTOR_NAME;
+
+  elem->name = g_quark_from_string (name);
+
+  path->elements = g_slist_prepend (path->elements, elem);
+}
+
+static void
 selector_path_prepend_combinator (SelectorPath   *path,
                                   CombinatorType  combinator)
 {
@@ -418,6 +433,20 @@ compare_selector_element (GtkWidgetPath   *path,
       *score = 1;
       return TRUE;
     }
+  else if (elem->elem_type == SELECTOR_NAME)
+    {
+      const gchar *name, *path_name;
+
+      name = g_quark_to_string (elem->name);
+      path_name = gtk_widget_path_get_element_name (path, index);
+
+      if (!path_name ||
+          strcmp (path_name, name) != 0)
+        return FALSE;
+
+      *score = 0xF;
+      return TRUE;
+    }
 
   return FALSE;
 }
@@ -738,6 +767,7 @@ css_provider_apply_scope (GtkCssProvider *css_provider,
     g_assert_not_reached ();
 
   priv->scanner->config->scan_float = FALSE;
+  priv->scanner->config->cpair_comment_single = NULL;
 }
 
 static void
@@ -908,12 +938,27 @@ parse_selector (GtkCssProvider  *css_provider,
   *selector_out = path;
 
   if (scanner->token != ':' &&
+      scanner->token != '#' &&
       scanner->token != G_TOKEN_IDENTIFIER)
     return G_TOKEN_IDENTIFIER;
 
-  while (scanner->token == G_TOKEN_IDENTIFIER)
+  while (scanner->token == '#' ||
+         scanner->token == G_TOKEN_IDENTIFIER)
     {
-      if (g_ascii_isupper (scanner->value.v_identifier[0]))
+      if (scanner->token == '#')
+        {
+          g_scanner_get_next_token (scanner);
+
+          if (scanner->token != G_TOKEN_IDENTIFIER)
+            return G_TOKEN_IDENTIFIER;
+
+          /* Add glob selector if path is empty */
+          if (selector_path_depth (path) == 0)
+            selector_path_prepend_glob (path);
+
+          selector_path_prepend_name (path, scanner->value.v_identifier);
+        }
+      else if (g_ascii_isupper (scanner->value.v_identifier[0]))
         selector_path_prepend_type (path, scanner->value.v_identifier);
       else if (g_ascii_islower (scanner->value.v_identifier[0]))
         {



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