[gtk+/wip/otte/tokenizer: 22/78] css: Add token parser for palettes



commit c5d5825cf05adc58b84b3122fd60f39989489122
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 17 03:19:22 2016 +0100

    css: Add token parser for palettes

 gtk/gtkcsspalettevalue.c        |   52 +++++++++++++++++++++++++++++++++++++++
 gtk/gtkcsspalettevalueprivate.h |    2 +
 gtk/gtkcssstylepropertyimpl.c   |    2 +-
 3 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcsspalettevalue.c b/gtk/gtkcsspalettevalue.c
index cf98968..595dea5 100644
--- a/gtk/gtkcsspalettevalue.c
+++ b/gtk/gtkcsspalettevalue.c
@@ -242,6 +242,58 @@ gtk_css_palette_value_parse (GtkCssParser *parser)
   return result;
 }
 
+GtkCssValue *
+gtk_css_palette_value_token_parse (GtkCssTokenSource *source)
+{
+  GtkCssValue *result, *color;
+  const GtkCssToken *token;
+  char *ident;
+
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_token_is_ident (token, "default"))
+    {
+      gtk_css_token_source_consume_token (source);
+      return gtk_css_palette_value_new_default ();
+    }
+  
+  result = gtk_css_palette_value_new_empty ();
+
+  while (TRUE)
+    {
+      token = gtk_css_token_source_get_token (source);
+      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_IDENT))
+        {
+          gtk_css_token_source_error (source, "Expected color name");
+          gtk_css_token_source_consume_all (source);
+          _gtk_css_value_unref (result);
+          return NULL;
+        }
+      ident = g_strdup (token->string.string);
+      gtk_css_token_source_consume_token (source);
+      gtk_css_token_source_consume_whitespace (source);
+      
+      color = gtk_css_color_value_token_parse (source);
+      if (color == NULL)
+        {
+          g_free (ident);
+          _gtk_css_value_unref (result);
+          return NULL;
+        }
+
+      gtk_css_palette_value_add_color (result, ident, color);
+      g_free (ident);
+
+      gtk_css_token_source_consume_whitespace (source);
+      token = gtk_css_token_source_get_token (source);
+      if (!gtk_css_token_is (token, GTK_CSS_TOKEN_COMMA))
+        break;
+      gtk_css_token_source_consume_token (source);
+      gtk_css_token_source_consume_whitespace (source);
+  }
+
+  return result;
+}
+
 const GdkRGBA *
 gtk_css_palette_value_get_color (GtkCssValue *value,
                                  const char  *name)
diff --git a/gtk/gtkcsspalettevalueprivate.h b/gtk/gtkcsspalettevalueprivate.h
index b422494..a4ed681 100644
--- a/gtk/gtkcsspalettevalueprivate.h
+++ b/gtk/gtkcsspalettevalueprivate.h
@@ -21,6 +21,7 @@
 #define __GTK_CSS_PALETTE_VALUE_PRIVATE_H__
 
 #include "gtkcssparserprivate.h"
+#include "gtkcsstokensourceprivate.h"
 #include "gtkcssvalueprivate.h"
 
 G_BEGIN_DECLS
@@ -28,6 +29,7 @@ G_BEGIN_DECLS
 GtkCssValue *   gtk_css_palette_value_new_default       (void);
 
 GtkCssValue *   gtk_css_palette_value_parse             (GtkCssParser        *parser);
+GtkCssValue *   gtk_css_palette_value_token_parse       (GtkCssTokenSource   *source);
 
 const GdkRGBA * gtk_css_palette_value_get_color         (GtkCssValue         *value,
                                                          const char          *color_name);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 20d019e..1ca306b 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1455,7 +1455,7 @@ _gtk_css_style_property_init_properties (void)
                                          GTK_STYLE_PROPERTY_ANIMATED | GTK_STYLE_PROPERTY_INHERIT,
                                           GTK_CSS_AFFECTS_SYMBOLIC_ICON,
                                          icon_palette_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          (GtkCssStylePropertyTokenParseFunc) 
gtk_css_palette_value_token_parse,
                                          NULL,
                                          NULL,
                                          gtk_css_palette_value_new_default ());


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