[gtk+/wip/css: 134/154] Introduce _gtk_css_parser_try_length



commit 9d4d13201cf32ce9b6a312ec383274f2e04c4998
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Jan 5 15:47:23 2012 +0100

    Introduce _gtk_css_parser_try_length
    
    This starts to introduce the proper API abstraction for when we will
    support different units

 gtk/gtkcssparser.c        |   17 +++++++++++++++++
 gtk/gtkcssparserprivate.h |    6 ++++--
 gtk/gtkcssstylefuncs.c    |   16 +++++++---------
 3 files changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssparser.c b/gtk/gtkcssparser.c
index 8bdcfc2..a136466 100644
--- a/gtk/gtkcssparser.c
+++ b/gtk/gtkcssparser.c
@@ -578,6 +578,23 @@ _gtk_css_parser_try_double (GtkCssParser *parser,
   return TRUE;
 }
 
+/* XXX: we should introduce GtkCssLenght that deals with
+ * different kind of units */
+gboolean
+_gtk_css_parser_try_length (GtkCssParser *parser,
+                            int          *value)
+{
+  if (!_gtk_css_parser_try_int (parser, value))
+    return FALSE;
+
+  /* FIXME: _try_uint skips spaces while the
+   * spec forbids them
+   */
+  _gtk_css_parser_try (parser, "px", TRUE);
+
+  return TRUE;
+}
+
 gboolean
 _gtk_css_parser_try_enum (GtkCssParser *parser,
 			  GType         enum_type,
diff --git a/gtk/gtkcssparserprivate.h b/gtk/gtkcssparserprivate.h
index f751b73..35c01ea 100644
--- a/gtk/gtkcssparserprivate.h
+++ b/gtk/gtkcssparserprivate.h
@@ -72,9 +72,11 @@ gboolean        _gtk_css_parser_try_uint          (GtkCssParser          *parser
                                                    guint                 *value);
 gboolean        _gtk_css_parser_try_double        (GtkCssParser          *parser,
                                                    gdouble               *value);
+gboolean        _gtk_css_parser_try_length        (GtkCssParser          *parser,
+                                                   int                   *value);
 gboolean        _gtk_css_parser_try_enum          (GtkCssParser          *parser,
-						   GType                  enum_type,
-						   int                   *value);
+                                                   GType                  enum_type,
+                                                   int                   *value);
 
 void            _gtk_css_parser_skip_whitespace   (GtkCssParser          *parser);
 char *          _gtk_css_parser_read_string       (GtkCssParser          *parser);
diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c
index 7b53bbb..8595699 100644
--- a/gtk/gtkcssstylefuncs.c
+++ b/gtk/gtkcssstylefuncs.c
@@ -646,7 +646,8 @@ border_value_parse (GtkCssParser *parser,
                     GValue       *value)
 {
   GtkBorder border = { 0, };
-  guint i, numbers[4];
+  guint i;
+  int numbers[4];
 
   for (i = 0; i < G_N_ELEMENTS (numbers); i++)
     {
@@ -654,7 +655,7 @@ border_value_parse (GtkCssParser *parser,
 	{
 	  /* These are strictly speaking signed, but we want to be able to use them
 	     for unsigned types too, as the actual ranges of values make this safe */
-	  int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
+	  int res = _gtk_win32_theme_int_parse (parser, base, &numbers[i]);
 
 	  if (res == 0) /* Parse error, report */
 	    return FALSE;
@@ -663,13 +664,10 @@ border_value_parse (GtkCssParser *parser,
 	    break;
 	}
       else
-	{
-	  if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
-	    break;
-
-	  /* XXX: shouldn't allow spaces here? */
-	  _gtk_css_parser_try (parser, "px", TRUE);
-	}
+        {
+          if (!_gtk_css_parser_try_length (parser, &numbers[i]))
+            break;
+        }
     }
 
   if (i == 0)



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