diff options
author | Benjamin Otte <otte@redhat.com> | 2019-03-30 12:04:51 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2019-04-12 19:34:28 +0200 |
commit | d99ae4b6c2b7b9f1dd8d8f915fb57e584d4fa08e (patch) | |
tree | 574dafbbccd518ab56698590dfc4562e8f3bd0c5 /gtk/gtkcssimagecrossfade.c | |
parent | 96f9cbcabf48cd747d588d4732122fdccafe28a0 (diff) | |
download | gtk+-d99ae4b6c2b7b9f1dd8d8f915fb57e584d4fa08e.tar.gz |
cross-fade: Use gtk_css_parser_consume_any()
.. and gtk_css_parser_consume_function().
gtk_css_parser_consume_any() is a new function that implements the CSS
spec's any combinator ||.
Diffstat (limited to 'gtk/gtkcssimagecrossfade.c')
-rw-r--r-- | gtk/gtkcssimagecrossfade.c | 95 |
1 files changed, 58 insertions, 37 deletions
diff --git a/gtk/gtkcssimagecrossfade.c b/gtk/gtkcssimagecrossfade.c index cc22ecd800..080c2a2d1d 100644 --- a/gtk/gtkcssimagecrossfade.c +++ b/gtk/gtkcssimagecrossfade.c @@ -230,59 +230,80 @@ gtk_css_image_cross_fade_snapshot (GtkCssImage *image, } static gboolean -gtk_css_image_cross_fade_parse (GtkCssImage *image, - GtkCssParser *parser) +parse_progress (GtkCssParser *parser, + gpointer option_data, + gpointer user_data) { - GtkCssImageCrossFade *self = GTK_CSS_IMAGE_CROSS_FADE (image); - double progress; + double *progress = option_data; + GtkCssValue *number; + + number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_PERCENT | GTK_CSS_POSITIVE_ONLY); + if (number == NULL) + return FALSE; + *progress = _gtk_css_number_value_get (number, 1); + _gtk_css_value_unref (number); - if (!_gtk_css_parser_try (parser, "cross-fade(", TRUE)) + if (*progress > 1.0) { - _gtk_css_parser_error (parser, "Expected 'cross-fade('"); + _gtk_css_parser_error (parser, "Percentages over 100%% are not allowed"); return FALSE; } - if (gtk_css_number_value_can_parse (parser)) - { - GtkCssValue *number; - - number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_PERCENT | GTK_CSS_POSITIVE_ONLY); - if (number == NULL) - return FALSE; - progress = _gtk_css_number_value_get (number, 1); - _gtk_css_value_unref (number); - - if (progress > 1.0) - { - _gtk_css_parser_error (parser, "Percentages over 100%% are not allowed"); - return FALSE; - } - } - else - progress = 0.5; + return TRUE; +} - image = _gtk_css_image_new_parse (parser); - if (image == NULL) +static gboolean +parse_image (GtkCssParser *parser, + gpointer option_data, + gpointer user_data) +{ + GtkCssImage **image = option_data; + + *image = _gtk_css_image_new_parse (parser); + if (*image == NULL) return FALSE; - gtk_css_image_cross_fade_add (self, progress, image); + return TRUE; +} - if (_gtk_css_parser_try (parser, ",", TRUE)) +static guint +gtk_css_image_cross_fade_parse_arg (GtkCssParser *parser, + guint arg, + gpointer data) +{ + GtkCssImageCrossFade *self = data; + double progress = -1.0; + GtkCssImage *image = NULL; + GtkCssParseOption options[] = { - /* XXX: allow parsing colors here */ - image = _gtk_css_image_new_parse (parser); - if (image == NULL) - return FALSE; - gtk_css_image_cross_fade_add (self, 1.0 - progress, image); - } + { (void *) gtk_css_number_value_can_parse, parse_progress, &progress }, + { NULL, parse_image, &image }, + }; + + if (!gtk_css_parser_consume_any (parser, options, G_N_ELEMENTS (options), self)) + return 0; + + g_assert (image != NULL); + + /* XXX */ + if (progress < 0) + progress = 1.0 - self->total_progress; + gtk_css_image_cross_fade_add (self, progress, image); - if (!_gtk_css_parser_try (parser, ")", TRUE)) + return 1; +} + +static gboolean +gtk_css_image_cross_fade_parse (GtkCssImage *image, + GtkCssParser *parser) +{ + if (!gtk_css_parser_has_function (parser, "cross-fade")) { - _gtk_css_parser_error (parser, "Missing closing bracket"); + _gtk_css_parser_error (parser, "Expected 'cross-fade('"); return FALSE; } - return TRUE; + return gtk_css_parser_consume_function (parser, 1, G_MAXUINT, gtk_css_image_cross_fade_parse_arg, image); } static void |