Commit f785f717 authored by Benjamin Otte's avatar Benjamin Otte

cssvalue: Add a custom value for repeats

In particular, that's background-repeat and border-image-repeat.

Also, fix up the border-image shorthand to allow any order.
parent 5377169e
......@@ -445,6 +445,7 @@ gtk_private_h_sources = \
gtkcssparserprivate.h \
gtkcsspositionvalueprivate.h \
gtkcssproviderprivate.h \
gtkcssrepeatvalueprivate.h \
gtkcssrgbavalueprivate.h \
gtkcsssectionprivate.h \
gtkcssselectorprivate.h \
......@@ -656,6 +657,7 @@ gtk_base_c_sources = \
gtkcssparser.c \
gtkcsspositionvalue.c \
gtkcssprovider.c \
gtkcssrepeatvalue.c \
gtkcssrgbavalue.c \
gtkcsssection.c \
gtkcssselector.c \
......
......@@ -26,6 +26,7 @@
#include "gtkborderimageprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssrepeatvalueprivate.h"
#include "gtkstylepropertiesprivate.h"
#include "gtkthemingengineprivate.h"
......@@ -54,7 +55,7 @@ _gtk_border_image_init (GtkBorderImage *image,
else
image->has_width = FALSE;
image->repeat = *_gtk_css_value_get_border_image_repeat (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_REPEAT));
image->repeat = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_BORDER_IMAGE_REPEAT);
return TRUE;
}
......@@ -91,8 +92,8 @@ gtk_border_image_render_slice (cairo_t *cr,
double y,
double width,
double height,
GtkCssBorderRepeatStyle hrepeat,
GtkCssBorderRepeatStyle vrepeat)
GtkCssRepeatStyle hrepeat,
GtkCssRepeatStyle vrepeat)
{
double hscale, vscale;
double xstep, ystep;
......@@ -299,8 +300,8 @@ _gtk_border_image_render (GtkBorderImage *image,
vertical_border[v].offset,
horizontal_border[h].size,
vertical_border[v].size,
h == 1 ? image->repeat.hrepeat : GTK_CSS_REPEAT_STYLE_STRETCH,
v == 1 ? image->repeat.vrepeat : GTK_CSS_REPEAT_STYLE_STRETCH);
h == 1 ? _gtk_css_border_repeat_value_get_x (image->repeat) : GTK_CSS_REPEAT_STYLE_STRETCH,
v == 1 ? _gtk_css_border_repeat_value_get_y (image->repeat) : GTK_CSS_REPEAT_STYLE_STRETCH);
cairo_surface_destroy (slice);
}
......
......@@ -24,8 +24,8 @@
#include "gtkborder.h"
#include "gtkcssimageprivate.h"
#include "gtkcssvalueprivate.h"
#include "gtkthemingengine.h"
#include "gtkcsstypesprivate.h"
G_BEGIN_DECLS
......@@ -37,7 +37,7 @@ struct _GtkBorderImage {
GtkBorder slice;
gboolean has_width;
GtkBorder width;
GtkCssBorderImageRepeat repeat;
GtkCssValue *repeat;
};
gboolean _gtk_border_image_init (GtkBorderImage *image,
......
......@@ -120,12 +120,6 @@ gtk_css_value_position_print (const GtkCssValue *position,
g_string_append (string, "center ");
_gtk_css_value_print (position->y, string);
}
_gtk_css_value_print (position->x, string);
if (!_gtk_css_value_equal (position->x, position->y))
{
g_string_append_c (string, ' ');
_gtk_css_value_print (position->y, string);
}
done:
for (i = 0; i < G_N_ELEMENTS (values); i++)
......
/* GTK - The GIMP Toolkit
* Copyright (C) 2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gtkcssrepeatvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
struct _GtkCssValue {
GTK_CSS_VALUE_BASE
GtkCssRepeatStyle x;
GtkCssRepeatStyle y;
};
static void
gtk_css_value_repeat_free (GtkCssValue *value)
{
g_slice_free (GtkCssValue, value);
}
static gboolean
gtk_css_value_repeat_equal (const GtkCssValue *repeat1,
const GtkCssValue *repeat2)
{
return repeat1->x == repeat2->x
&& repeat1->y == repeat2->y;
}
static GtkCssValue *
gtk_css_value_repeat_transition (GtkCssValue *start,
GtkCssValue *end,
double progress)
{
return NULL;
}
static void
gtk_css_value_background_repeat_print (const GtkCssValue *repeat,
GString *string)
{
static const char *names[] = {
"no-repeat",
"repeat",
"round",
"space"
};
if (repeat->x == repeat->y)
{
g_string_append (string, names[repeat->x]);
}
else if (repeat->x == GTK_CSS_REPEAT_STYLE_REPEAT &&
repeat->y == GTK_CSS_REPEAT_STYLE_NO_REPEAT)
{
g_string_append (string, "repeat-x");
}
else if (repeat->x == GTK_CSS_REPEAT_STYLE_NO_REPEAT &&
repeat->y == GTK_CSS_REPEAT_STYLE_REPEAT)
{
g_string_append (string, "repeat-y");
}
else
{
g_string_append (string, names[repeat->x]);
g_string_append_c (string, ' ');
g_string_append (string, names[repeat->y]);
}
}
static void
gtk_css_value_border_repeat_print (const GtkCssValue *repeat,
GString *string)
{
static const char *names[] = {
"stretch",
"repeat",
"round",
"space"
};
g_string_append (string, names[repeat->x]);
if (repeat->x != repeat->y)
{
g_string_append_c (string, ' ');
g_string_append (string, names[repeat->y]);
}
}
static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_background_repeat_print
};
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_border_repeat_print
};
/* BACKGROUND REPEAT */
static struct {
const char *name;
GtkCssValue values[4];
} background_repeat_values[4] = {
{ "no-repeat",
{ { &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_NO_REPEAT, GTK_CSS_REPEAT_STYLE_NO_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_NO_REPEAT, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_NO_REPEAT, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_NO_REPEAT, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "repeat",
{ { &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_NO_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "round",
{ { &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_NO_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "space",
{ { &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_NO_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BACKGROUND_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_SPACE }
} }
};
GtkCssValue *
_gtk_css_background_repeat_value_new (GtkCssRepeatStyle x,
GtkCssRepeatStyle y)
{
return _gtk_css_value_ref (&background_repeat_values[x].values[y]);
}
static gboolean
_gtk_css_background_repeat_style_try (GtkCssParser *parser,
GtkCssRepeatStyle *result)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (background_repeat_values); i++)
{
if (_gtk_css_parser_try (parser, background_repeat_values[i].name, TRUE))
{
*result = i;
return TRUE;
}
}
return FALSE;
}
GtkCssValue *
_gtk_css_background_repeat_value_try_parse (GtkCssParser *parser)
{
GtkCssRepeatStyle x, y;
g_return_val_if_fail (parser != NULL, NULL);
if (_gtk_css_parser_try (parser, "repeat-x", TRUE))
return _gtk_css_background_repeat_value_new (GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_NO_REPEAT);
if (_gtk_css_parser_try (parser, "repeat-y", TRUE))
return _gtk_css_background_repeat_value_new (GTK_CSS_REPEAT_STYLE_NO_REPEAT, GTK_CSS_REPEAT_STYLE_REPEAT);
if (!_gtk_css_background_repeat_style_try (parser, &x))
return NULL;
if (!_gtk_css_background_repeat_style_try (parser, &y))
y = x;
return _gtk_css_background_repeat_value_new (x, y);
}
GtkCssRepeatStyle
_gtk_css_background_repeat_value_get_x (const GtkCssValue *repeat)
{
g_return_val_if_fail (repeat->class == &GTK_CSS_VALUE_BACKGROUND_REPEAT, GTK_CSS_REPEAT_STYLE_NO_REPEAT);
return repeat->x;
}
GtkCssRepeatStyle
_gtk_css_background_repeat_value_get_y (const GtkCssValue *repeat)
{
g_return_val_if_fail (repeat->class == &GTK_CSS_VALUE_BACKGROUND_REPEAT, GTK_CSS_REPEAT_STYLE_NO_REPEAT);
return repeat->y;
}
/* BORDER IMAGE REPEAT */
static struct {
const char *name;
GtkCssValue values[4];
} border_repeat_values[4] = {
{ "stretch",
{ { &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_STRETCH },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "repeat",
{ { &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_STRETCH },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_REPEAT, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "round",
{ { &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_STRETCH },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_ROUND, GTK_CSS_REPEAT_STYLE_SPACE }
} },
{ "space",
{ { &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_STRETCH },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_REPEAT },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_ROUND },
{ &GTK_CSS_VALUE_BORDER_REPEAT, 1, GTK_CSS_REPEAT_STYLE_SPACE, GTK_CSS_REPEAT_STYLE_SPACE }
} }
};
GtkCssValue *
_gtk_css_border_repeat_value_new (GtkCssRepeatStyle x,
GtkCssRepeatStyle y)
{
return _gtk_css_value_ref (&border_repeat_values[x].values[y]);
}
static gboolean
_gtk_css_border_repeat_style_try (GtkCssParser *parser,
GtkCssRepeatStyle *result)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (border_repeat_values); i++)
{
if (_gtk_css_parser_try (parser, border_repeat_values[i].name, TRUE))
{
*result = i;
return TRUE;
}
}
return FALSE;
}
GtkCssValue *
_gtk_css_border_repeat_value_try_parse (GtkCssParser *parser)
{
GtkCssRepeatStyle x, y;
g_return_val_if_fail (parser != NULL, NULL);
if (!_gtk_css_border_repeat_style_try (parser, &x))
return NULL;
if (!_gtk_css_border_repeat_style_try (parser, &y))
y = x;
return _gtk_css_border_repeat_value_new (x, y);
}
GtkCssRepeatStyle
_gtk_css_border_repeat_value_get_x (const GtkCssValue *repeat)
{
g_return_val_if_fail (repeat->class == &GTK_CSS_VALUE_BORDER_REPEAT, GTK_CSS_REPEAT_STYLE_STRETCH);
return repeat->x;
}
GtkCssRepeatStyle
_gtk_css_border_repeat_value_get_y (const GtkCssValue *repeat)
{
g_return_val_if_fail (repeat->class == &GTK_CSS_VALUE_BORDER_REPEAT, GTK_CSS_REPEAT_STYLE_STRETCH);
return repeat->y;
}
/*
* Copyright © 2012 Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Alexander Larsson <alexl@gnome.org>
*/
#ifndef __GTK_CSS_REPEAT_VALUE_PRIVATE_H__
#define __GTK_CSS_REPEAT_VALUE_PRIVATE_H__
#include "gtkcssparserprivate.h"
#include "gtkcssvalueprivate.h"
G_BEGIN_DECLS
typedef enum {
GTK_CSS_REPEAT_STYLE_NO_REPEAT,
GTK_CSS_REPEAT_STYLE_STRETCH = GTK_CSS_REPEAT_STYLE_NO_REPEAT,
GTK_CSS_REPEAT_STYLE_REPEAT,
GTK_CSS_REPEAT_STYLE_ROUND,
GTK_CSS_REPEAT_STYLE_SPACE
} GtkCssRepeatStyle;
GtkCssValue * _gtk_css_background_repeat_value_new (GtkCssRepeatStyle x,
GtkCssRepeatStyle y);
GtkCssValue * _gtk_css_background_repeat_value_try_parse (GtkCssParser *parser);
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);
GtkCssRepeatStyle _gtk_css_border_repeat_value_get_x (const GtkCssValue *repeat);
GtkCssRepeatStyle _gtk_css_border_repeat_value_get_y (const GtkCssValue *repeat);
G_END_DECLS
#endif /* __GTK_CSS_REPEAT_VALUE_PRIVATE_H__ */
......@@ -30,6 +30,7 @@
#include "gtkcssimageprivate.h"
#include "gtkcssimagevalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcssrepeatvalueprivate.h"
#include "gtkcssstringvalueprivate.h"
#include "gtkcssstylefuncsprivate.h"
#include "gtkcsstypesprivate.h"
......@@ -277,45 +278,58 @@ parse_border_image (GtkCssShorthandProperty *shorthand,
GtkCssParser *parser,
GFile *base)
{
GValue value = G_VALUE_INIT;
GtkCssImage *image;
if (_gtk_css_parser_try (parser, "none", TRUE))
image = NULL;
else
do
{
image = _gtk_css_image_new_parse (parser, base);
if (!image)
return FALSE;
}
values[0] = _gtk_css_image_value_new (image);
if (value_is_done_parsing (parser))
return TRUE;
if (values[0] == NULL &&
(_gtk_css_parser_has_prefix (parser, "none") ||
_gtk_css_image_can_parse (parser)))
{
GtkCssImage *image;
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
return FALSE;
values[1] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
if (_gtk_css_parser_try (parser, "none", TRUE))
image = NULL;
else
{
image = _gtk_css_image_new_parse (parser, base);
if (image == NULL)
return FALSE;
}
if (_gtk_css_parser_try (parser, "/", TRUE))
{
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
return FALSE;
values[2] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
}
values[0] = _gtk_css_image_value_new (image);
}
else if (values[3] == NULL &&
(values[3] = _gtk_css_border_repeat_value_try_parse (parser)))
{
/* please move along */
}
else if (values[1] == NULL)
{
GValue value = G_VALUE_INIT;
if (value_is_done_parsing (parser))
return TRUE;
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
return FALSE;
values[1] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
g_value_init (&value, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
if (!_gtk_css_style_parse_value (&value, parser, base))
return FALSE;
values[3] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
if (_gtk_css_parser_try (parser, "/", TRUE))
{
g_value_init (&value, GTK_TYPE_BORDER);
if (!_gtk_css_style_parse_value (&value, parser, base))
return FALSE;
values[2] = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
}
}
else
{
/* We parsed everything and there's still stuff left?
* Pretend we didn't notice and let the normal code produce
* a 'junk at end of value' error */
break;
}
}
while (!value_is_done_parsing (parser));
return TRUE;
}
......@@ -353,13 +367,6 @@ parse_border_side (GtkCssShorthandProperty *shorthand,
values[2] = _gtk_css_value_new_take_symbolic_color (symbolic);
}
else
{
/* We parsed everything and there's still stuff left?
* Pretend we didn't notice and let the normal code produce
* a 'junk at end of value' error */
break;
}
}
while (!value_is_done_parsing (parser));
......@@ -474,8 +481,6 @@ parse_background (GtkCssShorthandProperty *shorthand,
GtkCssParser *parser,
GFile *base)
{
int enum_value;
do
{
/* the image part */
......@@ -497,27 +502,9 @@ parse_background (GtkCssShorthandProperty *shorthand,
values[0] = _gtk_css_image_value_new (image);
}
else if (values[1] == NULL &&
_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
(values[1] = _gtk_css_background_repeat_value_try_parse (parser)))
{
if (enum_value <= GTK_CSS_BACKGROUND_REPEAT_MASK)
{
int vertical;
if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
{
if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
{
_gtk_css_parser_error (parser, "Not a valid 2nd value for border-repeat");
return FALSE;
}
else
enum_value |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
}
else
enum_value |= enum_value << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
}
values[1] = _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT, enum_value);
/* nothing to do here */
}
else if ((values[2] == NULL || values[3] == NULL) &&
(values[3] = _gtk_css_area_value_try_parse (parser)))
......
......@@ -887,52 +887,6 @@ pattern_value_compute (GtkStyleContext *context,
return _gtk_css_value_ref (specified);
}
static gboolean
border_image_repeat_value_parse (GtkCssParser *parser,
GFile *file,
GValue *value)
{
GtkCssBorderImageRepeat image_repeat;
GtkCssBorderRepeatStyle styles[2];
gint i, v;
for (i = 0; i < 2; i++)
{
if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
styles[i] = v;
else if (i == 0)
{
styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
break;
}
else
styles[i] = styles[0];
}
image_repeat.hrepeat = styles[0];
image_repeat.vrepeat = styles[1];
g_value_set_boxed (value, &image_repeat);
return TRUE;
}
static void
border_image_repeat_value_print (const GValue *value,
GString *string)
{
GtkCssBorderImageRepeat *image_repeat;
image_repeat = g_value_get_boxed (value);
enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
if (image_repeat->hrepeat != image_repeat->vrepeat)
{
g_string_append (string, " ");
enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
}
}
static gboolean
enum_value_parse (GtkCssParser *parser,
GFile *base,
......@@ -1100,10 +1054,6 @@ gtk_css_style_funcs_init (void)
pattern_value_parse,
pattern_value_print,
pattern_value_compute);
register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
border_image_repeat_value_parse,
border_image_repeat_value_print,
NULL);
register_conversion_function (G_TYPE_ENUM,
enum_value_parse,
enum_value_print,
......
......@@ -50,6 +50,7 @@
#include "gtkcssenumvalueprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkcsspositionvalueprivate.h"
#include "gtkcssrepeatvalueprivate.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkcssshadowsvalueprivate.h"
#include "gtkcssstringvalueprivate.h"
......@@ -665,20 +666,15 @@ border_image_repeat_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
GValue value = G_VALUE_INIT;
GtkCssValue *result;
GtkCssValue *value = _gtk_css_border_repeat_value_try_parse (parser);
g_value_init (&value, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
if (!_gtk_css_style_parse_value (&value, parser, base))
if (value == NULL)
{
g_value_unset (&value);
_gtk_css_parser_error (parser, "Not a valid value");
return NULL;
}
result = _gtk_css_value_new_from_gvalue (&value);
g_value_unset (&value);
return result;
return value;
}
static GtkCssValue *
......@@ -886,63 +882,15 @@ background_repeat_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
int repeat, vertical;
GtkCssValue *value = _gtk_css_background_repeat_value_try_parse (parser);
if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &repeat))
if (value == NULL)
{
_gtk_css_parser_error (parser, "Not a valid value");
return FALSE;
}
if (repeat <= GTK_CSS_BACKGROUND_REPEAT_MASK)
{
if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
{
if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
{
_gtk_css_parser_error (parser, "Not a valid 2nd value");
return FALSE;
}
else
repeat |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
}
else
repeat |= repeat << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
}
return _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT, repeat);
}
static void
background_repeat_value_print (GtkCssStyleProperty *property,
const GtkCssValue *value,
GString *string)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
GtkCssBackgroundRepeat repeat;
repeat = _gtk_css_value_get_enum (value);
enum_class = g_type_class_ref (GTK_TYPE_CSS_BACKGROUND_REPEAT);
enum_value = g_enum_get_value (enum_class, repeat);
/* only triggers for 'repeat-x' and 'repeat-y' */
if (enum_value)
g_string_append (string, enum_value->value_nick);
else