[gtk+/wip/css: 21/36] cssimage: Implement (most of) current cross-fade syntax



commit c36992ff0da5949475531abd02ecd5493da00dd3
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 14 02:06:14 2012 +0200

    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...)

 gtk/gtkcssimagecrossfade.c |   67 +++++++++++++++++++++----------------------
 1 files changed, 33 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkcssimagecrossfade.c b/gtk/gtkcssimagecrossfade.c
index 424703a..c08c89f 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, ")");
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]