2 * Copyright © 2011 Red Hat Inc.
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.1 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/>.
17 * Authors: Benjamin Otte <otte@gnome.org>
22 #include "gtkcssshorthandpropertyprivate.h"
24 #include <cairo-gobject.h>
27 #include "gtkcssarrayvalueprivate.h"
28 #include "gtkcssbgsizevalueprivate.h"
29 #include "gtkcssbordervalueprivate.h"
30 #include "gtkcsscolorvalueprivate.h"
31 #include "gtkcsscornervalueprivate.h"
32 #include "gtkcsseasevalueprivate.h"
33 #include "gtkcssenumvalueprivate.h"
34 #include "gtkcssimageprivate.h"
35 #include "gtkcssimagevalueprivate.h"
36 #include "gtkcssnumbervalueprivate.h"
37 #include "gtkcsspositionvalueprivate.h"
38 #include "gtkcssrepeatvalueprivate.h"
39 #include "gtkcssstringvalueprivate.h"
40 #include "gtkcssstylefuncsprivate.h"
41 #include "gtkcssvalueprivate.h"
42 #include "gtkstylepropertiesprivate.h"
43 #include "gtktypebuiltins.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"
53 value_is_done_parsing (GtkCssParser *parser)
55 return _gtk_css_parser_is_eof (parser) ||
56 _gtk_css_parser_begins_with (parser, ',') ||
57 _gtk_css_parser_begins_with (parser, ';') ||
58 _gtk_css_parser_begins_with (parser, '}');
62 parse_four_numbers (GtkCssShorthandProperty *shorthand,
65 GtkCssNumberParseFlags flags)
69 for (i = 0; i < 4; i++)
71 if (!_gtk_css_parser_has_number (parser))
74 values[i] = _gtk_css_number_value_parse (parser, flags);
75 if (values[i] == NULL)
81 _gtk_css_parser_error (parser, "Expected a length");
87 values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
94 parse_margin (GtkCssShorthandProperty *shorthand,
98 return parse_four_numbers (shorthand,
101 GTK_CSS_NUMBER_AS_PIXELS
102 | GTK_CSS_PARSE_LENGTH);
106 parse_padding (GtkCssShorthandProperty *shorthand,
107 GtkCssValue **values,
108 GtkCssParser *parser)
110 return parse_four_numbers (shorthand,
113 GTK_CSS_POSITIVE_ONLY
114 | GTK_CSS_NUMBER_AS_PIXELS
115 | GTK_CSS_PARSE_LENGTH);
119 parse_border_width (GtkCssShorthandProperty *shorthand,
120 GtkCssValue **values,
121 GtkCssParser *parser)
123 return parse_four_numbers (shorthand,
126 GTK_CSS_POSITIVE_ONLY
127 | GTK_CSS_NUMBER_AS_PIXELS
128 | GTK_CSS_PARSE_LENGTH);
132 parse_border_radius (GtkCssShorthandProperty *shorthand,
133 GtkCssValue **values,
134 GtkCssParser *parser)
136 GtkCssValue *x[4] = { NULL, }, *y[4] = { NULL, };
139 for (i = 0; i < 4; i++)
141 if (!_gtk_css_parser_has_number (parser))
143 x[i] = _gtk_css_number_value_parse (parser,
144 GTK_CSS_POSITIVE_ONLY
145 | GTK_CSS_PARSE_PERCENT
146 | GTK_CSS_NUMBER_AS_PIXELS
147 | GTK_CSS_PARSE_LENGTH);
154 _gtk_css_parser_error (parser, "Expected a number");
158 /* The magic (i - 1) >> 1 below makes it take the correct value
159 * according to spec. Feel free to check the 4 cases */
161 x[i] = _gtk_css_value_ref (x[(i - 1) >> 1]);
163 if (_gtk_css_parser_try (parser, "/", TRUE))
165 for (i = 0; i < 4; i++)
167 if (!_gtk_css_parser_has_number (parser))
169 y[i] = _gtk_css_number_value_parse (parser,
170 GTK_CSS_POSITIVE_ONLY
171 | GTK_CSS_PARSE_PERCENT
172 | GTK_CSS_NUMBER_AS_PIXELS
173 | GTK_CSS_PARSE_LENGTH);
180 _gtk_css_parser_error (parser, "Expected a number");
185 y[i] = _gtk_css_value_ref (y[(i - 1) >> 1]);
189 for (i = 0; i < 4; i++)
190 y[i] = _gtk_css_value_ref (x[i]);
193 for (i = 0; i < 4; i++)
195 values[i] = _gtk_css_corner_value_new (x[i], y[i]);
201 for (i = 0; i < 4; i++)
204 _gtk_css_value_unref (x[i]);
206 _gtk_css_value_unref (y[i]);
212 parse_border_color (GtkCssShorthandProperty *shorthand,
213 GtkCssValue **values,
214 GtkCssParser *parser)
218 for (i = 0; i < 4; i++)
220 values[i] = _gtk_css_color_value_parse (parser);
221 if (values[i] == NULL)
224 if (value_is_done_parsing (parser))
228 for (i++; i < 4; i++)
230 values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
237 parse_border_style (GtkCssShorthandProperty *shorthand,
238 GtkCssValue **values,
239 GtkCssParser *parser)
243 for (i = 0; i < 4; i++)
245 values[i] = _gtk_css_border_style_value_try_parse (parser);
246 if (values[i] == NULL)
252 _gtk_css_parser_error (parser, "Expected a border style");
257 values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
263 parse_border_image (GtkCssShorthandProperty *shorthand,
264 GtkCssValue **values,
265 GtkCssParser *parser)
269 if (values[0] == NULL &&
270 (_gtk_css_parser_has_prefix (parser, "none") ||
271 _gtk_css_image_can_parse (parser)))
275 if (_gtk_css_parser_try (parser, "none", TRUE))
279 image = _gtk_css_image_new_parse (parser);
284 values[0] = _gtk_css_image_value_new (image);
286 else if (values[3] == NULL &&
287 (values[3] = _gtk_css_border_repeat_value_try_parse (parser)))
289 /* please move along */
291 else if (values[1] == NULL)
293 values[1] = _gtk_css_border_value_parse (parser,
294 GTK_CSS_PARSE_PERCENT
295 | GTK_CSS_PARSE_NUMBER
296 | GTK_CSS_POSITIVE_ONLY,
299 if (values[1] == NULL)
302 if (_gtk_css_parser_try (parser, "/", TRUE))
304 values[2] = _gtk_css_border_value_parse (parser,
305 GTK_CSS_PARSE_PERCENT
306 | GTK_CSS_PARSE_LENGTH
307 | GTK_CSS_PARSE_NUMBER
308 | GTK_CSS_POSITIVE_ONLY,
311 if (values[2] == NULL)
317 /* We parsed everything and there's still stuff left?
318 * Pretend we didn't notice and let the normal code produce
319 * a 'junk at end of value' error */
323 while (!value_is_done_parsing (parser));
329 parse_border_side (GtkCssShorthandProperty *shorthand,
330 GtkCssValue **values,
331 GtkCssParser *parser)
335 if (values[0] == NULL &&
336 _gtk_css_parser_has_number (parser))
338 values[0] = _gtk_css_number_value_parse (parser,
339 GTK_CSS_POSITIVE_ONLY
340 | GTK_CSS_NUMBER_AS_PIXELS
341 | GTK_CSS_PARSE_LENGTH);
342 if (values[0] == NULL)
345 else if (values[1] == NULL &&
346 (values[1] = _gtk_css_border_style_value_try_parse (parser)))
350 else if (values[2] == NULL)
352 values[2] = _gtk_css_color_value_parse (parser);
353 if (values[2] == NULL)
357 while (!value_is_done_parsing (parser));
363 parse_border (GtkCssShorthandProperty *shorthand,
364 GtkCssValue **values,
365 GtkCssParser *parser)
369 if (values[0] == NULL &&
370 _gtk_css_parser_has_number (parser))
372 values[0] = _gtk_css_number_value_parse (parser,
373 GTK_CSS_POSITIVE_ONLY
374 | GTK_CSS_NUMBER_AS_PIXELS
375 | GTK_CSS_PARSE_LENGTH);
376 if (values[0] == NULL)
378 values[1] = _gtk_css_value_ref (values[0]);
379 values[2] = _gtk_css_value_ref (values[0]);
380 values[3] = _gtk_css_value_ref (values[0]);
382 else if (values[4] == NULL &&
383 (values[4] = _gtk_css_border_style_value_try_parse (parser)))
385 values[5] = _gtk_css_value_ref (values[4]);
386 values[6] = _gtk_css_value_ref (values[4]);
387 values[7] = _gtk_css_value_ref (values[4]);
389 else if (!G_IS_VALUE (&values[8]))
391 values[8] = _gtk_css_color_value_parse (parser);
392 if (values[8] == NULL)
395 values[9] = _gtk_css_value_ref (values[8]);
396 values[10] = _gtk_css_value_ref (values[8]);
397 values[11] = _gtk_css_value_ref (values[8]);
401 /* We parsed everything and there's still stuff left?
402 * Pretend we didn't notice and let the normal code produce
403 * a 'junk at end of value' error */
407 while (!value_is_done_parsing (parser));
409 /* Note that border-image values are not set: according to the spec
410 they just need to be reset when using the border shorthand */
416 parse_font (GtkCssShorthandProperty *shorthand,
417 GtkCssValue **values,
418 GtkCssParser *parser)
420 PangoFontDescription *desc;
424 str = _gtk_css_parser_read_value (parser);
428 desc = pango_font_description_from_string (str);
431 mask = pango_font_description_get_set_fields (desc);
433 if (mask & PANGO_FONT_MASK_FAMILY)
435 values[0] = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (desc)));
437 if (mask & PANGO_FONT_MASK_STYLE)
439 values[1] = _gtk_css_font_style_value_new (pango_font_description_get_style (desc));
441 if (mask & PANGO_FONT_MASK_VARIANT)
443 values[2] = _gtk_css_font_variant_value_new (pango_font_description_get_variant (desc));
445 if (mask & PANGO_FONT_MASK_WEIGHT)
447 values[3] = _gtk_css_font_weight_value_new (pango_font_description_get_weight (desc));
449 if (mask & PANGO_FONT_MASK_SIZE)
451 values[4] = _gtk_css_number_value_new ((double) pango_font_description_get_size (desc) / PANGO_SCALE, GTK_CSS_PX);
454 pango_font_description_free (desc);
460 parse_one_background (GtkCssShorthandProperty *shorthand,
461 GtkCssValue **values,
462 GtkCssParser *parser)
464 GtkCssValue *value = NULL;
469 if (values[0] == NULL &&
470 (_gtk_css_parser_has_prefix (parser, "none") ||
471 _gtk_css_image_can_parse (parser)))
475 if (_gtk_css_parser_try (parser, "none", TRUE))
479 image = _gtk_css_image_new_parse (parser);
484 values[0] = _gtk_css_image_value_new (image);
486 else if (values[1] == NULL &&
487 (value = _gtk_css_position_value_try_parse (parser)))
492 if (_gtk_css_parser_try (parser, "/", TRUE) &&
493 (value = _gtk_css_bg_size_value_parse (parser)))
499 else if (values[3] == NULL &&
500 (value = _gtk_css_background_repeat_value_try_parse (parser)))
505 else if ((values[4] == NULL || values[5] == NULL) &&
506 (value = _gtk_css_area_value_try_parse (parser)))
510 if (values[5] == NULL)
512 values[5] = values[4];
517 else if (values[6] == NULL)
519 value = _gtk_css_color_value_parse (parser);
521 values[6] = _gtk_css_value_ref (_gtk_css_style_property_get_initial_value
522 (_gtk_css_shorthand_property_get_subproperty (shorthand, 6)));
530 /* We parsed everything and there's still stuff left?
531 * Pretend we didn't notice and let the normal code produce
532 * a 'junk at end of value' error */
536 while (!value_is_done_parsing (parser));
538 if (values[5] != NULL && values[4] == NULL)
539 values[4] = _gtk_css_value_ref (values[5]);
545 parse_background (GtkCssShorthandProperty *shorthand,
546 GtkCssValue **values,
547 GtkCssParser *parser)
549 GtkCssValue *step_values[7];
550 GPtrArray *arrays[6];
553 for (i = 0; i < 6; i++)
555 arrays[i] = g_ptr_array_new ();
556 step_values[i] = NULL;
559 step_values[6] = NULL;
562 if (!parse_one_background (shorthand, step_values, parser))
564 for (i = 0; i < 6; i++)
566 g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
567 g_ptr_array_unref (arrays[i]);
572 for (i = 0; i < 6; i++)
574 if (step_values[i] == NULL)
576 GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
577 _gtk_css_shorthand_property_get_subproperty (shorthand, i));
578 step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
581 g_ptr_array_add (arrays[i], step_values[i]);
582 step_values[i] = NULL;
584 } while (_gtk_css_parser_try (parser, ",", TRUE));
586 for (i = 0; i < 6; i++)
588 values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
589 g_ptr_array_unref (arrays[i]);
592 values[6] = step_values[6];
598 parse_one_transition (GtkCssShorthandProperty *shorthand,
599 GtkCssValue **values,
600 GtkCssParser *parser)
605 if (values[2] == NULL &&
606 _gtk_css_parser_has_number (parser) && !_gtk_css_parser_begins_with (parser, '-'))
608 GtkCssValue *number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME);
613 if (values[1] == NULL)
618 else if (values[3] == NULL &&
619 _gtk_css_ease_value_can_parse (parser))
621 values[3] = _gtk_css_ease_value_parse (parser);
623 if (values[3] == NULL)
626 else if (values[0] == NULL)
628 values[0] = _gtk_css_ident_value_try_parse (parser);
629 if (values[0] == NULL)
631 _gtk_css_parser_error (parser, "Unknown value for property");
638 /* We parsed everything and there's still stuff left?
639 * Pretend we didn't notice and let the normal code produce
640 * a 'junk at end of value' error */
644 while (!value_is_done_parsing (parser));
650 parse_transition (GtkCssShorthandProperty *shorthand,
651 GtkCssValue **values,
652 GtkCssParser *parser)
654 GtkCssValue *step_values[4];
655 GPtrArray *arrays[4];
658 for (i = 0; i < 4; i++)
660 arrays[i] = g_ptr_array_new ();
661 step_values[i] = NULL;
665 if (!parse_one_transition (shorthand, step_values, parser))
667 for (i = 0; i < 4; i++)
669 g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
670 g_ptr_array_unref (arrays[i]);
675 for (i = 0; i < 4; i++)
677 if (step_values[i] == NULL)
679 GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
680 _gtk_css_shorthand_property_get_subproperty (shorthand, i));
681 step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
684 g_ptr_array_add (arrays[i], step_values[i]);
685 step_values[i] = NULL;
687 } while (_gtk_css_parser_try (parser, ",", TRUE));
689 for (i = 0; i < 4; i++)
691 values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
692 g_ptr_array_unref (arrays[i]);
699 parse_one_animation (GtkCssShorthandProperty *shorthand,
700 GtkCssValue **values,
701 GtkCssParser *parser)
705 if (values[1] == NULL && _gtk_css_parser_try (parser, "infinite", TRUE))
707 values[1] = _gtk_css_number_value_new (HUGE_VAL, GTK_CSS_NUMBER);
709 else if ((values[1] == NULL || values[3] == NULL) &&
710 _gtk_css_parser_has_number (parser))
714 value = _gtk_css_number_value_parse (parser,
715 GTK_CSS_POSITIVE_ONLY
716 | (values[1] == NULL ? GTK_CSS_PARSE_NUMBER : 0)
717 | (values[3] == NULL ? GTK_CSS_PARSE_TIME : 0));
718 if (_gtk_css_number_value_get_unit (value) == GTK_CSS_NUMBER)
720 else if (values[2] == NULL)
725 else if (values[4] == NULL &&
726 _gtk_css_ease_value_can_parse (parser))
728 values[4] = _gtk_css_ease_value_parse (parser);
730 if (values[4] == NULL)
733 else if (values[5] == NULL &&
734 (values[5] = _gtk_css_direction_value_try_parse (parser)))
738 else if (values[6] == NULL &&
739 (values[6] = _gtk_css_fill_mode_value_try_parse (parser)))
743 else if (values[0] == NULL &&
744 (values[0] = _gtk_css_ident_value_try_parse (parser)))
747 /* keep in mind though that this needs to come last as fill modes, directions
748 * etc are valid idents */
752 /* We parsed everything and there's still stuff left?
753 * Pretend we didn't notice and let the normal code produce
754 * a 'junk at end of value' error */
758 while (!value_is_done_parsing (parser));
764 parse_animation (GtkCssShorthandProperty *shorthand,
765 GtkCssValue **values,
766 GtkCssParser *parser)
768 GtkCssValue *step_values[7];
769 GPtrArray *arrays[6];
772 for (i = 0; i < 6; i++)
774 arrays[i] = g_ptr_array_new ();
775 step_values[i] = NULL;
778 step_values[6] = NULL;
781 if (!parse_one_animation (shorthand, step_values, parser))
783 for (i = 0; i < 6; i++)
785 g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
786 g_ptr_array_unref (arrays[i]);
791 for (i = 0; i < 6; i++)
793 if (step_values[i] == NULL)
795 GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
796 _gtk_css_shorthand_property_get_subproperty (shorthand, i));
797 step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
800 g_ptr_array_add (arrays[i], step_values[i]);
801 step_values[i] = NULL;
803 } while (_gtk_css_parser_try (parser, ",", TRUE));
805 for (i = 0; i < 6; i++)
807 values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
808 g_ptr_array_unref (arrays[i]);
811 values[6] = step_values[6];
819 unpack_border (GtkCssShorthandProperty *shorthand,
820 GtkStyleProperties *props,
824 GValue v = G_VALUE_INIT;
825 GtkBorder *border = g_value_get_boxed (value);
827 g_value_init (&v, G_TYPE_INT);
829 g_value_set_int (&v, border->top);
830 _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)), props, state, &v);
831 g_value_set_int (&v, border->right);
832 _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)), props, state, &v);
833 g_value_set_int (&v, border->bottom);
834 _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)), props, state, &v);
835 g_value_set_int (&v, border->left);
836 _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)), props, state, &v);
842 pack_border (GtkCssShorthandProperty *shorthand,
844 GtkStyleQueryFunc query_func,
847 GtkCssStyleProperty *prop;
851 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
852 _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
853 border.top = g_value_get_int (&v);
856 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
857 _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
858 border.right = g_value_get_int (&v);
861 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
862 _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
863 border.bottom = g_value_get_int (&v);
866 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
867 _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
868 border.left = g_value_get_int (&v);
871 g_value_init (value, GTK_TYPE_BORDER);
872 g_value_set_boxed (value, &border);
876 unpack_border_radius (GtkCssShorthandProperty *shorthand,
877 GtkStyleProperties *props,
881 GtkCssValue *css_value;
884 css_value = _gtk_css_corner_value_new (_gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX),
885 _gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX));
887 for (i = 0; i < 4; i++)
888 _gtk_style_properties_set_property_by_property (props,
889 _gtk_css_shorthand_property_get_subproperty (shorthand, i),
893 _gtk_css_value_unref (css_value);
897 pack_border_radius (GtkCssShorthandProperty *shorthand,
899 GtkStyleQueryFunc query_func,
902 GtkCssStyleProperty *prop;
906 prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
907 v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
909 i = _gtk_css_corner_value_get_x (v, 100);
911 g_value_init (value, G_TYPE_INT);
912 g_value_set_int (value, i);
916 unpack_font_description (GtkCssShorthandProperty *shorthand,
917 GtkStyleProperties *props,
921 GtkStyleProperty *prop;
922 PangoFontDescription *description;
924 GValue v = G_VALUE_INIT;
926 /* For backwards compat, we only unpack values that are indeed set.
927 * For strict CSS conformance we need to unpack all of them.
928 * Note that we do set all of them in the parse function, so it
929 * will not have effects when parsing CSS files. It will though
930 * for custom style providers.
933 description = g_value_get_boxed (value);
936 mask = pango_font_description_get_set_fields (description);
940 if (mask & PANGO_FONT_MASK_FAMILY)
942 GPtrArray *strv = g_ptr_array_new ();
944 g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
945 g_ptr_array_add (strv, NULL);
946 g_value_init (&v, G_TYPE_STRV);
947 g_value_take_boxed (&v, g_ptr_array_free (strv, FALSE));
949 prop = _gtk_style_property_lookup ("font-family");
950 _gtk_style_property_assign (prop, props, state, &v);
954 if (mask & PANGO_FONT_MASK_STYLE)
956 g_value_init (&v, PANGO_TYPE_STYLE);
957 g_value_set_enum (&v, pango_font_description_get_style (description));
959 prop = _gtk_style_property_lookup ("font-style");
960 _gtk_style_property_assign (prop, props, state, &v);
964 if (mask & PANGO_FONT_MASK_VARIANT)
966 g_value_init (&v, PANGO_TYPE_VARIANT);
967 g_value_set_enum (&v, pango_font_description_get_variant (description));
969 prop = _gtk_style_property_lookup ("font-variant");
970 _gtk_style_property_assign (prop, props, state, &v);
974 if (mask & PANGO_FONT_MASK_WEIGHT)
976 g_value_init (&v, PANGO_TYPE_WEIGHT);
977 g_value_set_enum (&v, pango_font_description_get_weight (description));
979 prop = _gtk_style_property_lookup ("font-weight");
980 _gtk_style_property_assign (prop, props, state, &v);
984 if (mask & PANGO_FONT_MASK_SIZE)
986 g_value_init (&v, G_TYPE_DOUBLE);
987 g_value_set_double (&v, (double) pango_font_description_get_size (description) / PANGO_SCALE);
989 prop = _gtk_style_property_lookup ("font-size");
990 _gtk_style_property_assign (prop, props, state, &v);
996 pack_font_description (GtkCssShorthandProperty *shorthand,
998 GtkStyleQueryFunc query_func,
1001 PangoFontDescription *description;
1004 description = pango_font_description_new ();
1006 v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
1009 /* xxx: Can we set all the families here somehow? */
1010 pango_font_description_set_family (description, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, 0)));
1013 v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
1015 pango_font_description_set_size (description, round (_gtk_css_number_value_get (v, 100) * PANGO_SCALE));
1017 v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
1019 pango_font_description_set_style (description, _gtk_css_font_style_value_get (v));
1021 v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
1023 pango_font_description_set_variant (description, _gtk_css_font_variant_value_get (v));
1025 v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
1027 pango_font_description_set_weight (description, _gtk_css_font_weight_value_get (v));
1029 g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
1030 g_value_take_boxed (value, description);
1034 unpack_to_everything (GtkCssShorthandProperty *shorthand,
1035 GtkStyleProperties *props,
1036 GtkStateFlags state,
1037 const GValue *value)
1039 GtkCssStyleProperty *prop;
1042 n = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
1044 for (i = 0; i < n; i++)
1046 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
1047 _gtk_style_property_assign (GTK_STYLE_PROPERTY (prop), props, state, value);
1052 pack_first_element (GtkCssShorthandProperty *shorthand,
1054 GtkStyleQueryFunc query_func,
1055 gpointer query_data)
1057 GtkCssStyleProperty *prop;
1059 /* NB: This is a fallback for properties that originally were
1060 * not used as shorthand. We just pick the first subproperty
1061 * as a representative.
1062 * Lesson learned: Don't query the shorthand, query the
1063 * real properties instead. */
1064 prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
1065 _gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
1072 _gtk_css_shorthand_property_register (const char *name,
1074 const char **subproperties,
1075 GtkCssShorthandPropertyParseFunc parse_func,
1076 GtkCssShorthandPropertyAssignFunc assign_func,
1077 GtkCssShorthandPropertyQueryFunc query_func)
1079 GtkCssShorthandProperty *node;
1081 node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
1083 "value-type", value_type,
1084 "subproperties", subproperties,
1087 node->parse = parse_func;
1088 node->assign = assign_func;
1089 node->query = query_func;
1093 _gtk_css_shorthand_property_init_properties (void)
1095 /* The order is important here, be careful when changing it */
1096 const char *font_subproperties[] = { "font-family", "font-style", "font-variant", "font-weight", "font-size", NULL };
1097 const char *margin_subproperties[] = { "margin-top", "margin-right", "margin-bottom", "margin-left", NULL };
1098 const char *padding_subproperties[] = { "padding-top", "padding-right", "padding-bottom", "padding-left", NULL };
1099 const char *border_width_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", NULL };
1100 const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
1101 "border-bottom-right-radius", "border-bottom-left-radius", NULL };
1102 const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
1103 const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
1104 const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
1105 const char *border_top_subproperties[] = { "border-top-width", "border-top-style", "border-top-color", NULL };
1106 const char *border_right_subproperties[] = { "border-right-width", "border-right-style", "border-right-color", NULL };
1107 const char *border_bottom_subproperties[] = { "border-bottom-width", "border-bottom-style", "border-bottom-color", NULL };
1108 const char *border_left_subproperties[] = { "border-left-width", "border-left-style", "border-left-color", NULL };
1109 const char *border_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width",
1110 "border-top-style", "border-right-style", "border-bottom-style", "border-left-style",
1111 "border-top-color", "border-right-color", "border-bottom-color", "border-left-color",
1112 "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
1113 const char *outline_subproperties[] = { "outline-width", "outline-style", "outline-color", NULL };
1114 const char *background_subproperties[] = { "background-image", "background-position", "background-size", "background-repeat", "background-clip", "background-origin",
1115 "background-color", NULL };
1116 const char *transition_subproperties[] = { "transition-property", "transition-duration", "transition-delay", "transition-timing-function", NULL };
1117 const char *animation_subproperties[] = { "animation-name", "animation-iteration-count", "animation-duration", "animation-delay",
1118 "animation-timing-function", "animation-direction", "animation-fill-mode", NULL };
1120 _gtk_css_shorthand_property_register ("font",
1121 PANGO_TYPE_FONT_DESCRIPTION,
1124 unpack_font_description,
1125 pack_font_description);
1126 _gtk_css_shorthand_property_register ("margin",
1128 margin_subproperties,
1132 _gtk_css_shorthand_property_register ("padding",
1134 padding_subproperties,
1138 _gtk_css_shorthand_property_register ("border-width",
1140 border_width_subproperties,
1144 _gtk_css_shorthand_property_register ("border-radius",
1146 border_radius_subproperties,
1147 parse_border_radius,
1148 unpack_border_radius,
1149 pack_border_radius);
1150 _gtk_css_shorthand_property_register ("border-color",
1152 border_color_subproperties,
1154 unpack_to_everything,
1155 pack_first_element);
1156 _gtk_css_shorthand_property_register ("border-style",
1157 GTK_TYPE_BORDER_STYLE,
1158 border_style_subproperties,
1160 unpack_to_everything,
1161 pack_first_element);
1162 _gtk_css_shorthand_property_register ("border-image",
1164 border_image_subproperties,
1168 _gtk_css_shorthand_property_register ("border-top",
1170 border_top_subproperties,
1174 _gtk_css_shorthand_property_register ("border-right",
1176 border_right_subproperties,
1180 _gtk_css_shorthand_property_register ("border-bottom",
1182 border_bottom_subproperties,
1186 _gtk_css_shorthand_property_register ("border-left",
1188 border_left_subproperties,
1192 _gtk_css_shorthand_property_register ("border",
1194 border_subproperties,
1198 _gtk_css_shorthand_property_register ("outline",
1200 outline_subproperties,
1204 _gtk_css_shorthand_property_register ("background",
1206 background_subproperties,
1210 _gtk_css_shorthand_property_register ("transition",
1212 transition_subproperties,
1216 _gtk_css_shorthand_property_register ("animation",
1218 animation_subproperties,