[gtk/wip/otte/css: 58/66] csspositionvalue: Redo the parser
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/css: 58/66] csspositionvalue: Redo the parser
- Date: Thu, 11 Apr 2019 22:45:30 +0000 (UTC)
commit 8d7f6ea43caaa75673718cb09e04ee57bd25d0c8
Author: Benjamin Otte <otte redhat com>
Date: Wed Apr 10 21:10:03 2019 +0200
csspositionvalue: Redo the parser
The old one incorrectly rejected "center left" and "center right".
gtk/gtkcsspositionvalue.c | 86 +++++++++++++++++++++++++----------------------
1 file changed, 46 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkcsspositionvalue.c b/gtk/gtkcsspositionvalue.c
index 473ae56ca9..b5cde9de9c 100644
--- a/gtk/gtkcsspositionvalue.c
+++ b/gtk/gtkcsspositionvalue.c
@@ -179,42 +179,34 @@ position_value_parse (GtkCssParser *parser, gboolean try)
const char *name;
guint percentage;
gboolean horizontal;
- gboolean vertical;
+ gboolean swap;
} names[] = {
{ "left", 0, TRUE, FALSE },
{ "right", 100, TRUE, FALSE },
{ "center", 50, TRUE, TRUE },
- { "top", 0, FALSE, TRUE },
- { "bottom", 100, FALSE, TRUE },
- { NULL , 0, TRUE, FALSE }, /* used for numbers */
- { NULL , 50, TRUE, TRUE } /* used for no value */
+ { "top", 0, FALSE, FALSE },
+ { "bottom", 100, FALSE, FALSE },
};
- GtkCssValue *x, *y;
- GtkCssValue **missing;
- guint first, second;
+ GtkCssValue *x = NULL, *y = NULL;
+ gboolean swap = FALSE;
+ guint i;
- for (first = 0; names[first].name != NULL; first++)
+ for (i = 0; i < G_N_ELEMENTS (names); i++)
{
- if (gtk_css_parser_try_ident (parser, names[first].name))
+ if (gtk_css_parser_try_ident (parser, names[i].name))
{
- if (names[first].horizontal)
- {
- x = _gtk_css_number_value_new (names[first].percentage, GTK_CSS_PERCENT);
- missing = &y;
- }
+ if (names[i].horizontal)
+ x = _gtk_css_number_value_new (names[i].percentage, GTK_CSS_PERCENT);
else
- {
- y = _gtk_css_number_value_new (names[first].percentage, GTK_CSS_PERCENT);
- missing = &x;
- }
+ y = _gtk_css_number_value_new (names[i].percentage, GTK_CSS_PERCENT);
+ swap = names[i].swap;
break;
}
}
- if (names[first].name == NULL)
+ if (i == G_N_ELEMENTS (names))
{
if (gtk_css_number_value_can_parse (parser))
{
- missing = &y;
x = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_PERCENT
| GTK_CSS_PARSE_LENGTH);
@@ -230,20 +222,44 @@ position_value_parse (GtkCssParser *parser, gboolean try)
}
}
- for (second = 0; names[second].name != NULL; second++)
+ for (i = 0; i < G_N_ELEMENTS (names); i++)
{
- if (gtk_css_parser_try_ident (parser, names[second].name))
+ if (!swap && !names[i].swap)
{
- *missing = _gtk_css_number_value_new (names[second].percentage, GTK_CSS_PERCENT);
+ if (names[i].horizontal && x != NULL)
+ continue;
+ if (!names[i].horizontal && y != NULL)
+ continue;
+ }
+
+ if (gtk_css_parser_try_ident (parser, names[i].name))
+ {
+ if (x)
+ {
+ if (names[i].horizontal && !names[i].swap)
+ {
+ y = x;
+ x = _gtk_css_number_value_new (names[i].percentage, GTK_CSS_PERCENT);
+ }
+ else
+ {
+ y = _gtk_css_number_value_new (names[i].percentage, GTK_CSS_PERCENT);
+ }
+ }
+ else
+ {
+ g_assert (names[i].horizontal || names[i].swap);
+ x = _gtk_css_number_value_new (names[i].percentage, GTK_CSS_PERCENT);
+ }
break;
}
}
- if (names[second].name == NULL)
+ if (i == G_N_ELEMENTS (names))
{
if (gtk_css_number_value_can_parse (parser))
{
- if (missing != &y)
+ if (y != NULL)
{
if (!try)
gtk_css_parser_error_syntax (parser, "Invalid combination of values");
@@ -261,20 +277,10 @@ position_value_parse (GtkCssParser *parser, gboolean try)
}
else
{
- second++;
- *missing = _gtk_css_number_value_new (50, GTK_CSS_PERCENT);
- }
- }
- else
- {
- if ((names[first].horizontal && !names[second].vertical) ||
- (!names[first].horizontal && !names[second].horizontal))
- {
- if (!try)
- gtk_css_parser_error_syntax (parser, "Invalid combination of values");
- _gtk_css_value_unref (x);
- _gtk_css_value_unref (y);
- return NULL;
+ if (y)
+ x = _gtk_css_number_value_new (50, GTK_CSS_PERCENT);
+ else
+ y = _gtk_css_number_value_new (50, GTK_CSS_PERCENT);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]