[gtk+/wip/otte/tokenizer: 24/42] css: Add a token parser for border values



commit b3b050fbf5431469945248fa5d8674c9db8a35b8
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 17 03:42:03 2016 +0100

    css: Add a token parser for border values

 gtk/gtkcssbordervalue.c        |   70 ++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssbordervalueprivate.h |    5 +++
 gtk/gtkcssstylepropertyimpl.c  |   29 +++++++++++++++-
 3 files changed, 102 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssbordervalue.c b/gtk/gtkcssbordervalue.c
index 0b68d86..5f9d236 100644
--- a/gtk/gtkcssbordervalue.c
+++ b/gtk/gtkcssbordervalue.c
@@ -205,6 +205,76 @@ _gtk_css_border_value_parse (GtkCssParser           *parser,
 }
 
 GtkCssValue *
+gtk_css_border_value_token_parse (GtkCssTokenSource      *source,
+                                  GtkCssNumberParseFlags  flags,
+                                  gboolean                allow_auto,
+                                  gboolean                allow_fill)
+{
+  GtkCssValue *result;
+  const GtkCssToken *token;
+  int i;
+
+  result = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
+
+  token = gtk_css_token_source_get_token (source);
+  if (allow_fill && gtk_css_token_is_ident (token, "fill"))
+    {
+      result->fill = TRUE;
+      gtk_css_token_source_consume_token (source);
+      gtk_css_token_source_consume_whitespace (source);
+      token = gtk_css_token_source_get_token (source);
+    }
+
+  for (i = 0;
+       !gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
+       i++, token = gtk_css_token_source_get_token (source))
+    {
+      if (allow_fill && !result->fill && gtk_css_token_is_ident (token, "fill"))
+        {
+          result->fill = TRUE;
+          gtk_css_token_source_consume_token (source);
+          gtk_css_token_source_consume_whitespace (source);
+          i--;
+          break;
+        }
+
+      if (allow_auto && gtk_css_token_is_ident (token, "auto"))
+        {
+          gtk_css_token_source_consume_token (source);
+          gtk_css_token_source_consume_whitespace (source);
+          continue;
+        }
+
+      if (i == 4)
+        break;
+
+      result->values[i] = gtk_css_number_value_token_parse (source, flags);
+      if (result->values[i] == NULL)
+        {
+          _gtk_css_value_unref (result);
+          return NULL;
+        }
+      gtk_css_token_source_consume_whitespace (source);
+    }
+
+  if (i <= 0)
+    {
+      gtk_css_token_source_error (source, "Expected a number");
+      gtk_css_token_source_consume_all (source);
+      _gtk_css_value_unref (result);
+      return NULL;
+    }
+
+  for (; i < 4; i++)
+    {
+      if (result->values[(i - 1) >> 1])
+        result->values[i] = _gtk_css_value_ref (result->values[(i - 1) >> 1]);
+    }
+
+  return result;
+}
+
+GtkCssValue *
 _gtk_css_border_value_get_top (const GtkCssValue *value)
 {
   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_BORDER, NULL);
diff --git a/gtk/gtkcssbordervalueprivate.h b/gtk/gtkcssbordervalueprivate.h
index fe49904..69e405a 100644
--- a/gtk/gtkcssbordervalueprivate.h
+++ b/gtk/gtkcssbordervalueprivate.h
@@ -21,6 +21,7 @@
 #define __GTK_CSS_BORDER_VALUE_PRIVATE_H__
 
 #include "gtkcssparserprivate.h"
+#include "gtkcsstokensourceprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssvalueprivate.h"
 
@@ -34,6 +35,10 @@ GtkCssValue *   _gtk_css_border_value_parse         (GtkCssParser           *par
                                                      GtkCssNumberParseFlags  flags,
                                                      gboolean                allow_auto,
                                                      gboolean                allow_fill);
+GtkCssValue *   gtk_css_border_value_token_parse    (GtkCssTokenSource      *source,
+                                                     GtkCssNumberParseFlags  flags,
+                                                     gboolean                allow_auto,
+                                                     gboolean                allow_fill);
 
 GtkCssValue *   _gtk_css_border_value_get_top       (const GtkCssValue      *value);
 GtkCssValue *   _gtk_css_border_value_get_right     (const GtkCssValue      *value);
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 2d1ff54..1be55c3 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -1123,6 +1123,18 @@ border_image_slice_parse (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
+border_image_slice_token_parse (GtkCssTokenSource   *source,
+                                GtkCssStyleProperty *property)
+{
+  return gtk_css_border_value_token_parse (source,
+                                           GTK_CSS_PARSE_PERCENT
+                                           | GTK_CSS_PARSE_NUMBER
+                                           | GTK_CSS_POSITIVE_ONLY,
+                                           FALSE,
+                                           TRUE);
+}
+
+static GtkCssValue *
 border_image_width_parse (GtkCssStyleProperty *property,
                           GtkCssParser        *parser)
 {
@@ -1136,6 +1148,19 @@ border_image_width_parse (GtkCssStyleProperty *property,
 }
 
 static GtkCssValue *
+border_image_width_token_parse (GtkCssTokenSource   *source,
+                                GtkCssStyleProperty *property)
+{
+  return gtk_css_border_value_token_parse (source,
+                                           GTK_CSS_PARSE_PERCENT
+                                           | GTK_CSS_PARSE_LENGTH
+                                           | GTK_CSS_PARSE_NUMBER
+                                           | GTK_CSS_POSITIVE_ONLY,
+                                           TRUE,
+                                           FALSE);
+}
+
+static GtkCssValue *
 minmax_parse (GtkCssStyleProperty *property,
               GtkCssParser        *parser)
 {
@@ -2021,7 +2046,7 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           GTK_CSS_AFFECTS_BORDER,
                                           border_image_slice_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          border_image_slice_token_parse,
                                           query_border,
                                           assign_border,
                                           _gtk_css_border_value_new (_gtk_css_number_value_new (100, 
GTK_CSS_PERCENT),
@@ -2034,7 +2059,7 @@ _gtk_css_style_property_init_properties (void)
                                           0,
                                           GTK_CSS_AFFECTS_BORDER,
                                           border_image_width_parse,
-                                          gtk_css_style_property_token_parse_default,
+                                          border_image_width_token_parse,
                                           query_border,
                                           assign_border,
                                           _gtk_css_border_value_new (_gtk_css_number_value_new (1, 
GTK_CSS_NUMBER),


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