[gtk+] styleproperty: Parse all values for background-repeat
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] styleproperty: Parse all values for background-repeat
- Date: Mon, 9 Jan 2012 17:54:07 +0000 (UTC)
commit bc9373fb43a6668b36e59bb9a34a74e6979e74cb
Author: Benjamin Otte <otte redhat com>
Date: Thu Jan 5 02:48:32 2012 +0100
styleproperty: Parse all values for background-repeat
... and its component in the background property.
gtk/gtkcssshorthandpropertyimpl.c | 18 +++++++++
gtk/gtkcssstylepropertyimpl.c | 72 +++++++++++++++++++++++++++++++++++--
gtk/gtkcsstypesprivate.h | 19 +++++++++-
3 files changed, 104 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c
index cd1dfda..33d5335 100644
--- a/gtk/gtkcssshorthandpropertyimpl.c
+++ b/gtk/gtkcssshorthandpropertyimpl.c
@@ -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);
}
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 3038eb0..447e1df 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -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,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index a2492df..95123be 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -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 {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]