From 4ba9be5b976df6f51b7ae0f81af5b29246b7ac80 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 30 Mar 2012 02:19:39 +0200 Subject: [PATCH] cssvalue: Add GtkCssArea to the enum values ... and get rid of its GType. This makes it non-queryable using gtk_style_context_get() but it used to be a private struct anyway. --- gtk/gtkcssenumvalue.c | 52 +++++++++++++++++++++++++++++++ gtk/gtkcssenumvalueprivate.h | 4 +++ gtk/gtkcssshorthandpropertyimpl.c | 9 ++++-- gtk/gtkcssstylepropertyimpl.c | 29 ++++++++--------- gtk/gtkcsstypesprivate.h | 2 +- gtk/gtkthemingbackground.c | 11 ++----- 6 files changed, 79 insertions(+), 28 deletions(-) diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c index 7e79fc7407..ee786b67cb 100644 --- a/gtk/gtkcssenumvalue.c +++ b/gtk/gtkcssenumvalue.c @@ -256,3 +256,55 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value) return value->value; } +/* GtkCssArea */ + +static const GtkCssValueClass GTK_CSS_VALUE_AREA = { + gtk_css_value_enum_free, + gtk_css_value_enum_equal, + gtk_css_value_enum_print +}; + +static GtkCssValue area_values[] = { + { >K_CSS_VALUE_AREA, 1, GTK_CSS_AREA_BORDER_BOX, "border-box" }, + { >K_CSS_VALUE_AREA, 1, GTK_CSS_AREA_PADDING_BOX, "padding-box" }, + { >K_CSS_VALUE_AREA, 1, GTK_CSS_AREA_CONTENT_BOX, "content-box" } +}; + +GtkCssValue * +_gtk_css_area_value_new (GtkCssArea area) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (area_values); i++) + { + if (area_values[i].value == area) + return _gtk_css_value_ref (&area_values[i]); + } + + g_return_val_if_reached (NULL); +} + +GtkCssValue * +_gtk_css_area_value_try_parse (GtkCssParser *parser) +{ + guint i; + + g_return_val_if_fail (parser != NULL, NULL); + + for (i = 0; i < G_N_ELEMENTS (area_values); i++) + { + if (_gtk_css_parser_try (parser, area_values[i].name, TRUE)) + return _gtk_css_value_ref (&area_values[i]); + } + + return NULL; +} + +GtkCssArea +_gtk_css_area_value_get (const GtkCssValue *value) +{ + g_return_val_if_fail (value->class == >K_CSS_VALUE_AREA, GTK_CSS_AREA_BORDER_BOX); + + return value->value; +} + diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h index ec37ec7836..60921371e4 100644 --- a/gtk/gtkcssenumvalueprivate.h +++ b/gtk/gtkcssenumvalueprivate.h @@ -22,6 +22,7 @@ #include "gtkenums.h" #include "gtkcssparserprivate.h" +#include "gtkcsstypesprivate.h" #include "gtkcssvalueprivate.h" G_BEGIN_DECLS @@ -42,6 +43,9 @@ GtkCssValue * _gtk_css_font_weight_value_new (PangoWeight weight GtkCssValue * _gtk_css_font_weight_value_try_parse (GtkCssParser *parser); PangoWeight _gtk_css_font_weight_value_get (const GtkCssValue *value); +GtkCssValue * _gtk_css_area_value_new (GtkCssArea area); +GtkCssValue * _gtk_css_area_value_try_parse (GtkCssParser *parser); +GtkCssArea _gtk_css_area_value_get (const GtkCssValue *value); G_END_DECLS diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index fe6707083b..b7eb6d72c7 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -511,10 +511,13 @@ parse_background (GtkCssShorthandProperty *shorthand, values[1] = _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT, enum_value); } else if ((values[2] == NULL || values[3] == NULL) && - _gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_AREA, &enum_value)) + (values[3] = _gtk_css_area_value_try_parse (parser))) { - guint idx = values[2] == NULL ? 2 : 3; - values[idx] = _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, enum_value); + if (values[2] == NULL) + { + values[2] = values[3]; + values[3] = NULL; + } } else if (values[4] == NULL) { diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c index a2e35b1175..a05bdc4c82 100644 --- a/gtk/gtkcssstylepropertyimpl.c +++ b/gtk/gtkcssstylepropertyimpl.c @@ -417,15 +417,12 @@ parse_css_area (GtkCssStyleProperty *property, GtkCssParser *parser, GFile *base) { - int value; + GtkCssValue *value = _gtk_css_area_value_try_parse (parser); + + if (value == NULL) + _gtk_css_parser_error (parser, "unknown value for property"); - if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_AREA, &value)) - { - _gtk_css_parser_error (parser, "unknown value for property"); - return NULL; - } - - return _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, value); + return value; } static GtkCssValue * @@ -1543,25 +1540,25 @@ _gtk_css_style_property_init_properties (void) _gtk_css_value_new_from_int (0)); gtk_css_style_property_register ("background-clip", - GTK_TYPE_CSS_AREA, + G_TYPE_NONE, 0, parse_css_area, NULL, NULL, - query_simple, - assign_simple, NULL, - _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_BORDER_BOX)); + NULL, + NULL, + _gtk_css_area_value_new (GTK_CSS_AREA_BORDER_BOX)); gtk_css_style_property_register ("background-origin", - GTK_TYPE_CSS_AREA, + G_TYPE_NONE, 0, parse_css_area, NULL, NULL, - query_simple, - assign_simple, NULL, - _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_PADDING_BOX)); + NULL, + NULL, + _gtk_css_area_value_new (GTK_CSS_AREA_PADDING_BOX)); gtk_css_style_property_register ("background-size", G_TYPE_NONE, 0, diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h index 08e18eecf7..6371c54480 100644 --- a/gtk/gtkcsstypesprivate.h +++ b/gtk/gtkcsstypesprivate.h @@ -81,7 +81,7 @@ typedef enum { GTK_CSS_REPEAT_STYLE_SPACE } GtkCssBorderRepeatStyle; -typedef enum { +typedef enum /*< skip >*/ { GTK_CSS_AREA_BORDER_BOX, GTK_CSS_AREA_PADDING_BOX, GTK_CSS_AREA_CONTENT_BOX diff --git a/gtk/gtkthemingbackground.c b/gtk/gtkthemingbackground.c index 63050fa8c4..882e4969fe 100644 --- a/gtk/gtkthemingbackground.c +++ b/gtk/gtkthemingbackground.c @@ -23,6 +23,7 @@ #include "gtkthemingbackgroundprivate.h" +#include "gtkcssenumvalueprivate.h" #include "gtkcssimagevalueprivate.h" #include "gtkcsstypesprivate.h" #include "gtkthemingengineprivate.h" @@ -54,9 +55,7 @@ _gtk_theming_background_apply_origin (GtkThemingBackground *bg) GtkCssArea origin; cairo_rectangle_t image_rect; - gtk_style_context_get (bg->context, bg->flags, - "background-origin", &origin, - NULL); + origin = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, "background-clip")); /* The default size of the background image depends on the background-origin value as this affects the top left @@ -91,11 +90,7 @@ _gtk_theming_background_apply_origin (GtkThemingBackground *bg) static void _gtk_theming_background_apply_clip (GtkThemingBackground *bg) { - GtkCssArea clip; - - gtk_style_context_get (bg->context, bg->flags, - "background-clip", &clip, - NULL); + GtkCssArea clip = _gtk_css_area_value_get (_gtk_style_context_peek_property (bg->context, "background-clip")); if (clip == GTK_CSS_AREA_PADDING_BOX) {