1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gtkcssstylefuncsprivate.h"
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 #include <cairo-gobject.h>
30 #include "gtkanimationdescription.h"
31 #include "gtkcssimagegradientprivate.h"
32 #include "gtkcssprovider.h"
33 #include "gtkcssrgbavalueprivate.h"
34 #include "gtkcsstypesprivate.h"
35 #include "gtkgradient.h"
36 #include "gtkprivatetypebuiltins.h"
37 #include "gtkcssshadowvalueprivate.h"
38 #include "gtkstylecontextprivate.h"
39 #include "gtksymboliccolorprivate.h"
40 #include "gtkthemingengine.h"
41 #include "gtktypebuiltins.h"
42 #include "gtkwin32themeprivate.h"
44 /* this is in case round() is not provided by the compiler,
45 * such as in the case of C89 compilers, like MSVC
47 #include "fallback-c89.c"
49 static GHashTable *parse_funcs = NULL;
50 static GHashTable *print_funcs = NULL;
51 static GHashTable *compute_funcs = NULL;
53 typedef gboolean (* GtkStyleParseFunc) (GtkCssParser *parser,
56 typedef void (* GtkStylePrintFunc) (const GValue *value,
58 typedef GtkCssValue * (* GtkStyleComputeFunc) (GtkStyleContext *context,
59 GtkCssValue *specified);
62 register_conversion_function (GType type,
63 GtkStyleParseFunc parse,
64 GtkStylePrintFunc print,
65 GtkStyleComputeFunc compute)
68 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
70 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
72 g_hash_table_insert (compute_funcs, GSIZE_TO_POINTER (type), compute);
76 string_append_double (GString *string,
79 char buf[G_ASCII_DTOSTR_BUF_SIZE];
81 g_ascii_dtostr (buf, sizeof (buf), d);
82 g_string_append (string, buf);
86 string_append_string (GString *str,
91 g_string_append_c (str, '"');
94 len = strcspn (string, "\"\n\r\f");
95 g_string_append (str, string);
102 g_string_append (str, "\\A ");
105 g_string_append (str, "\\D ");
108 g_string_append (str, "\\C ");
111 g_string_append (str, "\\\"");
114 g_assert_not_reached ();
119 g_string_append_c (str, '"');
122 /*** IMPLEMENTATIONS ***/
125 enum_parse (GtkCssParser *parser,
131 if (_gtk_css_parser_try_enum (parser, type, res))
134 str = _gtk_css_parser_try_ident (parser, TRUE);
137 _gtk_css_parser_error (parser, "Expected an identifier");
141 _gtk_css_parser_error (parser,
142 "Unknown value '%s' for enum type '%s'",
143 str, g_type_name (type));
150 enum_print (int value,
154 GEnumClass *enum_class;
155 GEnumValue *enum_value;
157 enum_class = g_type_class_ref (type);
158 enum_value = g_enum_get_value (enum_class, value);
160 g_string_append (string, enum_value->value_nick);
162 g_type_class_unref (enum_class);
166 rgba_value_parse (GtkCssParser *parser,
170 GtkSymbolicColor *symbolic;
173 if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
175 symbolic = gtk_symbolic_color_ref (_gtk_symbolic_color_get_current_color ());
179 symbolic = _gtk_css_parser_read_symbolic_color (parser);
180 if (symbolic == NULL)
184 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
186 g_value_set_boxed (value, &rgba);
187 gtk_symbolic_color_unref (symbolic);
191 g_value_unset (value);
192 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
193 g_value_take_boxed (value, symbolic);
200 rgba_value_print (const GValue *value,
203 const GdkRGBA *rgba = g_value_get_boxed (value);
206 g_string_append (string, "none");
209 char *s = gdk_rgba_to_string (rgba);
210 g_string_append (string, s);
216 rgba_value_compute (GtkStyleContext *context,
217 GtkCssValue *specified)
219 GdkRGBA white = { 1, 1, 1, 1 };
221 if (_gtk_css_value_holds (specified, GTK_TYPE_SYMBOLIC_COLOR))
223 GtkSymbolicColor *symbolic = _gtk_css_value_get_symbolic_color (specified);
226 if (symbolic == _gtk_symbolic_color_get_current_color ())
227 rgba = *_gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, "color"));
228 else if (!gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
231 return _gtk_css_value_new_from_boxed (GDK_TYPE_RGBA, &rgba);
234 return _gtk_css_value_ref (specified);
238 color_value_parse (GtkCssParser *parser,
242 GtkSymbolicColor *symbolic;
245 symbolic = _gtk_css_parser_read_symbolic_color (parser);
246 if (symbolic == NULL)
249 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
253 color.red = rgba.red * 65535. + 0.5;
254 color.green = rgba.green * 65535. + 0.5;
255 color.blue = rgba.blue * 65535. + 0.5;
257 g_value_set_boxed (value, &color);
261 g_value_unset (value);
262 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
263 g_value_take_boxed (value, symbolic);
270 color_value_print (const GValue *value,
273 const GdkColor *color = g_value_get_boxed (value);
276 g_string_append (string, "none");
279 char *s = gdk_color_to_string (color);
280 g_string_append (string, s);
286 color_value_compute (GtkStyleContext *context,
287 GtkCssValue *specified)
290 GdkColor color = { 0, 65535, 65535, 65535 };
292 if (_gtk_css_value_holds (specified, GTK_TYPE_SYMBOLIC_COLOR))
294 if (_gtk_style_context_resolve_color (context,
295 _gtk_css_value_get_symbolic_color (specified),
298 color.red = rgba.red * 65535. + 0.5;
299 color.green = rgba.green * 65535. + 0.5;
300 color.blue = rgba.blue * 65535. + 0.5;
303 return _gtk_css_value_new_from_color (&color);
306 return _gtk_css_value_ref (specified);
310 symbolic_color_value_parse (GtkCssParser *parser,
314 GtkSymbolicColor *symbolic;
316 if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
318 symbolic = gtk_symbolic_color_ref (_gtk_symbolic_color_get_current_color ());
322 symbolic = _gtk_css_parser_read_symbolic_color (parser);
323 if (symbolic == NULL)
327 g_value_take_boxed (value, symbolic);
332 symbolic_color_value_print (const GValue *value,
335 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
337 if (symbolic == NULL)
338 g_string_append (string, "none");
341 char *s = gtk_symbolic_color_to_string (symbolic);
342 g_string_append (string, s);
348 font_description_value_parse (GtkCssParser *parser,
352 PangoFontDescription *font_desc;
356 str = _gtk_css_parser_read_value (parser);
360 font_desc = pango_font_description_from_string (str);
361 mask = pango_font_description_get_set_fields (font_desc);
362 /* These values are not really correct,
363 * but the fields must be set, so we set them to something */
364 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
365 pango_font_description_set_family_static (font_desc, "Sans");
366 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
367 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
369 g_value_take_boxed (value, font_desc);
374 font_description_value_print (const GValue *value,
377 const PangoFontDescription *desc = g_value_get_boxed (value);
380 g_string_append (string, "none");
383 char *s = pango_font_description_to_string (desc);
384 g_string_append (string, s);
390 boolean_value_parse (GtkCssParser *parser,
394 if (_gtk_css_parser_try (parser, "true", TRUE) ||
395 _gtk_css_parser_try (parser, "1", TRUE))
397 g_value_set_boolean (value, TRUE);
400 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
401 _gtk_css_parser_try (parser, "0", TRUE))
403 g_value_set_boolean (value, FALSE);
408 _gtk_css_parser_error (parser, "Expected a boolean value");
414 boolean_value_print (const GValue *value,
417 if (g_value_get_boolean (value))
418 g_string_append (string, "true");
420 g_string_append (string, "false");
424 int_value_parse (GtkCssParser *parser,
430 if (_gtk_css_parser_begins_with (parser, '-'))
432 int res = _gtk_win32_theme_int_parse (parser, base, &i);
435 g_value_set_int (value, i);
438 /* < 0 => continue */
441 if (!_gtk_css_parser_try_int (parser, &i))
443 _gtk_css_parser_error (parser, "Expected a valid integer value");
447 g_value_set_int (value, i);
452 int_value_print (const GValue *value,
455 g_string_append_printf (string, "%d", g_value_get_int (value));
459 uint_value_parse (GtkCssParser *parser,
465 if (!_gtk_css_parser_try_uint (parser, &u))
467 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
471 g_value_set_uint (value, u);
476 uint_value_print (const GValue *value,
479 g_string_append_printf (string, "%u", g_value_get_uint (value));
483 double_value_parse (GtkCssParser *parser,
489 if (!_gtk_css_parser_try_double (parser, &d))
491 _gtk_css_parser_error (parser, "Expected a number");
495 g_value_set_double (value, d);
500 double_value_print (const GValue *value,
503 string_append_double (string, g_value_get_double (value));
507 float_value_parse (GtkCssParser *parser,
513 if (!_gtk_css_parser_try_double (parser, &d))
515 _gtk_css_parser_error (parser, "Expected a number");
519 g_value_set_float (value, d);
524 float_value_print (const GValue *value,
527 string_append_double (string, g_value_get_float (value));
531 string_value_parse (GtkCssParser *parser,
535 char *str = _gtk_css_parser_read_string (parser);
540 g_value_take_string (value, str);
545 string_value_print (const GValue *value,
548 string_append_string (str, g_value_get_string (value));
552 theming_engine_value_parse (GtkCssParser *parser,
556 GtkThemingEngine *engine;
559 if (_gtk_css_parser_try (parser, "none", TRUE))
561 g_value_set_object (value, gtk_theming_engine_load (NULL));
565 str = _gtk_css_parser_try_ident (parser, TRUE);
568 _gtk_css_parser_error (parser, "Expected a valid theme name");
572 engine = gtk_theming_engine_load (str);
576 _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
581 g_value_set_object (value, engine);
587 theming_engine_value_print (const GValue *value,
590 GtkThemingEngine *engine;
593 engine = g_value_get_object (value);
595 g_string_append (string, "none");
598 /* XXX: gtk_theming_engine_get_name()? */
599 g_object_get (engine, "name", &name, NULL);
600 g_string_append (string, name ? name : "none");
606 animation_description_value_parse (GtkCssParser *parser,
610 GtkAnimationDescription *desc;
613 str = _gtk_css_parser_read_value (parser);
617 desc = _gtk_animation_description_from_string (str);
622 _gtk_css_parser_error (parser, "Invalid animation description");
626 g_value_take_boxed (value, desc);
631 animation_description_value_print (const GValue *value,
634 GtkAnimationDescription *desc = g_value_get_boxed (value);
637 g_string_append (string, "none");
639 _gtk_animation_description_print (desc, string);
643 border_value_parse (GtkCssParser *parser,
647 GtkBorder border = { 0, };
651 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
653 if (_gtk_css_parser_begins_with (parser, '-'))
655 /* These are strictly speaking signed, but we want to be able to use them
656 for unsigned types too, as the actual ranges of values make this safe */
657 int res = _gtk_win32_theme_int_parse (parser, base, &numbers[i]);
659 if (res == 0) /* Parse error, report */
662 if (res < 0) /* Nothing known to expand */
667 if (!_gtk_css_parser_try_length (parser, &numbers[i]))
674 _gtk_css_parser_error (parser, "Expected valid border");
678 border.top = numbers[0];
680 border.right = numbers[1];
682 border.right = border.top;
684 border.bottom = numbers[2];
686 border.bottom = border.top;
688 border.left = numbers[3];
690 border.left = border.right;
692 g_value_set_boxed (value, &border);
697 border_value_print (const GValue *value, GString *string)
699 const GtkBorder *border = g_value_get_boxed (value);
702 g_string_append (string, "none");
703 else if (border->left != border->right)
704 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
705 else if (border->top != border->bottom)
706 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
707 else if (border->top != border->left)
708 g_string_append_printf (string, "%d %d", border->top, border->right);
710 g_string_append_printf (string, "%d", border->top);
714 gradient_value_parse (GtkCssParser *parser,
718 GtkGradient *gradient;
720 gradient = _gtk_gradient_parse (parser);
721 if (gradient == NULL)
724 g_value_take_boxed (value, gradient);
729 gradient_value_print (const GValue *value,
732 GtkGradient *gradient = g_value_get_boxed (value);
734 if (gradient == NULL)
735 g_string_append (string, "none");
738 char *s = gtk_gradient_to_string (gradient);
739 g_string_append (string, s);
745 pattern_value_parse (GtkCssParser *parser,
749 if (_gtk_css_parser_try (parser, "none", TRUE))
751 /* nothing to do here */
753 else if (_gtk_css_parser_begins_with (parser, '-'))
755 g_value_unset (value);
756 g_value_init (value, GTK_TYPE_GRADIENT);
757 return gradient_value_parse (parser, base, value);
761 GError *error = NULL;
765 cairo_surface_t *surface;
766 cairo_pattern_t *pattern;
768 cairo_matrix_t matrix;
770 file = _gtk_css_parser_read_url (parser, base);
774 path = g_file_get_path (file);
775 g_object_unref (file);
777 pixbuf = gdk_pixbuf_new_from_file (path, &error);
781 _gtk_css_parser_take_error (parser, error);
785 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
786 gdk_pixbuf_get_width (pixbuf),
787 gdk_pixbuf_get_height (pixbuf));
788 cr = cairo_create (surface);
789 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
791 pattern = cairo_pattern_create_for_surface (surface);
793 cairo_matrix_init_scale (&matrix,
794 gdk_pixbuf_get_width (pixbuf),
795 gdk_pixbuf_get_height (pixbuf));
796 cairo_pattern_set_matrix (pattern, &matrix);
798 cairo_surface_destroy (surface);
800 g_object_unref (pixbuf);
802 g_value_take_boxed (value, pattern);
808 static cairo_status_t
809 surface_write (void *closure,
810 const unsigned char *data,
813 g_byte_array_append (closure, data, length);
815 return CAIRO_STATUS_SUCCESS;
819 surface_print (cairo_surface_t *surface,
822 #if CAIRO_HAS_PNG_FUNCTIONS
826 array = g_byte_array_new ();
827 cairo_surface_write_to_png_stream (surface, surface_write, array);
828 base64 = g_base64_encode (array->data, array->len);
829 g_byte_array_free (array, TRUE);
831 g_string_append (string, "url(\"data:image/png;base64,");
832 g_string_append (string, base64);
833 g_string_append (string, "\")");
837 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
842 pattern_value_print (const GValue *value,
845 cairo_pattern_t *pattern;
846 cairo_surface_t *surface;
848 pattern = g_value_get_boxed (value);
852 g_string_append (string, "none");
856 switch (cairo_pattern_get_type (pattern))
858 case CAIRO_PATTERN_TYPE_SURFACE:
859 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
861 g_assert_not_reached ();
863 surface_print (surface, string);
865 case CAIRO_PATTERN_TYPE_SOLID:
866 case CAIRO_PATTERN_TYPE_LINEAR:
867 case CAIRO_PATTERN_TYPE_RADIAL:
869 g_assert_not_reached ();
875 pattern_value_compute (GtkStyleContext *context,
876 GtkCssValue *specified)
878 if (_gtk_css_value_holds (specified, GTK_TYPE_GRADIENT))
880 cairo_pattern_t *gradient;
882 gradient = gtk_gradient_resolve_for_context (_gtk_css_value_get_gradient (specified), context);
884 return _gtk_css_value_new_take_pattern (gradient);
887 return _gtk_css_value_ref (specified);
891 border_image_repeat_value_parse (GtkCssParser *parser,
895 GtkCssBorderImageRepeat image_repeat;
896 GtkCssBorderRepeatStyle styles[2];
899 for (i = 0; i < 2; i++)
901 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
905 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
909 styles[i] = styles[0];
912 image_repeat.hrepeat = styles[0];
913 image_repeat.vrepeat = styles[1];
915 g_value_set_boxed (value, &image_repeat);
921 border_image_repeat_value_print (const GValue *value,
924 GtkCssBorderImageRepeat *image_repeat;
926 image_repeat = g_value_get_boxed (value);
928 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
929 if (image_repeat->hrepeat != image_repeat->vrepeat)
931 g_string_append (string, " ");
932 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
937 enum_value_parse (GtkCssParser *parser,
943 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
945 g_value_set_enum (value, v);
953 enum_value_print (const GValue *value,
956 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
960 flags_value_parse (GtkCssParser *parser,
964 GFlagsClass *flags_class;
965 GFlagsValue *flag_value;
969 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
972 str = _gtk_css_parser_try_ident (parser, TRUE);
975 _gtk_css_parser_error (parser, "Expected an identifier");
976 g_type_class_unref (flags_class);
980 flag_value = g_flags_get_value_by_nick (flags_class, str);
983 _gtk_css_parser_error (parser,
984 "Unknown flag value '%s' for type '%s'",
985 str, g_type_name (G_VALUE_TYPE (value)));
986 /* XXX Do we want to return FALSE here? We can get
987 * forward-compatibility for new values this way
990 g_type_class_unref (flags_class);
996 while (_gtk_css_parser_try (parser, ",", FALSE));
998 g_type_class_unref (flags_class);
1000 g_value_set_enum (value, flags);
1006 flags_value_print (const GValue *value,
1009 GFlagsClass *flags_class;
1012 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1013 flags = g_value_get_flags (value);
1015 for (i = 0; i < flags_class->n_values; i++)
1017 GFlagsValue *flags_value = &flags_class->values[i];
1019 if (flags & flags_value->value)
1021 if (string->len != 0)
1022 g_string_append (string, ", ");
1024 g_string_append (string, flags_value->value_nick);
1028 g_type_class_unref (flags_class);
1034 gtk_css_style_funcs_init (void)
1036 if (G_LIKELY (parse_funcs != NULL))
1039 parse_funcs = g_hash_table_new (NULL, NULL);
1040 print_funcs = g_hash_table_new (NULL, NULL);
1041 compute_funcs = g_hash_table_new (NULL, NULL);
1043 register_conversion_function (GDK_TYPE_RGBA,
1046 rgba_value_compute);
1047 register_conversion_function (GDK_TYPE_COLOR,
1050 color_value_compute);
1051 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
1052 symbolic_color_value_parse,
1053 symbolic_color_value_print,
1055 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
1056 font_description_value_parse,
1057 font_description_value_print,
1059 register_conversion_function (G_TYPE_BOOLEAN,
1060 boolean_value_parse,
1061 boolean_value_print,
1063 register_conversion_function (G_TYPE_INT,
1067 register_conversion_function (G_TYPE_UINT,
1071 register_conversion_function (G_TYPE_DOUBLE,
1075 register_conversion_function (G_TYPE_FLOAT,
1079 register_conversion_function (G_TYPE_STRING,
1083 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
1084 theming_engine_value_parse,
1085 theming_engine_value_print,
1087 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
1088 animation_description_value_parse,
1089 animation_description_value_print,
1091 register_conversion_function (GTK_TYPE_BORDER,
1095 register_conversion_function (GTK_TYPE_GRADIENT,
1096 gradient_value_parse,
1097 gradient_value_print,
1099 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
1100 pattern_value_parse,
1101 pattern_value_print,
1102 pattern_value_compute);
1103 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1104 border_image_repeat_value_parse,
1105 border_image_repeat_value_print,
1107 register_conversion_function (G_TYPE_ENUM,
1111 register_conversion_function (G_TYPE_FLAGS,
1118 * _gtk_css_style_parse_value:
1119 * @value: the value to parse into. Must be a valid initialized #GValue
1120 * @parser: the parser to parse from
1121 * @base: the base URL for @parser
1123 * This is the generic parsing function used for CSS values. If the
1124 * function fails to parse a value, it will emit an error on @parser,
1125 * return %FALSE and not touch @value.
1127 * Returns: %TRUE if parsing succeeded.
1130 _gtk_css_style_parse_value (GValue *value,
1131 GtkCssParser *parser,
1134 GtkStyleParseFunc func;
1136 g_return_val_if_fail (value != NULL, FALSE);
1137 g_return_val_if_fail (parser != NULL, FALSE);
1139 gtk_css_style_funcs_init ();
1141 func = g_hash_table_lookup (parse_funcs,
1142 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1144 func = g_hash_table_lookup (parse_funcs,
1145 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1149 _gtk_css_parser_error (parser,
1150 "Cannot convert to type '%s'",
1151 g_type_name (G_VALUE_TYPE (value)));
1155 return (*func) (parser, base, value);
1159 * _gtk_css_style_print_value:
1160 * @value: an initialized GValue returned from _gtk_css_style_parse()
1161 * @string: the string to print into
1163 * Prints @value into @string as a CSS value. If @value is not a
1164 * valid value, a random string will be printed instead.
1167 _gtk_css_style_print_value (const GValue *value,
1170 GtkStylePrintFunc func;
1172 gtk_css_style_funcs_init ();
1174 func = g_hash_table_lookup (print_funcs,
1175 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1177 func = g_hash_table_lookup (print_funcs,
1178 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1182 char *s = g_strdup_value_contents (value);
1183 g_string_append (string, s);
1188 func (value, string);
1192 * _gtk_css_style_compute_value:
1193 * @computed: (out): a value to be filled with the result
1194 * @context: the context to use for computing the value
1195 * @specified: the value to use for the computation
1197 * Converts the @specified value into the @computed value using the
1198 * information in @context. The values must have matching types, ie
1199 * @specified must be a result of a call to
1200 * _gtk_css_style_parse_value() with the same type as @computed.
1203 _gtk_css_style_compute_value (GtkStyleContext *context,
1205 GtkCssValue *specified)
1207 GtkStyleComputeFunc func;
1209 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
1211 gtk_css_style_funcs_init ();
1213 func = g_hash_table_lookup (compute_funcs,
1214 GSIZE_TO_POINTER (target_type));
1216 func = g_hash_table_lookup (compute_funcs,
1217 GSIZE_TO_POINTER (g_type_fundamental (target_type)));
1220 return func (context, specified);
1222 return _gtk_css_value_ref (specified);