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 "gtkcsscolorvalueprivate.h"
31 #include "gtkcssimagegradientprivate.h"
32 #include "gtkcssprovider.h"
33 #include "gtkcssrgbavalueprivate.h"
34 #include "gtkcsstypedvalueprivate.h"
35 #include "gtkcsstypesprivate.h"
36 #include "gtkprivatetypebuiltins.h"
37 #include "gtkstylecontextprivate.h"
38 #include "gtkthemingengine.h"
39 #include "gtktypebuiltins.h"
40 #include "gtkwin32themeprivate.h"
42 #include "deprecated/gtkgradientprivate.h"
43 #include "deprecated/gtksymboliccolorprivate.h"
45 /* this is in case round() is not provided by the compiler,
46 * such as in the case of C89 compilers, like MSVC
48 #include "fallback-c89.c"
50 static GHashTable *parse_funcs = NULL;
51 static GHashTable *print_funcs = NULL;
52 static GHashTable *compute_funcs = NULL;
54 typedef gboolean (* GtkStyleParseFunc) (GtkCssParser *parser,
56 typedef void (* GtkStylePrintFunc) (const GValue *value,
58 typedef GtkCssValue * (* GtkStyleComputeFunc) (GtkStyleProviderPrivate *provider,
59 GtkCssComputedValues *values,
60 GtkCssComputedValues *parent_values,
61 GtkCssValue *specified,
62 GtkCssDependencies *dependencies);
65 register_conversion_function (GType type,
66 GtkStyleParseFunc parse,
67 GtkStylePrintFunc print,
68 GtkStyleComputeFunc compute)
71 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
73 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
75 g_hash_table_insert (compute_funcs, GSIZE_TO_POINTER (type), compute);
79 string_append_double (GString *string,
82 char buf[G_ASCII_DTOSTR_BUF_SIZE];
84 g_ascii_dtostr (buf, sizeof (buf), d);
85 g_string_append (string, buf);
89 string_append_string (GString *str,
94 g_string_append_c (str, '"');
97 len = strcspn (string, "\"\n\r\f");
98 g_string_append (str, string);
105 g_string_append (str, "\\A ");
108 g_string_append (str, "\\D ");
111 g_string_append (str, "\\C ");
114 g_string_append (str, "\\\"");
117 g_assert_not_reached ();
122 g_string_append_c (str, '"');
125 /*** IMPLEMENTATIONS ***/
128 enum_parse (GtkCssParser *parser,
134 if (_gtk_css_parser_try_enum (parser, type, res))
137 str = _gtk_css_parser_try_ident (parser, TRUE);
140 _gtk_css_parser_error (parser, "Expected an identifier");
144 _gtk_css_parser_error (parser,
145 "Unknown value '%s' for enum type '%s'",
146 str, g_type_name (type));
153 enum_print (int value,
157 GEnumClass *enum_class;
158 GEnumValue *enum_value;
160 enum_class = g_type_class_ref (type);
161 enum_value = g_enum_get_value (enum_class, value);
163 g_string_append (string, enum_value->value_nick);
165 g_type_class_unref (enum_class);
169 rgba_value_parse (GtkCssParser *parser,
172 GtkSymbolicColor *symbolic;
175 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
177 symbolic = _gtk_css_symbolic_value_new (parser);
178 if (symbolic == NULL)
181 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
183 g_value_set_boxed (value, &rgba);
184 gtk_symbolic_color_unref (symbolic);
188 g_value_unset (value);
189 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
190 g_value_take_boxed (value, symbolic);
193 G_GNUC_END_IGNORE_DEPRECATIONS;
199 rgba_value_print (const GValue *value,
202 const GdkRGBA *rgba = g_value_get_boxed (value);
205 g_string_append (string, "none");
208 char *s = gdk_rgba_to_string (rgba);
209 g_string_append (string, s);
215 rgba_value_compute (GtkStyleProviderPrivate *provider,
216 GtkCssComputedValues *values,
217 GtkCssComputedValues *parent_values,
218 GtkCssValue *specified,
219 GtkCssDependencies *dependencies)
221 GdkRGBA white = { 1, 1, 1, 1 };
224 value = _gtk_css_typed_value_get (specified);
226 if (G_VALUE_HOLDS (value, GTK_TYPE_SYMBOLIC_COLOR))
228 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
230 GValue new_value = G_VALUE_INIT;
233 val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (symbolic),
235 _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
236 GTK_CSS_DEPENDS_ON_COLOR,
240 rgba = *_gtk_css_rgba_value_get_rgba (val);
241 _gtk_css_value_unref (val);
246 g_value_init (&new_value, GDK_TYPE_RGBA);
247 g_value_set_boxed (&new_value, &rgba);
248 return _gtk_css_typed_value_new_take (&new_value);
251 return _gtk_css_value_ref (specified);
255 color_value_parse (GtkCssParser *parser,
258 GtkSymbolicColor *symbolic;
261 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
263 symbolic = _gtk_css_symbolic_value_new (parser);
264 if (symbolic == NULL)
267 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
271 color.red = rgba.red * 65535. + 0.5;
272 color.green = rgba.green * 65535. + 0.5;
273 color.blue = rgba.blue * 65535. + 0.5;
275 g_value_set_boxed (value, &color);
279 g_value_unset (value);
280 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
281 g_value_take_boxed (value, symbolic);
284 G_GNUC_END_IGNORE_DEPRECATIONS;
290 color_value_print (const GValue *value,
293 const GdkColor *color = g_value_get_boxed (value);
296 g_string_append (string, "none");
299 char *s = gdk_color_to_string (color);
300 g_string_append (string, s);
306 color_value_compute (GtkStyleProviderPrivate *provider,
307 GtkCssComputedValues *values,
308 GtkCssComputedValues *parent_values,
309 GtkCssValue *specified,
310 GtkCssDependencies *dependencies)
312 GdkColor color = { 0, 65535, 65535, 65535 };
315 value = _gtk_css_typed_value_get (specified);
317 if (G_VALUE_HOLDS (value, GTK_TYPE_SYMBOLIC_COLOR))
319 GValue new_value = G_VALUE_INIT;
322 val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (g_value_get_boxed (value)),
324 _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
325 GTK_CSS_DEPENDS_ON_COLOR,
329 const GdkRGBA *rgba = _gtk_css_rgba_value_get_rgba (val);
330 color.red = rgba->red * 65535. + 0.5;
331 color.green = rgba->green * 65535. + 0.5;
332 color.blue = rgba->blue * 65535. + 0.5;
333 _gtk_css_value_unref (val);
336 g_value_init (&new_value, GDK_TYPE_COLOR);
337 g_value_set_boxed (&new_value, &color);
338 return _gtk_css_typed_value_new_take (&new_value);
341 return _gtk_css_value_ref (specified);
345 symbolic_color_value_parse (GtkCssParser *parser,
348 GtkSymbolicColor *symbolic;
350 symbolic = _gtk_css_symbolic_value_new (parser);
351 if (symbolic == NULL)
354 g_value_take_boxed (value, symbolic);
359 symbolic_color_value_print (const GValue *value,
362 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
364 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
366 if (symbolic == NULL)
367 g_string_append (string, "none");
370 char *s = gtk_symbolic_color_to_string (symbolic);
371 g_string_append (string, s);
375 G_GNUC_END_IGNORE_DEPRECATIONS;
379 font_description_value_parse (GtkCssParser *parser,
382 PangoFontDescription *font_desc;
386 str = _gtk_css_parser_read_value (parser);
390 font_desc = pango_font_description_from_string (str);
391 mask = pango_font_description_get_set_fields (font_desc);
392 /* These values are not really correct,
393 * but the fields must be set, so we set them to something */
394 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
395 pango_font_description_set_family_static (font_desc, "Sans");
396 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
397 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
399 g_value_take_boxed (value, font_desc);
404 font_description_value_print (const GValue *value,
407 const PangoFontDescription *desc = g_value_get_boxed (value);
410 g_string_append (string, "none");
413 char *s = pango_font_description_to_string (desc);
414 g_string_append (string, s);
420 boolean_value_parse (GtkCssParser *parser,
423 if (_gtk_css_parser_try (parser, "true", TRUE) ||
424 _gtk_css_parser_try (parser, "1", TRUE))
426 g_value_set_boolean (value, TRUE);
429 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
430 _gtk_css_parser_try (parser, "0", TRUE))
432 g_value_set_boolean (value, FALSE);
437 _gtk_css_parser_error (parser, "Expected a boolean value");
443 boolean_value_print (const GValue *value,
446 if (g_value_get_boolean (value))
447 g_string_append (string, "true");
449 g_string_append (string, "false");
453 int_value_parse (GtkCssParser *parser,
458 if (_gtk_css_parser_begins_with (parser, '-'))
460 int res = _gtk_win32_theme_int_parse (parser, &i);
463 g_value_set_int (value, i);
466 /* < 0 => continue */
469 if (!_gtk_css_parser_try_int (parser, &i))
471 _gtk_css_parser_error (parser, "Expected a valid integer value");
475 g_value_set_int (value, i);
480 int_value_print (const GValue *value,
483 g_string_append_printf (string, "%d", g_value_get_int (value));
487 uint_value_parse (GtkCssParser *parser,
492 if (!_gtk_css_parser_try_uint (parser, &u))
494 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
498 g_value_set_uint (value, u);
503 uint_value_print (const GValue *value,
506 g_string_append_printf (string, "%u", g_value_get_uint (value));
510 double_value_parse (GtkCssParser *parser,
515 if (!_gtk_css_parser_try_double (parser, &d))
517 _gtk_css_parser_error (parser, "Expected a number");
521 g_value_set_double (value, d);
526 double_value_print (const GValue *value,
529 string_append_double (string, g_value_get_double (value));
533 float_value_parse (GtkCssParser *parser,
538 if (!_gtk_css_parser_try_double (parser, &d))
540 _gtk_css_parser_error (parser, "Expected a number");
544 g_value_set_float (value, d);
549 float_value_print (const GValue *value,
552 string_append_double (string, g_value_get_float (value));
556 string_value_parse (GtkCssParser *parser,
559 char *str = _gtk_css_parser_read_string (parser);
564 g_value_take_string (value, str);
569 string_value_print (const GValue *value,
572 string_append_string (str, g_value_get_string (value));
576 theming_engine_value_parse (GtkCssParser *parser,
579 GtkThemingEngine *engine;
582 if (_gtk_css_parser_try (parser, "none", TRUE))
584 g_value_set_object (value, gtk_theming_engine_load (NULL));
588 str = _gtk_css_parser_try_ident (parser, TRUE);
591 _gtk_css_parser_error (parser, "Expected a valid theme name");
595 engine = gtk_theming_engine_load (str);
599 _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
604 g_value_set_object (value, engine);
610 theming_engine_value_print (const GValue *value,
613 GtkThemingEngine *engine;
616 engine = g_value_get_object (value);
618 g_string_append (string, "none");
621 /* XXX: gtk_theming_engine_get_name()? */
622 g_object_get (engine, "name", &name, NULL);
623 g_string_append (string, name ? name : "none");
629 border_value_parse (GtkCssParser *parser,
632 GtkBorder border = { 0, };
636 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
638 if (_gtk_css_parser_begins_with (parser, '-'))
640 /* These are strictly speaking signed, but we want to be able to use them
641 for unsigned types too, as the actual ranges of values make this safe */
642 int res = _gtk_win32_theme_int_parse (parser, &numbers[i]);
644 if (res == 0) /* Parse error, report */
647 if (res < 0) /* Nothing known to expand */
652 if (!_gtk_css_parser_try_length (parser, &numbers[i]))
659 _gtk_css_parser_error (parser, "Expected valid border");
663 border.top = numbers[0];
665 border.right = numbers[1];
667 border.right = border.top;
669 border.bottom = numbers[2];
671 border.bottom = border.top;
673 border.left = numbers[3];
675 border.left = border.right;
677 g_value_set_boxed (value, &border);
682 border_value_print (const GValue *value, GString *string)
684 const GtkBorder *border = g_value_get_boxed (value);
687 g_string_append (string, "none");
688 else if (border->left != border->right)
689 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
690 else if (border->top != border->bottom)
691 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
692 else if (border->top != border->left)
693 g_string_append_printf (string, "%d %d", border->top, border->right);
695 g_string_append_printf (string, "%d", border->top);
699 gradient_value_parse (GtkCssParser *parser,
702 GtkGradient *gradient;
704 gradient = _gtk_gradient_parse (parser);
705 if (gradient == NULL)
708 g_value_take_boxed (value, gradient);
713 gradient_value_print (const GValue *value,
716 GtkGradient *gradient = g_value_get_boxed (value);
718 G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
720 if (gradient == NULL)
721 g_string_append (string, "none");
724 char *s = gtk_gradient_to_string (gradient);
725 g_string_append (string, s);
729 G_GNUC_END_IGNORE_DEPRECATIONS;
733 pattern_value_parse (GtkCssParser *parser,
736 if (_gtk_css_parser_try (parser, "none", TRUE))
738 /* nothing to do here */
740 else if (_gtk_css_parser_begins_with (parser, '-'))
742 g_value_unset (value);
743 g_value_init (value, GTK_TYPE_GRADIENT);
744 return gradient_value_parse (parser, value);
748 GError *error = NULL;
752 cairo_surface_t *surface;
753 cairo_pattern_t *pattern;
755 cairo_matrix_t matrix;
757 file = _gtk_css_parser_read_url (parser);
761 path = g_file_get_path (file);
762 g_object_unref (file);
764 pixbuf = gdk_pixbuf_new_from_file (path, &error);
768 _gtk_css_parser_take_error (parser, error);
772 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
773 gdk_pixbuf_get_width (pixbuf),
774 gdk_pixbuf_get_height (pixbuf));
775 cr = cairo_create (surface);
776 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
778 pattern = cairo_pattern_create_for_surface (surface);
780 cairo_matrix_init_scale (&matrix,
781 gdk_pixbuf_get_width (pixbuf),
782 gdk_pixbuf_get_height (pixbuf));
783 cairo_pattern_set_matrix (pattern, &matrix);
785 cairo_surface_destroy (surface);
787 g_object_unref (pixbuf);
789 g_value_take_boxed (value, pattern);
795 static cairo_status_t
796 surface_write (void *closure,
797 const unsigned char *data,
800 g_byte_array_append (closure, data, length);
802 return CAIRO_STATUS_SUCCESS;
806 surface_print (cairo_surface_t *surface,
809 #if CAIRO_HAS_PNG_FUNCTIONS
813 array = g_byte_array_new ();
814 cairo_surface_write_to_png_stream (surface, surface_write, array);
815 base64 = g_base64_encode (array->data, array->len);
816 g_byte_array_free (array, TRUE);
818 g_string_append (string, "url(\"data:image/png;base64,");
819 g_string_append (string, base64);
820 g_string_append (string, "\")");
824 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
829 pattern_value_print (const GValue *value,
832 cairo_pattern_t *pattern;
833 cairo_surface_t *surface;
835 pattern = g_value_get_boxed (value);
839 g_string_append (string, "none");
843 switch (cairo_pattern_get_type (pattern))
845 case CAIRO_PATTERN_TYPE_SURFACE:
846 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
848 g_assert_not_reached ();
850 surface_print (surface, string);
852 case CAIRO_PATTERN_TYPE_LINEAR:
853 case CAIRO_PATTERN_TYPE_RADIAL:
854 g_string_append (string, "none /* FIXME: add support for printing gradients */");
856 case CAIRO_PATTERN_TYPE_SOLID:
858 g_assert_not_reached ();
864 pattern_value_compute (GtkStyleProviderPrivate *provider,
865 GtkCssComputedValues *values,
866 GtkCssComputedValues *parent_values,
867 GtkCssValue *specified,
868 GtkCssDependencies *dependencies)
870 const GValue *value = _gtk_css_typed_value_get (specified);
872 if (G_VALUE_HOLDS (value, GTK_TYPE_GRADIENT))
874 GValue new_value = G_VALUE_INIT;
875 cairo_pattern_t *gradient;
877 gradient = _gtk_gradient_resolve_full (g_value_get_boxed (value), provider, values, parent_values, dependencies);
879 g_value_init (&new_value, CAIRO_GOBJECT_TYPE_PATTERN);
880 g_value_take_boxed (&new_value, gradient);
881 return _gtk_css_typed_value_new_take (&new_value);
884 return _gtk_css_value_ref (specified);
888 enum_value_parse (GtkCssParser *parser,
893 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
895 g_value_set_enum (value, v);
903 enum_value_print (const GValue *value,
906 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
910 flags_value_parse (GtkCssParser *parser,
913 GFlagsClass *flags_class;
914 GFlagsValue *flag_value;
918 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
921 str = _gtk_css_parser_try_ident (parser, TRUE);
924 _gtk_css_parser_error (parser, "Expected an identifier");
925 g_type_class_unref (flags_class);
929 flag_value = g_flags_get_value_by_nick (flags_class, str);
932 _gtk_css_parser_error (parser,
933 "Unknown flag value '%s' for type '%s'",
934 str, g_type_name (G_VALUE_TYPE (value)));
935 /* XXX Do we want to return FALSE here? We can get
936 * forward-compatibility for new values this way
939 g_type_class_unref (flags_class);
945 while (_gtk_css_parser_try (parser, ",", FALSE));
947 g_type_class_unref (flags_class);
949 g_value_set_enum (value, flags);
955 flags_value_print (const GValue *value,
958 GFlagsClass *flags_class;
961 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
962 flags = g_value_get_flags (value);
964 for (i = 0; i < flags_class->n_values; i++)
966 GFlagsValue *flags_value = &flags_class->values[i];
968 if (flags & flags_value->value)
970 if (string->len != 0)
971 g_string_append (string, ", ");
973 g_string_append (string, flags_value->value_nick);
977 g_type_class_unref (flags_class);
983 gtk_css_style_funcs_init (void)
985 if (G_LIKELY (parse_funcs != NULL))
988 parse_funcs = g_hash_table_new (NULL, NULL);
989 print_funcs = g_hash_table_new (NULL, NULL);
990 compute_funcs = g_hash_table_new (NULL, NULL);
992 register_conversion_function (GDK_TYPE_RGBA,
996 register_conversion_function (GDK_TYPE_COLOR,
999 color_value_compute);
1000 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
1001 symbolic_color_value_parse,
1002 symbolic_color_value_print,
1004 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
1005 font_description_value_parse,
1006 font_description_value_print,
1008 register_conversion_function (G_TYPE_BOOLEAN,
1009 boolean_value_parse,
1010 boolean_value_print,
1012 register_conversion_function (G_TYPE_INT,
1016 register_conversion_function (G_TYPE_UINT,
1020 register_conversion_function (G_TYPE_DOUBLE,
1024 register_conversion_function (G_TYPE_FLOAT,
1028 register_conversion_function (G_TYPE_STRING,
1032 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
1033 theming_engine_value_parse,
1034 theming_engine_value_print,
1036 register_conversion_function (GTK_TYPE_BORDER,
1040 register_conversion_function (GTK_TYPE_GRADIENT,
1041 gradient_value_parse,
1042 gradient_value_print,
1044 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
1045 pattern_value_parse,
1046 pattern_value_print,
1047 pattern_value_compute);
1048 register_conversion_function (G_TYPE_ENUM,
1052 register_conversion_function (G_TYPE_FLAGS,
1059 * _gtk_css_style_parse_value:
1060 * @value: the value to parse into. Must be a valid initialized #GValue
1061 * @parser: the parser to parse from
1063 * This is the generic parsing function used for CSS values. If the
1064 * function fails to parse a value, it will emit an error on @parser,
1065 * return %FALSE and not touch @value.
1067 * Returns: %TRUE if parsing succeeded.
1070 _gtk_css_style_parse_value (GValue *value,
1071 GtkCssParser *parser)
1073 GtkStyleParseFunc func;
1075 g_return_val_if_fail (value != NULL, FALSE);
1076 g_return_val_if_fail (parser != NULL, FALSE);
1078 gtk_css_style_funcs_init ();
1080 func = g_hash_table_lookup (parse_funcs,
1081 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1083 func = g_hash_table_lookup (parse_funcs,
1084 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1088 _gtk_css_parser_error (parser,
1089 "Cannot convert to type '%s'",
1090 g_type_name (G_VALUE_TYPE (value)));
1094 return (*func) (parser, value);
1098 * _gtk_css_style_print_value:
1099 * @value: an initialized GValue returned from _gtk_css_style_parse()
1100 * @string: the string to print into
1102 * Prints @value into @string as a CSS value. If @value is not a
1103 * valid value, a random string will be printed instead.
1106 _gtk_css_style_print_value (const GValue *value,
1109 GtkStylePrintFunc func;
1111 gtk_css_style_funcs_init ();
1113 func = g_hash_table_lookup (print_funcs,
1114 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1116 func = g_hash_table_lookup (print_funcs,
1117 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1121 char *s = g_strdup_value_contents (value);
1122 g_string_append (string, s);
1127 func (value, string);
1131 * _gtk_css_style_compute_value:
1132 * @provider: Style provider to look up information from
1133 * @values: The values to compute for
1134 * @parent_values: Values to look up inherited values from
1135 * @target_type: Type the resulting value should have
1136 * @specified: the value to use for the computation
1137 * @dependencies: (out): Value initialized with 0 to take the dependencies
1138 * of the returned value
1140 * Converts the @specified value into the @computed value using the
1141 * information in @context. The values must have matching types, ie
1142 * @specified must be a result of a call to
1143 * _gtk_css_style_parse_value() with the same type as @computed.
1145 * Returns: the resulting value
1148 _gtk_css_style_compute_value (GtkStyleProviderPrivate *provider,
1149 GtkCssComputedValues *values,
1150 GtkCssComputedValues *parent_values,
1152 GtkCssValue *specified,
1153 GtkCssDependencies *dependencies)
1155 GtkStyleComputeFunc func;
1157 g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
1158 g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
1159 g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);
1160 g_return_val_if_fail (*dependencies == 0, NULL);
1162 gtk_css_style_funcs_init ();
1164 func = g_hash_table_lookup (compute_funcs,
1165 GSIZE_TO_POINTER (target_type));
1167 func = g_hash_table_lookup (compute_funcs,
1168 GSIZE_TO_POINTER (g_type_fundamental (target_type)));
1171 return func (provider, values, parent_values, specified, dependencies);
1173 return _gtk_css_value_ref (specified);