[gtk+/wip/otte/tokenizer: 71/78] cssimage: Move fallback token parser to -gtk-gradient()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/tokenizer: 71/78] cssimage: Move fallback token parser to -gtk-gradient()
- Date: Fri, 25 Nov 2016 22:43:37 +0000 (UTC)
commit 02f31d7133f0363a250070d7fd34169f9a77c549
Author: Benjamin Otte <otte redhat com>
Date: Sun Apr 3 04:07:03 2016 +0200
cssimage: Move fallback token parser to -gtk-gradient()
Every other image type has a real token parser now.
gtk/gtkcssimage.c | 32 -----------------------------
gtk/gtkcssimagegradient.c | 41 ++++++++++++++++++++++++++++++++++++++
gtk/gtkcssimagegradientprivate.h | 3 +-
3 files changed, 43 insertions(+), 33 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index b98f23c..6ea8222 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -97,37 +97,6 @@ gtk_css_image_real_transition (GtkCssImage *start,
}
static void
-forward_error_to_source (GtkCssParser *parser,
- const GError *error,
- gpointer source)
-{
- /* XXX: This is bad because it doesn't emit the error on the right token */
- gtk_css_token_source_emit_error (source, error);
-}
-
-static gboolean
-gtk_css_image_real_token_parse (GtkCssImage *image,
- GtkCssTokenSource *source)
-{
- GtkCssImageClass *klass;
- GtkCssParser *parser;
- char *str;
- gboolean success;
-
- str = gtk_css_token_source_consume_to_string (source);
- parser = _gtk_css_parser_new (str,
- NULL,
- forward_error_to_source,
- source);
- klass = GTK_CSS_IMAGE_GET_CLASS (image);
- success = klass->parse (image, parser);
- _gtk_css_parser_free (parser);
- g_free (str);
-
- return success;
-}
-
-static void
_gtk_css_image_class_init (GtkCssImageClass *klass)
{
klass->get_width = gtk_css_image_real_get_width;
@@ -136,7 +105,6 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->compute = gtk_css_image_real_compute;
klass->equal = gtk_css_image_real_equal;
klass->transition = gtk_css_image_real_transition;
- klass->token_parse = gtk_css_image_real_token_parse;
}
static void
diff --git a/gtk/gtkcssimagegradient.c b/gtk/gtkcssimagegradient.c
index 6ba993b..dbf200c 100644
--- a/gtk/gtkcssimagegradient.c
+++ b/gtk/gtkcssimagegradient.c
@@ -263,6 +263,17 @@ gtk_css_image_gradient_parse (GtkCssImage *image,
return gradient->gradient != NULL;
}
+static gboolean
+gtk_css_image_gradient_token_parse (GtkCssImage *image,
+ GtkCssTokenSource *source)
+{
+ GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
+
+ gradient->gradient = gtk_gradient_token_parse (source);
+
+ return gradient->gradient != NULL;
+}
+
static void
gtk_css_image_gradient_print (GtkCssImage *image,
GString *string)
@@ -304,6 +315,7 @@ _gtk_css_image_gradient_class_init (GtkCssImageGradientClass *klass)
image_class->transition = gtk_css_image_gradient_transition;
image_class->draw = gtk_css_image_gradient_draw;
image_class->parse = gtk_css_image_gradient_parse;
+ image_class->token_parse = gtk_css_image_gradient_token_parse;
image_class->print = gtk_css_image_gradient_print;
object_class->dispose = gtk_css_image_gradient_dispose;
@@ -505,3 +517,32 @@ _gtk_gradient_parse (GtkCssParser *parser)
return gradient;
}
+
+static void
+forward_error_to_source (GtkCssParser *parser,
+ const GError *error,
+ gpointer source)
+{
+ /* XXX: This is bad because it doesn't emit the error on the right token */
+ gtk_css_token_source_emit_error (source, error);
+}
+
+GtkGradient *
+gtk_gradient_token_parse (GtkCssTokenSource *source)
+{
+ GtkCssParser *parser;
+ GtkGradient *gradient;
+ char *str;
+
+ str = gtk_css_token_source_consume_to_string (source);
+ parser = _gtk_css_parser_new (str,
+ NULL,
+ forward_error_to_source,
+ source);
+ gradient = _gtk_gradient_parse (parser);
+ _gtk_css_parser_free (parser);
+ g_free (str);
+
+ return gradient;
+}
+
diff --git a/gtk/gtkcssimagegradientprivate.h b/gtk/gtkcssimagegradientprivate.h
index 4875435..924c47f 100644
--- a/gtk/gtkcssimagegradientprivate.h
+++ b/gtk/gtkcssimagegradientprivate.h
@@ -52,7 +52,8 @@ struct _GtkCssImageGradientClass
GType _gtk_css_image_gradient_get_type (void) G_GNUC_CONST;
/* for lack of a better place to put it */
-GtkGradient * _gtk_gradient_parse (GtkCssParser *parser);
+GtkGradient * _gtk_gradient_parse (GtkCssParser *parser);
+GtkGradient * gtk_gradient_token_parse (GtkCssTokenSource *source);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]