diff options
author | Benjamin Otte <otte@redhat.com> | 2012-09-14 02:06:14 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-09-17 20:39:13 +0200 |
commit | eb6ad3562e7c38fb0f4d9f5806cef1afca45d48a (patch) | |
tree | 8db187df6403d4d96b74ca0401b06340001a59fe /gtk/gtkcssimagecrossfade.c | |
parent | a7ec3ba53fb9978cf6bae91816f80ad5f5cf88de (diff) | |
download | gtk+-eb6ad3562e7c38fb0f4d9f5806cef1afca45d48a.tar.gz |
cssimage: Implement (most of) current cross-fade syntax
The CSS4 spec adapted their cross-fade syntax again. Yay!
(The previous parser was completely broken anyway...)
Diffstat (limited to 'gtk/gtkcssimagecrossfade.c')
-rw-r--r-- | gtk/gtkcssimagecrossfade.c | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/gtk/gtkcssimagecrossfade.c b/gtk/gtkcssimagecrossfade.c index 424703af85..c08c89f630 100644 --- a/gtk/gtkcssimagecrossfade.c +++ b/gtk/gtkcssimagecrossfade.c @@ -145,32 +145,41 @@ gtk_css_image_cross_fade_parse (GtkCssImage *image, GtkCssParser *parser) { GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image); - GtkCssValue *number; - if (!_gtk_css_parser_try (parser, "cross-fade(", TRUE)) { _gtk_css_parser_error (parser, "Expected 'cross-fade('"); return FALSE; } - cross_fade->start = _gtk_css_image_new_parse (parser); - if (cross_fade->start == NULL) - return FALSE; - - if (!_gtk_css_parser_try (parser, ",", TRUE)) + if (_gtk_css_parser_has_number (parser)) { - _gtk_css_parser_error (parser, "Missing comma after first image"); - return FALSE; + GtkCssValue *number; + + number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_PERCENT | GTK_CSS_POSITIVE_ONLY); + if (number == NULL) + return FALSE; + cross_fade->progress = _gtk_css_number_value_get (number, 1); + _gtk_css_value_unref (number); + + if (cross_fade->progress > 1.0) + { + _gtk_css_parser_error (parser, "Percentages over 100%% are not allowed"); + return FALSE; + } } + else + cross_fade->progress = 0.5; - cross_fade->end = _gtk_css_image_new_parse (parser); - if (cross_fade->end == NULL) + cross_fade->start = _gtk_css_image_new_parse (parser); + if (cross_fade->start == NULL) return FALSE; - if (!_gtk_css_parser_try (parser, ",", TRUE)) + if (_gtk_css_parser_try (parser, ",", TRUE)) { - _gtk_css_parser_error (parser, "Missing comma after second image"); - return FALSE; + /* XXX: allow parsing colors here */ + cross_fade->end = _gtk_css_image_new_parse (parser); + if (cross_fade->end == NULL) + return FALSE; } if (!_gtk_css_parser_try (parser, ")", TRUE)) @@ -179,19 +188,6 @@ gtk_css_image_cross_fade_parse (GtkCssImage *image, return FALSE; } - number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_PERCENT | GTK_CSS_POSITIVE_ONLY); - if (number == NULL) - return FALSE; - cross_fade->progress = _gtk_css_number_value_get (number, 1); - _gtk_css_value_unref (number); - - if (cross_fade->progress > 100) - { - _gtk_css_parser_error (parser, "Percentages ovre 100%% are not allowed"); - return FALSE; - } - cross_fade->progress /= 100.0; - return TRUE; } @@ -201,18 +197,21 @@ gtk_css_image_cross_fade_print (GtkCssImage *image, { GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image); - g_string_append (string, "cross_fade("); + g_string_append (string, "cross-fade("); + if (cross_fade->progress != 0.5) + { + g_string_append_printf (string, "%g%% ", cross_fade->progress * 100.0); + } + if (cross_fade->start) _gtk_css_image_print (cross_fade->start, string); else g_string_append (string, "none"); - g_string_append (string, ","); if (cross_fade->end) - _gtk_css_image_print (cross_fade->end, string); - else - g_string_append (string, "none"); - g_string_append (string, ","); - g_string_append_printf (string, "%g%%", cross_fade->progress * 100.0); + { + g_string_append (string, ", "); + _gtk_css_image_print (cross_fade->end, string); + } g_string_append (string, ")"); } |