[gtk+/wip/otte/tokenizer: 27/42] css: A token parse func for repeat values



commit 9c0b1f19b5c8b507a0cae0510f8af9f88bb9cc30
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 18 00:15:00 2016 +0100

    css: A token parse func for repeat values

 gtk/gtkcssrepeatvalue.c        |   97 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssrepeatvalueprivate.h |    3 +
 gtk/gtkcssstylepropertyimpl.c  |   11 ++++-
 3 files changed, 109 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssrepeatvalue.c b/gtk/gtkcssrepeatvalue.c
index e3cfcd0..a9b523b 100644
--- a/gtk/gtkcssrepeatvalue.c
+++ b/gtk/gtkcssrepeatvalue.c
@@ -205,6 +205,60 @@ _gtk_css_background_repeat_value_try_parse (GtkCssParser *parser)
   return _gtk_css_background_repeat_value_new (x, y);
 }
 
+static gboolean
+gtk_css_background_repeat_value_from_token (const GtkCssToken *token,
+                                            GtkCssRepeatStyle *style)
+{
+  if (gtk_css_token_is_ident (token, "repeat"))
+    *style = GTK_CSS_REPEAT_STYLE_REPEAT;
+  else if (gtk_css_token_is_ident (token, "space"))
+    *style = GTK_CSS_REPEAT_STYLE_SPACE;
+  else if (gtk_css_token_is_ident (token, "round"))
+    *style = GTK_CSS_REPEAT_STYLE_ROUND;
+  else if (gtk_css_token_is_ident (token, "no-repeat"))
+    *style = GTK_CSS_REPEAT_STYLE_NO_REPEAT;
+  else
+    return FALSE;
+
+  return TRUE;
+}
+
+GtkCssValue *
+gtk_css_background_repeat_value_token_parse (GtkCssTokenSource *source)
+{
+  GtkCssRepeatStyle x, y;
+  const GtkCssToken *token;
+
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_token_is_ident (token, "repeat-x"))
+    {
+      gtk_css_token_source_consume_token (source);
+      return _gtk_css_background_repeat_value_new (GTK_CSS_REPEAT_STYLE_REPEAT, 
GTK_CSS_REPEAT_STYLE_NO_REPEAT);
+    }
+  if (gtk_css_token_is_ident (token, "repeat-y"))
+    {
+      gtk_css_token_source_consume_token (source);
+      return _gtk_css_background_repeat_value_new (GTK_CSS_REPEAT_STYLE_NO_REPEAT, 
GTK_CSS_REPEAT_STYLE_REPEAT);
+    }
+
+  if (!gtk_css_background_repeat_value_from_token (token, &x))
+    {
+      gtk_css_token_source_error (source, "Not a repeat-style");
+      gtk_css_token_source_consume_all (source);
+      return NULL;
+    }
+
+  gtk_css_token_source_consume_token (source);
+  gtk_css_token_source_consume_whitespace (source);
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_background_repeat_value_from_token (token, &y))
+    gtk_css_token_source_consume_token (source);
+  else
+    y = x;
+
+  return _gtk_css_background_repeat_value_new (x, y);
+}
+
 GtkCssRepeatStyle
 _gtk_css_background_repeat_value_get_x (const GtkCssValue *repeat)
 {
@@ -294,6 +348,49 @@ _gtk_css_border_repeat_value_try_parse (GtkCssParser *parser)
   return _gtk_css_border_repeat_value_new (x, y);
 }
 
+static gboolean
+gtk_css_border_repeat_value_from_token (const GtkCssToken *token,
+                                        GtkCssRepeatStyle *style)
+{
+  if (gtk_css_token_is_ident (token, "repeat"))
+    *style = GTK_CSS_REPEAT_STYLE_REPEAT;
+  else if (gtk_css_token_is_ident (token, "space"))
+    *style = GTK_CSS_REPEAT_STYLE_SPACE;
+  else if (gtk_css_token_is_ident (token, "round"))
+    *style = GTK_CSS_REPEAT_STYLE_ROUND;
+  else if (gtk_css_token_is_ident (token, "stretch"))
+    *style = GTK_CSS_REPEAT_STYLE_STRETCH;
+  else
+    return FALSE;
+
+  return TRUE;
+}
+
+GtkCssValue *
+gtk_css_border_repeat_value_token_parse (GtkCssTokenSource *source)
+{
+  GtkCssRepeatStyle x, y;
+  const GtkCssToken *token;
+
+  token = gtk_css_token_source_get_token (source);
+  if (!gtk_css_border_repeat_value_from_token (token, &x))
+    {
+      gtk_css_token_source_error (source, "Not a repeat style");
+      gtk_css_token_source_consume_all (source);
+      return NULL;
+    }
+
+  gtk_css_token_source_consume_token (source);
+  gtk_css_token_source_consume_whitespace (source);
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_border_repeat_value_from_token (token, &y))
+    gtk_css_token_source_consume_token (source);
+  else
+    y = x;
+
+  return _gtk_css_border_repeat_value_new (x, y);
+}
+
 GtkCssRepeatStyle
 _gtk_css_border_repeat_value_get_x (const GtkCssValue *repeat)
 {
diff --git a/gtk/gtkcssrepeatvalueprivate.h b/gtk/gtkcssrepeatvalueprivate.h
index 7e8baa3..8d3453d 100644
--- a/gtk/gtkcssrepeatvalueprivate.h
+++ b/gtk/gtkcssrepeatvalueprivate.h
@@ -21,6 +21,7 @@
 #define __GTK_CSS_REPEAT_VALUE_PRIVATE_H__
 
 #include "gtkcssparserprivate.h"
+#include "gtkcsstokensourceprivate.h"
 #include "gtkcssvalueprivate.h"
 
 G_BEGIN_DECLS
@@ -36,12 +37,14 @@ typedef enum {
 GtkCssValue *       _gtk_css_background_repeat_value_new        (GtkCssRepeatStyle       x,
                                                                  GtkCssRepeatStyle       y);
 GtkCssValue *       _gtk_css_background_repeat_value_try_parse  (GtkCssParser           *parser);
+GtkCssValue *       gtk_css_background_repeat_value_token_parse (GtkCssTokenSource      *source);
 GtkCssRepeatStyle   _gtk_css_background_repeat_value_get_x      (const GtkCssValue      *repeat);
 GtkCssRepeatStyle   _gtk_css_background_repeat_value_get_y      (const GtkCssValue      *repeat);
 
 GtkCssValue *       _gtk_css_border_repeat_value_new            (GtkCssRepeatStyle       x,
                                                                  GtkCssRepeatStyle       y);
 GtkCssValue *       _gtk_css_border_repeat_value_try_parse      (GtkCssParser           *parser);
+GtkCssValue *       gtk_css_border_repeat_value_token_parse     (GtkCssTokenSource      *source);
 GtkCssRepeatStyle   _gtk_css_border_repeat_value_get_x          (const GtkCssValue      *repeat);
 GtkCssRepeatStyle   _gtk_css_border_repeat_value_get_y          (const GtkCssValue      *repeat);
 
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 2f46d7a..927613f 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1412,6 +1412,13 @@ background_repeat_value_parse (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
+background_repeat_value_token_parse (GtkCssTokenSource   *source,
+                                     GtkCssStyleProperty *property)
+{
+  return gtk_css_array_value_token_parse (source, gtk_css_background_repeat_value_token_parse);
+}
+
+static GtkCssValue *
 background_size_parse (GtkCssStyleProperty *property,
                        GtkCssParser        *parser)
 {
@@ -2009,7 +2016,7 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           GTK_CSS_AFFECTS_BACKGROUND,
                                           background_repeat_value_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          background_repeat_value_token_parse,
                                           NULL,
                                           NULL,
                                           _gtk_css_array_value_new (_gtk_css_background_repeat_value_new 
(GTK_CSS_REPEAT_STYLE_REPEAT,
@@ -2041,7 +2048,7 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           GTK_CSS_AFFECTS_BORDER,
                                           border_image_repeat_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          (GtkCssStylePropertyTokenParseFunc) 
gtk_css_border_repeat_value_token_parse,
                                           NULL,
                                           NULL,
                                           _gtk_css_border_repeat_value_new (GTK_CSS_REPEAT_STYLE_STRETCH,


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