css: Add a token parser for border values
This commit is contained in:
@@ -204,6 +204,76 @@ _gtk_css_border_value_parse (GtkCssParser *parser,
|
||||
return result;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1122,6 +1122,18 @@ border_image_slice_parse (GtkCssStyleProperty *property,
|
||||
TRUE);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -1135,6 +1147,19 @@ border_image_width_parse (GtkCssStyleProperty *property,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user