summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2016-03-20 04:21:17 +0100
committerBenjamin Otte <otte@redhat.com>2016-04-08 16:18:30 +0200
commit33b2684c29e7b505bb42e0c10e59d4e2104522a5 (patch)
tree02729f5be97f8607ed96cd7d8787a02231080a9e
parent16dff3909bec94b20b572c91e011e8aebb2f739e (diff)
downloadgtk+-33b2684c29e7b505bb42e0c10e59d4e2104522a5.tar.gz
css: Add a token aprser for define-color
-rw-r--r--gtk/Makefile.am2
-rw-r--r--gtk/gtkcssdefinecolorrule.c127
-rw-r--r--gtk/gtkcssdefinecolorruleprivate.h57
-rw-r--r--gtk/gtkcssrule.c5
4 files changed, 191 insertions, 0 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 47fb2e09b9..42a4de55a0 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -398,6 +398,7 @@ gtk_private_h_sources = \
gtkcsscustomgadgetprivate.h \
gtkcsscustompropertyprivate.h \
gtkcssdeclarationprivate.h \
+ gtkcssdefinecolorruleprivate.h \
gtkcssdimensionvalueprivate.h \
gtkcsseasevalueprivate.h \
gtkcssenginevalueprivate.h \
@@ -676,6 +677,7 @@ gtk_base_c_sources = \
gtkcsscustomgadget.c \
gtkcsscustomproperty.c \
gtkcssdeclaration.c \
+ gtkcssdefinecolorrule.c \
gtkcssdimensionvalue.c \
gtkcsseasevalue.c \
gtkcssenumvalue.c \
diff --git a/gtk/gtkcssdefinecolorrule.c b/gtk/gtkcssdefinecolorrule.c
new file mode 100644
index 0000000000..7b9beac8b1
--- /dev/null
+++ b/gtk/gtkcssdefinecolorrule.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2016 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#include "config.h"
+
+#include "gtkcssdefinecolorruleprivate.h"
+
+#include "gtkcsscolorvalueprivate.h"
+#include "gtkcssstylesheetprivate.h"
+
+typedef struct _GtkCssDefineColorRulePrivate GtkCssDefineColorRulePrivate;
+struct _GtkCssDefineColorRulePrivate {
+ char *name;
+ GtkCssValue *color;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GtkCssDefineColorRule, gtk_css_define_color_rule, GTK_TYPE_CSS_RULE)
+
+static void
+gtk_css_define_color_rule_finalize (GObject *object)
+{
+ GtkCssDefineColorRule *define_color_rule = GTK_CSS_DEFINE_COLOR_RULE (object);
+ GtkCssDefineColorRulePrivate *priv = gtk_css_define_color_rule_get_instance_private (define_color_rule);
+
+ g_free (priv->name);
+ if (priv->color)
+ _gtk_css_value_unref (priv->color);
+
+ G_OBJECT_CLASS (gtk_css_define_color_rule_parent_class)->finalize (object);
+}
+
+static void
+gtk_css_define_color_rule_class_init (GtkCssDefineColorRuleClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gtk_css_define_color_rule_finalize;
+}
+
+static void
+gtk_css_define_color_rule_init (GtkCssDefineColorRule *define_color_rule)
+{
+}
+
+static GtkCssRule *
+gtk_css_define_color_rule_new (GtkCssRule *parent_rule,
+ GtkCssStyleSheet *parent_style_sheet,
+ const char *name,
+ GtkCssValue *color)
+{
+ return g_object_new (GTK_TYPE_CSS_DEFINE_COLOR_RULE, NULL);
+}
+
+GtkCssRule *
+gtk_css_define_color_rule_new_parse (GtkCssTokenSource *source,
+ GtkCssRule *parent_rule,
+ GtkCssStyleSheet *parent_style_sheet)
+{
+ const GtkCssToken *token;
+ GtkCssRule *result;
+ GtkCssValue *color;
+ char *name;
+
+ g_return_val_if_fail (source != NULL, NULL);
+ g_return_val_if_fail (parent_rule == NULL || GTK_IS_CSS_RULE (parent_rule), NULL);
+ g_return_val_if_fail (GTK_IS_CSS_STYLE_SHEET (parent_style_sheet), NULL);
+
+ token = gtk_css_token_source_get_token (source);
+ if (token->type != GTK_CSS_TOKEN_AT_KEYWORD ||
+ g_ascii_strcasecmp (token->string.string, "define-color") != 0)
+ {
+ gtk_css_token_source_error (source, "Expected '@define-color'");
+ gtk_css_token_source_consume_all (source);
+ return NULL;
+ }
+ gtk_css_token_source_consume_token (source);
+
+ 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 name of color");
+ gtk_css_token_source_consume_all (source);
+ return NULL;
+ }
+ name = g_strdup (token->string.string);
+ gtk_css_token_source_consume_token (source);
+
+ color = gtk_css_color_value_token_parse (source);
+ if (color == NULL)
+ {
+ g_free (name);
+ return NULL;
+ }
+
+ token = gtk_css_token_source_get_token (source);
+ if (!gtk_css_token_is (token, GTK_CSS_TOKEN_SEMICOLON))
+ {
+ gtk_css_token_source_error (source, "Expected ';' at end of @define-color");
+ gtk_css_token_source_consume_all (source);
+ g_free (name);
+ _gtk_css_value_unref (color);
+ return NULL;
+ }
+ gtk_css_token_source_consume_token (source);
+
+ result = gtk_css_define_color_rule_new (parent_rule, parent_style_sheet, name, color);
+ g_free (name);
+ _gtk_css_value_unref (color);
+ return result;
+}
+
diff --git a/gtk/gtkcssdefinecolorruleprivate.h b/gtk/gtkcssdefinecolorruleprivate.h
new file mode 100644
index 0000000000..30767268a0
--- /dev/null
+++ b/gtk/gtkcssdefinecolorruleprivate.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2016 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#ifndef __GTK_CSS_DEFINE_COLOR_RULE_PRIVATE_H__
+#define __GTK_CSS_DEFINE_COLOR_RULE_PRIVATE_H__
+
+#include "gtk/gtkcssruleprivate.h"
+#include "gtk/gtkcssvalueprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CSS_DEFINE_COLOR_RULE (gtk_css_define_color_rule_get_type ())
+#define GTK_CSS_DEFINE_COLOR_RULE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_DEFINE_COLOR_RULE, GtkCssDefineColorRule))
+#define GTK_CSS_DEFINE_COLOR_RULE_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_DEFINE_COLOR_RULE, GtkCssDefineColorRuleClass))
+#define GTK_IS_CSS_DEFINE_COLOR_RULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_DEFINE_COLOR_RULE))
+#define GTK_IS_CSS_DEFINE_COLOR_RULE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_DEFINE_COLOR_RULE))
+#define GTK_CSS_DEFINE_COLOR_RULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_DEFINE_COLOR_RULE, GtkCssDefineColorRuleClass))
+
+typedef struct _GtkCssDefineColorRule GtkCssDefineColorRule;
+typedef struct _GtkCssDefineColorRuleClass GtkCssDefineColorRuleClass;
+
+struct _GtkCssDefineColorRule
+{
+ GtkCssRule parent;
+};
+
+struct _GtkCssDefineColorRuleClass
+{
+ GtkCssRuleClass parent_class;
+};
+
+GType gtk_css_define_color_rule_get_type (void) G_GNUC_CONST;
+
+GtkCssRule * gtk_css_define_color_rule_new_parse (GtkCssTokenSource *source,
+ GtkCssRule *parent_rule,
+ GtkCssStyleSheet *parent_style_sheet);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_DEFINE_COLOR_RULE_PRIVATE_H__ */
diff --git a/gtk/gtkcssrule.c b/gtk/gtkcssrule.c
index c0211ce887..d2e99f4a44 100644
--- a/gtk/gtkcssrule.c
+++ b/gtk/gtkcssrule.c
@@ -21,6 +21,7 @@
#include "gtkcssruleprivate.h"
+#include "gtkcssdefinecolorruleprivate.h"
#include "gtkcssimportruleprivate.h"
#include "gtkcssstylesheetprivate.h"
@@ -181,6 +182,10 @@ gtk_css_rule_new_from_at_rule (GtkCssTokenSource *source,
{
rule = gtk_css_import_rule_new_parse (at_source, parent_rule, parent_style_sheet);
}
+ else if (g_ascii_strcasecmp (token->string.string, "define-color") == 0)
+ {
+ rule = gtk_css_define_color_rule_new_parse (at_source, parent_rule, parent_style_sheet);
+ }
else
{
gtk_css_token_source_unknown (at_source, "Unknown rule @%s", token->string.string);