styleproperty: Parse all values for background-repeat

... and its component in the background property.
This commit is contained in:
Benjamin Otte 2012-01-05 02:48:32 +01:00
parent 77af93bad9
commit bc9373fb43
3 changed files with 104 additions and 5 deletions

View File

@ -307,6 +307,24 @@ parse_background (GtkCssShorthandProperty *shorthand,
else if (!G_IS_VALUE (&values[1]) &&
_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &enum_value))
{
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;
}
g_value_init (&values[1], GTK_TYPE_CSS_BACKGROUND_REPEAT);
g_value_set_enum (&values[1], enum_value);
}

View File

@ -432,6 +432,72 @@ css_image_value_compute (GtkCssStyleProperty *property,
g_value_take_object (computed, image);
}
static gboolean
background_repeat_value_parse (GtkCssStyleProperty *property,
GValue *value,
GtkCssParser *parser,
GFile *base)
{
int repeat, vertical;
if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &repeat))
{
_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;
}
g_value_set_enum (value, repeat);
return TRUE;
}
static void
background_repeat_value_print (GtkCssStyleProperty *property,
const GValue *value,
GString *string)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
GtkCssBackgroundRepeat repeat;
repeat = g_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
{
enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_HORIZONTAL (repeat));
g_string_append (string, enum_value->value_nick);
if (GTK_CSS_BACKGROUND_HORIZONTAL (repeat) != GTK_CSS_BACKGROUND_VERTICAL (repeat))
{
enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_VERTICAL (repeat));
g_string_append (string, " ");
g_string_append (string, enum_value->value_nick);
}
}
g_type_class_unref (enum_class);
}
/*** REGISTRATION ***/
#define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
@ -707,10 +773,10 @@ _gtk_css_style_property_init_properties (void)
gtk_style_property_register ("background-repeat",
GTK_TYPE_CSS_BACKGROUND_REPEAT,
0,
background_repeat_value_parse,
background_repeat_value_print,
NULL,
NULL,
NULL,
GTK_CSS_BACKGROUND_REPEAT);
GTK_CSS_BACKGROUND_REPEAT | (GTK_CSS_BACKGROUND_REPEAT << GTK_CSS_BACKGROUND_REPEAT_SHIFT));
g_value_init (&value, GTK_TYPE_CSS_IMAGE);
_gtk_style_property_register ("background-image",
CAIRO_GOBJECT_TYPE_PATTERN,

View File

@ -30,9 +30,24 @@ typedef enum {
GTK_CSS_CURRENT_COLOR /*< nick=currentColor >*/
} GtkCssSpecialValue;
typedef enum {
GTK_CSS_BACKGROUND_REPEAT,
/* We encode horizontal and vertical repeat in one enum value.
* This eases parsing and storage, but you need to be aware that
* you have to "unpack" this value.
*/
#define GTK_CSS_BACKGROUND_REPEAT_SHIFT (8)
#define GTK_CSS_BACKGROUND_REPEAT_MASK ((1 << GTK_CSS_BACKGROUND_REPEAT_SHIFT) - 1)
#define GTK_CSS_BACKGROUND_HORIZONTAL(repeat) ((repeat) & GTK_CSS_BACKGROUND_REPEAT_MASK)
#define GTK_CSS_BACKGROUND_VERTICAL(repeat) (((repeat) >> GTK_CSS_BACKGROUND_REPEAT_SHIFT) & GTK_CSS_BACKGROUND_REPEAT_MASK)
typedef enum /*< enum >*/
{
GTK_CSS_BACKGROUND_INVALID, /*< skip >*/
GTK_CSS_BACKGROUND_REPEAT, /* start at one so we know if a value has been set */
GTK_CSS_BACKGROUND_SPACE,
GTK_CSS_BACKGROUND_ROUND,
GTK_CSS_BACKGROUND_NO_REPEAT,
/* need to hardcode the numer or glib-mkenums makes us into a flags type */
GTK_CSS_BACKGROUND_REPEAT_X = 1025,
GTK_CSS_BACKGROUND_REPEAT_Y = 260
} GtkCssBackgroundRepeat;
typedef enum {