From: Benjamin Otte Date: Tue, 27 Mar 2012 05:15:23 +0000 (+0200) Subject: css: Move shadow parse/print/compute funcs X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=7fbc583b8877355d40094e1e321f7b2dc87bed45;p=~andy%2Fgtk css: Move shadow parse/print/compute funcs They don't belong in the style funcs, as those are for custom properties, and the shadow type is private. --- diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c index f3b58e57e..6a0bed713 100644 --- a/gtk/gtkcssstylefuncs.c +++ b/gtk/gtkcssstylefuncs.c @@ -889,121 +889,6 @@ pattern_value_compute (GtkStyleContext *context, return _gtk_css_value_ref (specified); } -static gboolean -shadow_value_parse (GtkCssParser *parser, - GFile *base, - GValue *value) -{ - gboolean have_inset, have_color, have_lengths; - gdouble hoffset, voffset, blur, spread; - GtkSymbolicColor *color; - GtkShadow *shadow; - guint i; - - if (_gtk_css_parser_try (parser, "none", TRUE)) - return TRUE; - - shadow = _gtk_shadow_new (); - - do - { - have_inset = have_lengths = have_color = FALSE; - - for (i = 0; i < 3; i++) - { - if (!have_inset && - _gtk_css_parser_try (parser, "inset", TRUE)) - { - have_inset = TRUE; - continue; - } - - if (!have_lengths && - _gtk_css_parser_try_double (parser, &hoffset)) - { - have_lengths = TRUE; - - if (!_gtk_css_parser_try_double (parser, &voffset)) - { - _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required"); - _gtk_shadow_unref (shadow); - return FALSE; - } - - if (!_gtk_css_parser_try_double (parser, &blur)) - blur = 0; - - if (!_gtk_css_parser_try_double (parser, &spread)) - spread = 0; - - continue; - } - - if (!have_color) - { - have_color = TRUE; - - /* XXX: the color is optional and UA-defined if it's missing, - * but it doesn't really make sense for us... - */ - color = _gtk_css_parser_read_symbolic_color (parser); - - if (color == NULL) - { - _gtk_shadow_unref (shadow); - return FALSE; - } - } - } - - if (!have_color || !have_lengths) - { - _gtk_css_parser_error (parser, "Must specify at least color and offsets"); - _gtk_shadow_unref (shadow); - return FALSE; - } - - _gtk_shadow_append (shadow, - hoffset, voffset, - blur, spread, - have_inset, color); - - gtk_symbolic_color_unref (color); - - } - while (_gtk_css_parser_try (parser, ",", TRUE)); - - g_value_take_boxed (value, shadow); - return TRUE; -} - -static void -shadow_value_print (const GValue *value, - GString *string) -{ - GtkShadow *shadow; - - shadow = g_value_get_boxed (value); - - if (shadow == NULL) - g_string_append (string, "none"); - else - _gtk_shadow_print (shadow, string); -} - -static GtkCssValue * -shadow_value_compute (GtkStyleContext *context, - GtkCssValue *specified) -{ - GtkShadow *shadow; - - shadow = _gtk_css_value_get_shadow (specified); - if (shadow) - shadow = _gtk_shadow_resolve (shadow, context); - - return _gtk_css_value_new_take_shadow (shadow); -} - static gboolean border_image_repeat_value_parse (GtkCssParser *parser, GFile *file, @@ -1228,10 +1113,6 @@ gtk_css_style_funcs_init (void) border_image_repeat_value_parse, border_image_repeat_value_print, NULL); - register_conversion_function (GTK_TYPE_SHADOW, - shadow_value_parse, - shadow_value_print, - shadow_value_compute); register_conversion_function (GTK_TYPE_CSS_NUMBER, NULL, css_number_print, diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c index 3b1bd4219..88cf9d980 100644 --- a/gtk/gtkcssstylepropertyimpl.c +++ b/gtk/gtkcssstylepropertyimpl.c @@ -396,6 +396,122 @@ bindings_value_print (GtkCssStyleProperty *property, } } +static GtkCssValue * +shadow_value_parse (GtkCssStyleProperty *property, + GtkCssParser *parser, + GFile *base) +{ + gboolean have_inset, have_color, have_lengths; + gdouble hoffset, voffset, blur, spread; + GtkSymbolicColor *color; + GtkShadow *shadow; + guint i; + + if (_gtk_css_parser_try (parser, "none", TRUE)) + return _gtk_css_value_new_take_shadow (NULL); + + shadow = _gtk_shadow_new (); + + do + { + have_inset = have_lengths = have_color = FALSE; + + for (i = 0; i < 3; i++) + { + if (!have_inset && + _gtk_css_parser_try (parser, "inset", TRUE)) + { + have_inset = TRUE; + continue; + } + + if (!have_lengths && + _gtk_css_parser_try_double (parser, &hoffset)) + { + have_lengths = TRUE; + + if (!_gtk_css_parser_try_double (parser, &voffset)) + { + _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required"); + _gtk_shadow_unref (shadow); + return NULL; + } + + if (!_gtk_css_parser_try_double (parser, &blur)) + blur = 0; + + if (!_gtk_css_parser_try_double (parser, &spread)) + spread = 0; + + continue; + } + + if (!have_color) + { + have_color = TRUE; + + /* XXX: the color is optional and UA-defined if it's missing, + * but it doesn't really make sense for us... + */ + color = _gtk_css_parser_read_symbolic_color (parser); + + if (color == NULL) + { + _gtk_shadow_unref (shadow); + return NULL; + } + } + } + + if (!have_color || !have_lengths) + { + _gtk_css_parser_error (parser, "Must specify at least color and offsets"); + _gtk_shadow_unref (shadow); + return NULL; + } + + _gtk_shadow_append (shadow, + hoffset, voffset, + blur, spread, + have_inset, color); + + gtk_symbolic_color_unref (color); + + } + while (_gtk_css_parser_try (parser, ",", TRUE)); + + return _gtk_css_value_new_take_shadow (shadow); +} + +static void +shadow_value_print (GtkCssStyleProperty *property, + const GtkCssValue *value, + GString *string) +{ + GtkShadow *shadow; + + shadow = _gtk_css_value_get_shadow (value); + + if (shadow == NULL) + g_string_append (string, "none"); + else + _gtk_shadow_print (shadow, string); +} + +static GtkCssValue * +shadow_value_compute (GtkCssStyleProperty *property, + GtkStyleContext *context, + GtkCssValue *specified) +{ + GtkShadow *shadow; + + shadow = _gtk_css_value_get_shadow (specified); + if (shadow) + shadow = _gtk_shadow_resolve (shadow, context); + + return _gtk_css_value_new_take_shadow (shadow); +} + static GtkCssValue * border_corner_radius_value_parse (GtkCssStyleProperty *property, GtkCssParser *parser, @@ -1048,9 +1164,9 @@ _gtk_css_style_property_init_properties (void) GTK_TYPE_SHADOW, GTK_TYPE_SHADOW, GTK_STYLE_PROPERTY_INHERIT, - NULL, - NULL, - NULL, + shadow_value_parse, + shadow_value_print, + shadow_value_compute, NULL, _gtk_css_value_new_take_shadow (NULL)); @@ -1059,9 +1175,9 @@ _gtk_css_style_property_init_properties (void) GTK_TYPE_SHADOW, GTK_TYPE_SHADOW, GTK_STYLE_PROPERTY_INHERIT, - NULL, - NULL, - NULL, + shadow_value_parse, + shadow_value_print, + shadow_value_compute, NULL, _gtk_css_value_new_take_shadow (NULL)); @@ -1070,9 +1186,9 @@ _gtk_css_style_property_init_properties (void) GTK_TYPE_SHADOW, GTK_TYPE_SHADOW, 0, - NULL, - NULL, - NULL, + shadow_value_parse, + shadow_value_print, + shadow_value_compute, NULL, _gtk_css_value_new_take_shadow (NULL));