[gtk+/wip/css: 112/125] styleproperty: Use factored-out gradient parser



commit 75c5034bd9b9a324fb81074a32d29e8f0f42ad82
Author: Benjamin Otte <otte redhat com>
Date:   Tue Dec 20 15:47:03 2011 +0100

    styleproperty: Use factored-out gradient parser

 gtk/gtkcssstylefuncs.c |  185 +----------------------------------------------
 1 files changed, 4 insertions(+), 181 deletions(-)
---
diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c
index a7b31f1..c179179 100644
--- a/gtk/gtkcssstylefuncs.c
+++ b/gtk/gtkcssstylefuncs.c
@@ -30,6 +30,7 @@
 #include <cairo-gobject.h>
 
 #include "gtkanimationdescription.h"
+#include "gtkcssimagegradientprivate.h"
 #include "gtkcssprovider.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkgradient.h"
@@ -705,188 +706,10 @@ gradient_value_parse (GtkCssParser *parser,
                       GValue       *value)
 {
   GtkGradient *gradient;
-  cairo_pattern_type_t type;
-  gdouble coords[6];
-  guint i;
-
-  if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
-    {
-      _gtk_css_parser_error (parser,
-                             "Expected '-gtk-gradient'");
-      return FALSE;
-    }
-
-  if (!_gtk_css_parser_try (parser, "(", TRUE))
-    {
-      _gtk_css_parser_error (parser,
-                             "Expected '(' after '-gtk-gradient'");
-      return FALSE;
-    }
-
-  /* Parse gradient type */
-  if (_gtk_css_parser_try (parser, "linear", TRUE))
-    type = CAIRO_PATTERN_TYPE_LINEAR;
-  else if (_gtk_css_parser_try (parser, "radial", TRUE))
-    type = CAIRO_PATTERN_TYPE_RADIAL;
-  else
-    {
-      _gtk_css_parser_error (parser,
-                             "Gradient type must be 'radial' or 'linear'");
-      return FALSE;
-    }
-
-  /* Parse start/stop position parameters */
-  for (i = 0; i < 2; i++)
-    {
-      if (! _gtk_css_parser_try (parser, ",", TRUE))
-        {
-          _gtk_css_parser_error (parser,
-                                 "Expected ','");
-          return FALSE;
-        }
-
-      if (_gtk_css_parser_try (parser, "left", TRUE))
-        coords[i * 3] = 0;
-      else if (_gtk_css_parser_try (parser, "right", TRUE))
-        coords[i * 3] = 1;
-      else if (_gtk_css_parser_try (parser, "center", TRUE))
-        coords[i * 3] = 0.5;
-      else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
-        {
-          _gtk_css_parser_error (parser,
-                                 "Expected a valid X coordinate");
-          return FALSE;
-        }
-
-      if (_gtk_css_parser_try (parser, "top", TRUE))
-        coords[i * 3 + 1] = 0;
-      else if (_gtk_css_parser_try (parser, "bottom", TRUE))
-        coords[i * 3 + 1] = 1;
-      else if (_gtk_css_parser_try (parser, "center", TRUE))
-        coords[i * 3 + 1] = 0.5;
-      else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
-        {
-          _gtk_css_parser_error (parser,
-                                 "Expected a valid Y coordinate");
-          return FALSE;
-        }
-
-      if (type == CAIRO_PATTERN_TYPE_RADIAL)
-        {
-          /* Parse radius */
-          if (! _gtk_css_parser_try (parser, ",", TRUE))
-            {
-              _gtk_css_parser_error (parser,
-                                     "Expected ','");
-              return FALSE;
-            }
-
-          if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
-            {
-              _gtk_css_parser_error (parser,
-                                     "Expected a numer for the radius");
-              return FALSE;
-            }
-        }
-    }
-
-  if (type == CAIRO_PATTERN_TYPE_LINEAR)
-    gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
-  else
-    gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
-                                        coords[3], coords[4], coords[5]);
-
-  while (_gtk_css_parser_try (parser, ",", TRUE))
-    {
-      GtkSymbolicColor *color;
-      gdouble position;
 
-      if (_gtk_css_parser_try (parser, "from", TRUE))
-        {
-          position = 0;
-
-          if (!_gtk_css_parser_try (parser, "(", TRUE))
-            {
-              gtk_gradient_unref (gradient);
-              _gtk_css_parser_error (parser,
-                                     "Expected '('");
-              return FALSE;
-            }
-
-        }
-      else if (_gtk_css_parser_try (parser, "to", TRUE))
-        {
-          position = 1;
-
-          if (!_gtk_css_parser_try (parser, "(", TRUE))
-            {
-              gtk_gradient_unref (gradient);
-              _gtk_css_parser_error (parser,
-                                     "Expected '('");
-              return FALSE;
-            }
-
-        }
-      else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
-        {
-          if (!_gtk_css_parser_try (parser, "(", TRUE))
-            {
-              gtk_gradient_unref (gradient);
-              _gtk_css_parser_error (parser,
-                                     "Expected '('");
-              return FALSE;
-            }
-
-          if (!_gtk_css_parser_try_double (parser, &position))
-            {
-              gtk_gradient_unref (gradient);
-              _gtk_css_parser_error (parser,
-                                     "Expected a valid number");
-              return FALSE;
-            }
-
-          if (!_gtk_css_parser_try (parser, ",", TRUE))
-            {
-              gtk_gradient_unref (gradient);
-              _gtk_css_parser_error (parser,
-                                     "Expected a comma");
-              return FALSE;
-            }
-        }
-      else
-        {
-          gtk_gradient_unref (gradient);
-          _gtk_css_parser_error (parser,
-                                 "Not a valid color-stop definition");
-          return FALSE;
-        }
-
-      color = _gtk_css_parser_read_symbolic_color (parser);
-      if (color == NULL)
-        {
-          gtk_gradient_unref (gradient);
-          return FALSE;
-        }
-
-      gtk_gradient_add_color_stop (gradient, position, color);
-      gtk_symbolic_color_unref (color);
-
-      if (!_gtk_css_parser_try (parser, ")", TRUE))
-        {
-          gtk_gradient_unref (gradient);
-          _gtk_css_parser_error (parser,
-                                 "Expected ')'");
-          return FALSE;
-        }
-    }
-
-  if (!_gtk_css_parser_try (parser, ")", TRUE))
-    {
-      gtk_gradient_unref (gradient);
-      _gtk_css_parser_error (parser,
-                             "Expected ')'");
-      return FALSE;
-    }
+  gradient = _gtk_gradient_parse (parser);
+  if (gradient == NULL)
+    return FALSE;
 
   g_value_take_boxed (value, gradient);
   return TRUE;



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