[gtk+/wip/otte/tokenizer: 31/42] css: Add token parser for bgsize values



commit 52b6c93d5782e69b5729c875cc930d67f5305a49
Author: Benjamin Otte <otte redhat com>
Date:   Fri Mar 18 20:23:25 2016 +0100

    css: Add token parser for bgsize values

 gtk/gtkcssbgsizevalue.c        |   59 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssbgsizevalueprivate.h |    4 ++-
 gtk/gtkcssstylepropertyimpl.c  |    9 +++++-
 3 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssbgsizevalue.c b/gtk/gtkcssbgsizevalue.c
index b5da067..168f0b4 100644
--- a/gtk/gtkcssbgsizevalue.c
+++ b/gtk/gtkcssbgsizevalue.c
@@ -212,6 +212,65 @@ _gtk_css_bg_size_value_parse (GtkCssParser *parser)
   return _gtk_css_bg_size_value_new (x, y);
 }
 
+GtkCssValue *
+gtk_css_bg_size_value_token_parse (GtkCssTokenSource *source)
+{
+  const GtkCssToken *token;
+  GtkCssValue *x, *y;
+
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_token_is_ident (token, "cover"))
+    {
+      gtk_css_token_source_consume_token (source);
+      return _gtk_css_value_ref (&cover_singleton);
+    }
+  if (gtk_css_token_is_ident (token, "contain"))
+    {
+      gtk_css_token_source_consume_token (source);
+      return _gtk_css_value_ref (&contain_singleton);
+    }
+
+  if (gtk_css_token_is_ident (token, "auto"))
+    {
+      gtk_css_token_source_consume_token (source);
+      x = NULL;
+    }
+  else
+    {
+      x = gtk_css_number_value_token_parse (source,
+                                            GTK_CSS_POSITIVE_ONLY
+                                            | GTK_CSS_PARSE_PERCENT
+                                            | GTK_CSS_PARSE_LENGTH);
+      if (x == NULL)
+        return NULL;
+    }
+
+  token = gtk_css_token_source_get_token (source);
+  if (gtk_css_token_is_ident (token, "auto"))
+    {
+      gtk_css_token_source_consume_token (source);
+      y = NULL;
+    }
+  else if (!gtk_css_number_value_check_token (token))
+    {
+      y = NULL;
+    }
+  else
+    {
+      y = gtk_css_number_value_token_parse (source,
+                                            GTK_CSS_POSITIVE_ONLY
+                                            | GTK_CSS_PARSE_PERCENT
+                                            | GTK_CSS_PARSE_LENGTH);
+      if (y == NULL)
+        {
+          _gtk_css_value_unref (x);
+          return NULL;
+        }
+    }
+
+  return _gtk_css_bg_size_value_new (x, y);
+}
+
 static void
 gtk_css_bg_size_compute_size_for_cover_contain (gboolean     cover,
                                                 GtkCssImage *image,
diff --git a/gtk/gtkcssbgsizevalueprivate.h b/gtk/gtkcssbgsizevalueprivate.h
index 5f31ff2..4bcd5ec 100644
--- a/gtk/gtkcssbgsizevalueprivate.h
+++ b/gtk/gtkcssbgsizevalueprivate.h
@@ -20,8 +20,9 @@
 #ifndef __GTK_CSS_BG_SIZE_VALUE_PRIVATE_H__
 #define __GTK_CSS_BG_SIZE_VALUE_PRIVATE_H__
 
-#include "gtkcssparserprivate.h"
 #include "gtkcssimageprivate.h"
+#include "gtkcssparserprivate.h"
+#include "gtkcsstokensourceprivate.h"
 #include "gtkcssvalueprivate.h"
 
 G_BEGIN_DECLS
@@ -29,6 +30,7 @@ G_BEGIN_DECLS
 GtkCssValue *   _gtk_css_bg_size_value_new          (GtkCssValue            *x,
                                                      GtkCssValue            *y);
 GtkCssValue *   _gtk_css_bg_size_value_parse        (GtkCssParser           *parser);
+GtkCssValue *   gtk_css_bg_size_value_token_parse   (GtkCssTokenSource      *source);
 
 void            _gtk_css_bg_size_value_compute_size (const GtkCssValue      *bg_size,
                                                      GtkCssImage            *image,
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index abd9987..5c06b6d 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1438,6 +1438,13 @@ background_size_parse (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
+background_size_token_parse (GtkCssTokenSource   *source,
+                             GtkCssStyleProperty *property)
+{
+  return gtk_css_array_value_token_parse (source, gtk_css_bg_size_value_token_parse);
+}
+
+static GtkCssValue *
 background_position_parse (GtkCssStyleProperty *property,
                           GtkCssParser        *parser)
 {
@@ -1962,7 +1969,7 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_STYLE_PROPERTY_ANIMATED,
                                           GTK_CSS_AFFECTS_BACKGROUND,
                                           background_size_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          background_size_token_parse,
                                           NULL,
                                           NULL,
                                           _gtk_css_array_value_new (_gtk_css_bg_size_value_new (NULL, 
NULL)));


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