[gtk+/wip/otte/tokenizer: 22/42] css: Add token parser for palettes
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/tokenizer: 22/42] css: Add token parser for palettes
- Date: Sun, 20 Mar 2016 05:02:52 +0000 (UTC)
commit 9ab84e2aa00d0163e3aa0339d2c317c8395f90c7
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]