]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssstylepropertyimpl.c
7315b9d90ed2473e1a2adc09d329b0bd67444c35
[~andy/gtk] / gtk / gtkcssstylepropertyimpl.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include "config.h"
19
20 #include "gtkstylepropertyprivate.h"
21
22 #include <gobject/gvaluecollector.h>
23 #include <gdk-pixbuf/gdk-pixbuf.h>
24 #include <cairo-gobject.h>
25 #include <math.h>
26
27 #include "gtkcssparserprivate.h"
28 #include "gtkcssstylefuncsprivate.h"
29 #include "gtkcssstylepropertyprivate.h"
30 #include "gtkcsstypesprivate.h"
31 #include "gtkintl.h"
32 #include "gtkprivatetypebuiltins.h"
33 #include "gtkstylepropertiesprivate.h"
34
35 /* this is in case round() is not provided by the compiler, 
36  * such as in the case of C89 compilers, like MSVC
37  */
38 #include "fallback-c89.c"
39
40 /* the actual parsers we have */
41 #include "gtkanimationdescription.h"
42 #include "gtkbindings.h"
43 #include "gtkcssimageprivate.h"
44 #include "gtkgradient.h"
45 #include "gtkshadowprivate.h"
46 #include "gtksymboliccolorprivate.h"
47 #include "gtkthemingengine.h"
48 #include "gtktypebuiltins.h"
49 #include "gtkwin32themeprivate.h"
50
51 /*** REGISTRATION ***/
52
53 static void
54 gtk_css_style_property_register (const char *                   name,
55                                  GType                          specified_type,
56                                  GType                          computed_type,
57                                  GType                          value_type,
58                                  GtkStylePropertyFlags          flags,
59                                  GtkCssStylePropertyParseFunc   parse_value,
60                                  GtkCssStylePropertyPrintFunc   print_value,
61                                  GtkCssStylePropertyComputeFunc compute_value,
62                                  GtkCssStylePropertyEqualFunc   equal_func,
63                                  GtkCssValue *                  initial_value)
64 {
65   GtkCssStyleProperty *node;
66
67   g_assert (initial_value != NULL);
68
69   node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
70                        "value-type", value_type,
71                        "computed-type", computed_type,
72                        "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE,
73                        "initial-value", initial_value,
74                        "name", name,
75                        NULL);
76   
77   if (parse_value)
78     node->parse_value = parse_value;
79   if (print_value)
80     node->print_value = print_value;
81   if (compute_value)
82     node->compute_value = compute_value;
83   if (equal_func)
84     node->equal_func = equal_func;
85
86   _gtk_css_value_unref (initial_value);
87 }
88
89 /*** HELPERS ***/
90
91 static void
92 string_append_string (GString    *str,
93                       const char *string)
94 {
95   gsize len;
96
97   g_string_append_c (str, '"');
98
99   do {
100     len = strcspn (string, "\"\n\r\f");
101     g_string_append (str, string);
102     string += len;
103     switch (*string)
104       {
105       case '\0':
106         break;
107       case '\n':
108         g_string_append (str, "\\A ");
109         break;
110       case '\r':
111         g_string_append (str, "\\D ");
112         break;
113       case '\f':
114         g_string_append (str, "\\C ");
115         break;
116       case '\"':
117         g_string_append (str, "\\\"");
118         break;
119       default:
120         g_assert_not_reached ();
121         break;
122       }
123   } while (*string);
124
125   g_string_append_c (str, '"');
126 }
127
128 /*** IMPLEMENTATIONS ***/
129
130 static GtkCssValue *
131 color_parse (GtkCssStyleProperty *property,
132              GtkCssParser        *parser,
133              GFile               *base)
134 {
135   GtkSymbolicColor *symbolic;
136
137   if (_gtk_css_parser_try (parser, "currentcolor", TRUE))
138     {
139       symbolic = gtk_symbolic_color_ref (_gtk_symbolic_color_get_current_color ());
140     }
141   else
142     {
143       symbolic = _gtk_css_parser_read_symbolic_color (parser);
144       if (symbolic == NULL)
145         return NULL;
146     }
147
148   return _gtk_css_value_new_take_symbolic_color (symbolic);
149 }
150
151 static GtkCssValue *
152 color_compute (GtkCssStyleProperty    *property,
153                GtkStyleContext        *context,
154                GtkCssValue            *specified)
155 {
156   GtkSymbolicColor *symbolic = _gtk_css_value_get_symbolic_color (specified);
157   GtkCssValue *resolved;
158
159   if (symbolic == _gtk_symbolic_color_get_current_color ())
160     {
161       /* The computed value of the ‘currentColor’ keyword is the computed
162        * value of the ‘color’ property. If the ‘currentColor’ keyword is
163        * set on the ‘color’ property itself, it is treated as ‘color: inherit’. 
164        */
165       if (g_str_equal (_gtk_style_property_get_name (GTK_STYLE_PROPERTY (property)), "color"))
166         {
167           GtkStyleContext *parent = gtk_style_context_get_parent (context);
168
169           if (parent)
170             return _gtk_css_value_ref (_gtk_style_context_peek_property (parent, "color"));
171           else
172             return _gtk_css_style_compute_value (context,
173                                                  GDK_TYPE_RGBA,
174                                                  _gtk_css_style_property_get_initial_value (property));
175         }
176       else
177         {
178           return _gtk_css_value_ref (_gtk_style_context_peek_property (context, "color"));
179         }
180     }
181   else if ((resolved = _gtk_style_context_resolve_color_value (context,
182                                                                symbolic)) != NULL)
183     {
184       return resolved;
185     }
186   else
187     {
188       return color_compute (property,
189                             context,
190                             _gtk_css_style_property_get_initial_value (property));
191     }
192 }
193
194 static GtkCssValue *
195 font_family_parse (GtkCssStyleProperty *property,
196                    GtkCssParser        *parser,
197                    GFile               *base)
198 {
199   GPtrArray *names;
200   char *name;
201
202   /* We don't special case generic families. Pango should do
203    * that for us */
204
205   names = g_ptr_array_new ();
206
207   do {
208     name = _gtk_css_parser_try_ident (parser, TRUE);
209     if (name)
210       {
211         GString *string = g_string_new (name);
212         g_free (name);
213         while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
214           {
215             g_string_append_c (string, ' ');
216             g_string_append (string, name);
217             g_free (name);
218           }
219         name = g_string_free (string, FALSE);
220       }
221     else 
222       {
223         name = _gtk_css_parser_read_string (parser);
224         if (name == NULL)
225           {
226             g_ptr_array_free (names, TRUE);
227             return FALSE;
228           }
229       }
230
231     g_ptr_array_add (names, name);
232   } while (_gtk_css_parser_try (parser, ",", TRUE));
233
234   /* NULL-terminate array */
235   g_ptr_array_add (names, NULL);
236   return _gtk_css_value_new_take_strv ((char **) g_ptr_array_free (names, FALSE));
237 }
238
239 static void
240 font_family_value_print (GtkCssStyleProperty *property,
241                          const GtkCssValue   *value,
242                          GString             *string)
243 {
244   const char **names = _gtk_css_value_get_strv (value);
245
246   if (names == NULL || *names == NULL)
247     {
248       g_string_append (string, "none");
249       return;
250     }
251
252   string_append_string (string, *names);
253   names++;
254   while (*names)
255     {
256       g_string_append (string, ", ");
257       string_append_string (string, *names);
258       names++;
259     }
260 }
261
262 static GtkCssValue *
263 bindings_value_parse (GtkCssStyleProperty *property,
264                       GtkCssParser        *parser,
265                       GFile               *base)
266 {
267   GPtrArray *array;
268   GtkBindingSet *binding_set;
269   char *name;
270
271   array = g_ptr_array_new ();
272
273   do {
274       name = _gtk_css_parser_try_ident (parser, TRUE);
275       if (name == NULL)
276         {
277           _gtk_css_parser_error (parser, "Not a valid binding name");
278           g_ptr_array_free (array, TRUE);
279           return FALSE;
280         }
281
282       binding_set = gtk_binding_set_find (name);
283
284       if (!binding_set)
285         {
286           _gtk_css_parser_error (parser, "No binding set named '%s'", name);
287           g_free (name);
288           continue;
289         }
290
291       g_ptr_array_add (array, binding_set);
292       g_free (name);
293     }
294   while (_gtk_css_parser_try (parser, ",", TRUE));
295
296   return _gtk_css_value_new_take_binding_sets (array);
297 }
298
299 static void
300 bindings_value_print (GtkCssStyleProperty *property,
301                       const GtkCssValue   *value,
302                       GString             *string)
303 {
304   GPtrArray *array;
305   guint i;
306
307   array = _gtk_css_value_get_boxed (value);
308
309   for (i = 0; i < array->len; i++)
310     {
311       GtkBindingSet *binding_set = g_ptr_array_index (array, i);
312
313       if (i > 0)
314         g_string_append (string, ", ");
315       g_string_append (string, binding_set->set_name);
316     }
317 }
318
319 static GtkCssValue *
320 border_corner_radius_value_parse (GtkCssStyleProperty *property,
321                                   GtkCssParser        *parser,
322                                   GFile               *base)
323 {
324   GtkCssBorderCornerRadius corner;
325
326   if (!_gtk_css_parser_read_number (parser,
327                                     &corner.horizontal,
328                                     GTK_CSS_POSITIVE_ONLY
329                                     | GTK_CSS_PARSE_PERCENT
330                                     | GTK_CSS_NUMBER_AS_PIXELS
331                                     | GTK_CSS_PARSE_LENGTH))
332     return FALSE;
333
334   if (!_gtk_css_parser_has_number (parser))
335     corner.vertical = corner.horizontal;
336   else if (!_gtk_css_parser_read_number (parser,
337                                          &corner.vertical,
338                                          GTK_CSS_POSITIVE_ONLY
339                                          | GTK_CSS_PARSE_PERCENT
340                                          | GTK_CSS_NUMBER_AS_PIXELS
341                                          | GTK_CSS_PARSE_LENGTH))
342     return FALSE;
343
344   return _gtk_css_value_new_from_border_corner_radius (&corner);
345 }
346
347 static void
348 border_corner_radius_value_print (GtkCssStyleProperty *property,
349                                   const GtkCssValue   *value,
350                                   GString             *string)
351 {
352   const GtkCssBorderCornerRadius *corner;
353
354   corner = _gtk_css_value_get_border_corner_radius (value);
355
356   _gtk_css_number_print (&corner->horizontal, string);
357
358   if (!_gtk_css_number_equal (&corner->horizontal, &corner->vertical))
359     {
360       g_string_append_c (string, ' ');
361       _gtk_css_number_print (&corner->vertical, string);
362     }
363 }
364
365 static GtkCssValue *
366 css_image_value_parse (GtkCssStyleProperty *property,
367                        GtkCssParser        *parser,
368                        GFile               *base)
369 {
370   GtkCssImage *image;
371
372   if (_gtk_css_parser_try (parser, "none", TRUE))
373     image = NULL;
374   else
375     {
376       image = _gtk_css_image_new_parse (parser, base);
377       if (image == NULL)
378         return FALSE;
379     }
380
381   return _gtk_css_value_new_take_image (image);
382 }
383
384 static void
385 css_image_value_print (GtkCssStyleProperty *property,
386                        const GtkCssValue   *value,
387                        GString             *string)
388 {
389   GtkCssImage *image = _gtk_css_value_get_image (value);
390
391   if (image)
392     _gtk_css_image_print (image, string);
393   else
394     g_string_append (string, "none");
395 }
396
397 static GtkCssValue *
398 css_image_value_compute (GtkCssStyleProperty    *property,
399                          GtkStyleContext        *context,
400                          GtkCssValue            *specified)
401 {
402   GtkCssImage *image, *computed;
403   
404   image = _gtk_css_value_get_image (specified);
405
406   if (image == NULL)
407     return _gtk_css_value_ref (specified);
408
409   computed = _gtk_css_image_compute (image, context);
410
411   if (computed == image)
412     {
413       g_object_unref (computed);
414       return _gtk_css_value_ref (specified);
415     }
416
417   return _gtk_css_value_new_take_image (computed);
418 }
419
420 static GtkCssValue *
421 parse_margin (GtkCssStyleProperty *property,
422               GtkCssParser        *parser,
423               GFile               *base)
424 {
425   GtkCssNumber number;
426
427   if (!_gtk_css_parser_read_number (parser,
428                                     &number, 
429                                     GTK_CSS_NUMBER_AS_PIXELS
430                                     | GTK_CSS_PARSE_LENGTH))
431     return NULL;
432
433   return _gtk_css_value_new_from_number (&number);
434 }
435
436 static GtkCssValue *
437 compute_margin (GtkCssStyleProperty *property,
438                 GtkStyleContext     *context,
439                 GtkCssValue         *specified)
440 {
441   GtkCssNumber number;
442   
443   if (_gtk_css_number_compute (&number,
444                                _gtk_css_value_get_number (specified),
445                                context))
446     {
447       return _gtk_css_value_new_from_number (&number);
448     }
449   return  _gtk_css_value_ref (specified);
450 }
451
452 static GtkCssValue *
453 parse_padding (GtkCssStyleProperty *property,
454                GtkCssParser        *parser,
455                GFile               *base)
456 {
457   GtkCssNumber number;
458
459   if (!_gtk_css_parser_read_number (parser,
460                                     &number, 
461                                     GTK_CSS_POSITIVE_ONLY
462                                     | GTK_CSS_NUMBER_AS_PIXELS
463                                     | GTK_CSS_PARSE_LENGTH))
464     return NULL;
465
466   return _gtk_css_value_new_from_number (&number);
467 }
468
469 static GtkCssValue *
470 compute_padding (GtkCssStyleProperty *property,
471                  GtkStyleContext     *context,
472                  GtkCssValue         *specified)
473 {
474   GtkCssNumber number;
475
476   if (_gtk_css_number_compute (&number,
477                                _gtk_css_value_get_number (specified),
478                                context))
479     return _gtk_css_value_new_from_number (&number);
480   return _gtk_css_value_ref (specified);
481 }
482
483 static GtkCssValue *
484 parse_border_width (GtkCssStyleProperty *property,
485                     GtkCssParser        *parser,
486                     GFile               *base)
487 {
488   GtkCssNumber number;
489
490   if (!_gtk_css_parser_read_number (parser,
491                                     &number, 
492                                     GTK_CSS_POSITIVE_ONLY
493                                     | GTK_CSS_NUMBER_AS_PIXELS
494                                     | GTK_CSS_PARSE_LENGTH))
495     return FALSE;
496
497   return _gtk_css_value_new_from_number (&number);
498 }
499
500 static GtkCssValue *
501 compute_border_width (GtkCssStyleProperty    *property,
502                       GtkStyleContext        *context,
503                       GtkCssValue            *specified)
504 {
505   GtkCssStyleProperty *style;
506   GtkBorderStyle border_style;
507   GtkCssNumber number;
508   int value = 0;
509   
510   /* The -1 is magic that is only true because we register the style
511    * properties directly after the width properties.
512    */
513   style = _gtk_css_style_property_lookup_by_id (_gtk_css_style_property_get_id (property) - 1);
514   
515   border_style = _gtk_css_value_get_border_style (_gtk_style_context_peek_property (context, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (style))));
516
517   if (border_style == GTK_BORDER_STYLE_NONE ||
518       border_style == GTK_BORDER_STYLE_HIDDEN)
519     {
520       value = 0;
521     }
522   else
523     {
524       _gtk_css_number_compute (&number,
525                                _gtk_css_value_get_number (specified),
526                                context);
527       value = round (number.value);
528     }
529   return _gtk_css_value_new_from_int (value);
530 }
531
532 static GtkCssValue *
533 background_repeat_value_parse (GtkCssStyleProperty *property,
534                                GtkCssParser        *parser,
535                                GFile               *base)
536 {
537   int repeat, vertical;
538
539   if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &repeat))
540     {
541       _gtk_css_parser_error (parser, "Not a valid value");
542       return FALSE;
543     }
544
545   if (repeat <= GTK_CSS_BACKGROUND_REPEAT_MASK)
546     {
547       if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
548         {
549           if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
550             {
551               _gtk_css_parser_error (parser, "Not a valid 2nd value");
552               return FALSE;
553             }
554           else
555             repeat |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
556         }
557       else
558         repeat |= repeat << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
559     }
560
561   return _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT, repeat);
562 }
563
564 static void
565 background_repeat_value_print (GtkCssStyleProperty *property,
566                                const GtkCssValue   *value,
567                                GString             *string)
568 {
569   GEnumClass *enum_class;
570   GEnumValue *enum_value;
571   GtkCssBackgroundRepeat repeat;
572
573   repeat = _gtk_css_value_get_enum (value);
574   enum_class = g_type_class_ref (GTK_TYPE_CSS_BACKGROUND_REPEAT);
575   enum_value = g_enum_get_value (enum_class, repeat);
576
577   /* only triggers for 'repeat-x' and 'repeat-y' */
578   if (enum_value)
579     g_string_append (string, enum_value->value_nick);
580   else
581     {
582       enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_HORIZONTAL (repeat));
583       g_string_append (string, enum_value->value_nick);
584
585       if (GTK_CSS_BACKGROUND_HORIZONTAL (repeat) != GTK_CSS_BACKGROUND_VERTICAL (repeat))
586         {
587           enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_VERTICAL (repeat));
588           g_string_append (string, " ");
589           g_string_append (string, enum_value->value_nick);
590         }
591     }
592
593   g_type_class_unref (enum_class);
594 }
595
596 static GtkCssValue *
597 background_size_parse (GtkCssStyleProperty *property,
598                        GtkCssParser        *parser,
599                        GFile               *base)
600 {
601   GtkCssBackgroundSize size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE};
602
603   if (_gtk_css_parser_try (parser, "cover", TRUE))
604     size.cover = TRUE;
605   else if (_gtk_css_parser_try (parser, "contain", TRUE))
606     size.contain = TRUE;
607   else
608     {
609       if (_gtk_css_parser_try (parser, "auto", TRUE))
610         _gtk_css_number_init (&size.width, 0, GTK_CSS_PX);
611       else if (!_gtk_css_parser_read_number (parser,
612                                              &size.width,
613                                              GTK_CSS_POSITIVE_ONLY
614                                              | GTK_CSS_PARSE_PERCENT
615                                              | GTK_CSS_PARSE_LENGTH))
616         return NULL;
617
618       if (_gtk_css_parser_try (parser, "auto", TRUE))
619         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
620       else if (_gtk_css_parser_has_number (parser))
621         {
622           if (!_gtk_css_parser_read_number (parser,
623                                             &size.height,
624                                             GTK_CSS_POSITIVE_ONLY
625                                             | GTK_CSS_PARSE_PERCENT
626                                             | GTK_CSS_PARSE_LENGTH))
627             return NULL;
628         }
629       else
630         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
631     }
632
633   return _gtk_css_value_new_from_background_size (&size);
634 }
635
636 static void
637 background_size_print (GtkCssStyleProperty *property,
638                        const GtkCssValue   *value,
639                        GString             *string)
640 {
641   const GtkCssBackgroundSize *size = _gtk_css_value_get_background_size (value);
642
643   if (size->cover)
644     g_string_append (string, "cover");
645   else if (size->contain)
646     g_string_append (string, "contain");
647   else
648     {
649       if (size->width.value == 0)
650         g_string_append (string, "auto");
651       else
652         _gtk_css_number_print (&size->width, string);
653
654       if (size->height.value != 0)
655         {
656           g_string_append (string, " ");
657           _gtk_css_number_print (&size->height, string);
658         }
659     }
660 }
661
662 static GtkCssValue *
663 background_size_compute (GtkCssStyleProperty    *property,
664                          GtkStyleContext        *context,
665                          GtkCssValue            *specified)
666 {
667   const GtkCssBackgroundSize *ssize = _gtk_css_value_get_background_size (specified);
668   GtkCssBackgroundSize csize;
669   gboolean changed;
670
671   csize.cover = ssize->cover;
672   csize.contain = ssize->contain;
673   changed = _gtk_css_number_compute (&csize.width,
674                                      &ssize->width,
675                                      context);
676   changed |= _gtk_css_number_compute (&csize.height,
677                                       &ssize->height,
678                                       context);
679   if (changed)
680     return _gtk_css_value_new_from_background_size (&csize);
681   return _gtk_css_value_ref (specified);
682 }
683
684 static GtkCssValue *
685 background_position_parse (GtkCssStyleProperty *property,
686                            GtkCssParser        *parser,
687                            GFile               *base)
688 {
689   static const struct {
690     const char *name;
691     guint       percentage;
692     gboolean    horizontal;
693     gboolean    vertical;
694   } names[] = {
695     { "left",     0, TRUE,  FALSE },
696     { "right",  100, TRUE,  FALSE },
697     { "center",  50, TRUE,  TRUE  },
698     { "top",      0, FALSE, TRUE  },
699     { "bottom", 100, FALSE, TRUE  },
700     { NULL    ,   0, TRUE,  FALSE }, /* used for numbers */
701     { NULL    ,  50, TRUE,  TRUE  }  /* used for no value */
702   };
703   GtkCssBackgroundPosition pos;
704   GtkCssNumber *missing;
705   guint first, second;
706
707   for (first = 0; names[first].name != NULL; first++)
708     {
709       if (_gtk_css_parser_try (parser, names[first].name, TRUE))
710         {
711           if (names[first].horizontal)
712             {
713               _gtk_css_number_init (&pos.x, names[first].percentage, GTK_CSS_PERCENT);
714               missing = &pos.y;
715             }
716           else
717             {
718               _gtk_css_number_init (&pos.y, names[first].percentage, GTK_CSS_PERCENT);
719               missing = &pos.x;
720             }
721           break;
722         }
723     }
724   if (names[first].name == NULL)
725     {
726       missing = &pos.y;
727       if (!_gtk_css_parser_read_number (parser,
728                                         &pos.x,
729                                         GTK_CSS_PARSE_PERCENT
730                                         | GTK_CSS_PARSE_LENGTH))
731         return NULL;
732     }
733
734   for (second = 0; names[second].name != NULL; second++)
735     {
736       if (_gtk_css_parser_try (parser, names[second].name, TRUE))
737         {
738           _gtk_css_number_init (missing, names[second].percentage, GTK_CSS_PERCENT);
739           break;
740         }
741     }
742
743   if (names[second].name == NULL)
744     {
745       if (_gtk_css_parser_has_number (parser))
746         {
747           if (missing != &pos.y)
748             {
749               _gtk_css_parser_error (parser, "Invalid combination of values");
750               return NULL;
751             }
752           if (!_gtk_css_parser_read_number (parser,
753                                             missing,
754                                             GTK_CSS_PARSE_PERCENT
755                                             | GTK_CSS_PARSE_LENGTH))
756             return NULL;
757         }
758       else
759         {
760           second++;
761           _gtk_css_number_init (missing, 50, GTK_CSS_PERCENT);
762         }
763     }
764   else
765     {
766       if ((names[first].horizontal && !names[second].vertical) ||
767           (!names[first].horizontal && !names[second].horizontal))
768         {
769           _gtk_css_parser_error (parser, "Invalid combination of values");
770           return NULL;
771         }
772     }
773
774   return _gtk_css_value_new_from_background_position (&pos);
775 }
776
777 static void
778 background_position_print (GtkCssStyleProperty *property,
779                            const GtkCssValue   *value,
780                            GString             *string)
781 {
782   const GtkCssBackgroundPosition *pos = _gtk_css_value_get_background_position (value);
783   static const GtkCssNumber center = GTK_CSS_NUMBER_INIT (50, GTK_CSS_PERCENT);
784   static const struct {
785     const char *x_name;
786     const char *y_name;
787     GtkCssNumber number;
788   } values[] = { 
789     { "left",   "top",    GTK_CSS_NUMBER_INIT (0,   GTK_CSS_PERCENT) },
790     { "right",  "bottom", GTK_CSS_NUMBER_INIT (100, GTK_CSS_PERCENT) }
791   };
792   guint i;
793
794   if (_gtk_css_number_equal (&pos->x, &center))
795     {
796       if (_gtk_css_number_equal (&pos->y, &center))
797         {
798           g_string_append (string, "center");
799           return;
800         }
801     }
802   else
803     {
804       for (i = 0; i < G_N_ELEMENTS (values); i++)
805         {
806           if (_gtk_css_number_equal (&pos->x, &values[i].number))
807             {
808               g_string_append (string, values[i].x_name);
809               break;
810             }
811         }
812       if (i == G_N_ELEMENTS (values))
813         _gtk_css_number_print (&pos->x, string);
814
815       if (_gtk_css_number_equal (&pos->y, &center))
816         return;
817
818       g_string_append_c (string, ' ');
819     }
820
821   for (i = 0; i < G_N_ELEMENTS (values); i++)
822     {
823       if (_gtk_css_number_equal (&pos->y, &values[i].number))
824         {
825           g_string_append (string, values[i].y_name);
826           break;
827         }
828     }
829   if (i == G_N_ELEMENTS (values))
830     {
831       if (_gtk_css_number_equal (&pos->x, &center))
832         g_string_append (string, "center ");
833       _gtk_css_number_print (&pos->y, string);
834     }
835 }
836
837 static GtkCssValue *
838 background_position_compute (GtkCssStyleProperty    *property,
839                              GtkStyleContext        *context,
840                              GtkCssValue            *specified)
841 {
842   const GtkCssBackgroundPosition *spos = _gtk_css_value_get_background_position (specified);
843   GtkCssBackgroundPosition cpos;
844   gboolean changed;
845
846   changed = _gtk_css_number_compute (&cpos.x,
847                                      &spos->x,
848                                      context);
849   changed |= _gtk_css_number_compute (&cpos.y,
850                                       &spos->y,
851                                       context);
852   if (changed)
853     return _gtk_css_value_new_from_background_position (&cpos);
854   return _gtk_css_value_ref (specified);
855 }
856
857 /*** REGISTRATION ***/
858
859 static GtkSymbolicColor *
860 gtk_symbolic_color_new_rgba (double red,
861                              double green,
862                              double blue,
863                              double alpha)
864 {
865   GdkRGBA rgba = { red, green, blue, alpha };
866
867   return gtk_symbolic_color_new_literal (&rgba);
868 }
869
870 void
871 _gtk_css_style_property_init_properties (void)
872 {
873   char *default_font_family[] = { "Sans", NULL };
874   GtkCssNumber number;
875   GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
876   GtkCssBackgroundPosition default_background_position = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PERCENT)};
877   GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
878   GtkBorder border_of_ones = { 1, 1, 1, 1 };
879   GtkCssBorderImageRepeat border_image_repeat = { GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_STRETCH };
880
881   /* Initialize "color" and "font-size" first,
882    * so that when computing values later they are
883    * done first. That way, 'currentColor' and font
884    * sizes in em can be looked up properly */
885   gtk_css_style_property_register        ("color",
886                                           GTK_TYPE_SYMBOLIC_COLOR,
887                                           GDK_TYPE_RGBA,
888                                           GDK_TYPE_RGBA,
889                                           GTK_STYLE_PROPERTY_INHERIT,
890                                           color_parse,
891                                           NULL,
892                                           color_compute,
893                                           NULL,
894                                           _gtk_css_value_new_take_symbolic_color (
895                                             gtk_symbolic_color_new_rgba (1, 1, 1, 1)));
896   gtk_css_style_property_register        ("font-size",
897                                           G_TYPE_DOUBLE,
898                                           G_TYPE_DOUBLE,
899                                           G_TYPE_DOUBLE,
900                                           GTK_STYLE_PROPERTY_INHERIT,
901                                           NULL,
902                                           NULL,
903                                           NULL,
904                                           NULL,
905                                           _gtk_css_value_new_from_double (10.0));
906
907   /* properties that aren't referenced when computing values
908    * start here */
909   gtk_css_style_property_register        ("background-color",
910                                           GTK_TYPE_SYMBOLIC_COLOR,
911                                           GDK_TYPE_RGBA,
912                                           GDK_TYPE_RGBA,
913                                           0,
914                                           color_parse,
915                                           NULL,
916                                           color_compute,
917                                           NULL,
918                                           _gtk_css_value_new_take_symbolic_color (
919                                             gtk_symbolic_color_new_rgba (0, 0, 0, 0)));
920
921   gtk_css_style_property_register        ("font-family",
922                                           G_TYPE_STRV,
923                                           G_TYPE_STRV,
924                                           G_TYPE_STRV,
925                                           GTK_STYLE_PROPERTY_INHERIT,
926                                           font_family_parse,
927                                           font_family_value_print,
928                                           NULL,
929                                           NULL,
930                                           _gtk_css_value_new_take_strv (g_strdupv (default_font_family)));
931   gtk_css_style_property_register        ("font-style",
932                                           PANGO_TYPE_STYLE,
933                                           PANGO_TYPE_STYLE,
934                                           PANGO_TYPE_STYLE,
935                                           GTK_STYLE_PROPERTY_INHERIT,
936                                           NULL,
937                                           NULL,
938                                           NULL,
939                                           NULL,
940                                           _gtk_css_value_new_from_enum (PANGO_TYPE_STYLE,
941                                                                         PANGO_STYLE_NORMAL));
942   gtk_css_style_property_register        ("font-variant",
943                                           PANGO_TYPE_VARIANT,
944                                           PANGO_TYPE_VARIANT,
945                                           PANGO_TYPE_VARIANT,
946                                           GTK_STYLE_PROPERTY_INHERIT,
947                                           NULL,
948                                           NULL,
949                                           NULL,
950                                           NULL,
951                                           _gtk_css_value_new_from_enum (PANGO_TYPE_VARIANT,
952                                                                         PANGO_VARIANT_NORMAL));
953   /* xxx: need to parse this properly, ie parse the numbers */
954   gtk_css_style_property_register        ("font-weight",
955                                           PANGO_TYPE_WEIGHT,
956                                           PANGO_TYPE_WEIGHT,
957                                           PANGO_TYPE_WEIGHT,
958                                           GTK_STYLE_PROPERTY_INHERIT,
959                                           NULL,
960                                           NULL,
961                                           NULL,
962                                           NULL,
963                                           _gtk_css_value_new_from_enum (PANGO_TYPE_WEIGHT,
964                                                                         PANGO_WEIGHT_NORMAL));
965
966   gtk_css_style_property_register        ("text-shadow",
967                                           GTK_TYPE_SHADOW,
968                                           GTK_TYPE_SHADOW,
969                                           GTK_TYPE_SHADOW,
970                                           GTK_STYLE_PROPERTY_INHERIT,
971                                           NULL,
972                                           NULL,
973                                           NULL,
974                                           NULL,
975                                           _gtk_css_value_new_take_shadow (NULL));
976
977   gtk_css_style_property_register        ("icon-shadow",
978                                           GTK_TYPE_SHADOW,
979                                           GTK_TYPE_SHADOW,
980                                           GTK_TYPE_SHADOW,
981                                           GTK_STYLE_PROPERTY_INHERIT,
982                                           NULL,
983                                           NULL,
984                                           NULL,
985                                           NULL,
986                                           _gtk_css_value_new_take_shadow (NULL));
987
988   gtk_css_style_property_register        ("box-shadow",
989                                           GTK_TYPE_SHADOW,
990                                           GTK_TYPE_SHADOW,
991                                           GTK_TYPE_SHADOW,
992                                           0,
993                                           NULL,
994                                           NULL,
995                                           NULL,
996                                           NULL,
997                                           _gtk_css_value_new_take_shadow (NULL));
998
999   _gtk_css_number_init (&number, 0, GTK_CSS_PX);
1000   gtk_css_style_property_register        ("margin-top",
1001                                           GTK_TYPE_CSS_NUMBER,
1002                                           GTK_TYPE_CSS_NUMBER,
1003                                           G_TYPE_INT,
1004                                           0,
1005                                           parse_margin,
1006                                           NULL,
1007                                           compute_margin,
1008                                           NULL,
1009                                           _gtk_css_value_new_from_number (&number));
1010   gtk_css_style_property_register        ("margin-left",
1011                                           GTK_TYPE_CSS_NUMBER,
1012                                           GTK_TYPE_CSS_NUMBER,
1013                                           G_TYPE_INT,
1014                                           0,
1015                                           parse_margin,
1016                                           NULL,
1017                                           compute_margin,
1018                                           NULL,
1019                                           _gtk_css_value_new_from_number (&number));
1020   gtk_css_style_property_register        ("margin-bottom",
1021                                           GTK_TYPE_CSS_NUMBER,
1022                                           GTK_TYPE_CSS_NUMBER,
1023                                           G_TYPE_INT,
1024                                           0,
1025                                           parse_margin,
1026                                           NULL,
1027                                           compute_margin,
1028                                           NULL,
1029                                           _gtk_css_value_new_from_number (&number));
1030   gtk_css_style_property_register        ("margin-right",
1031                                           GTK_TYPE_CSS_NUMBER,
1032                                           GTK_TYPE_CSS_NUMBER,
1033                                           G_TYPE_INT,
1034                                           0,
1035                                           parse_margin,
1036                                           NULL,
1037                                           compute_margin,
1038                                           NULL,
1039                                           _gtk_css_value_new_from_number (&number));
1040   gtk_css_style_property_register        ("padding-top",
1041                                           GTK_TYPE_CSS_NUMBER,
1042                                           GTK_TYPE_CSS_NUMBER,
1043                                           G_TYPE_INT,
1044                                           0,
1045                                           parse_padding,
1046                                           NULL,
1047                                           compute_padding,
1048                                           NULL,
1049                                           _gtk_css_value_new_from_number (&number));
1050   gtk_css_style_property_register        ("padding-left",
1051                                           GTK_TYPE_CSS_NUMBER,
1052                                           GTK_TYPE_CSS_NUMBER,
1053                                           G_TYPE_INT,
1054                                           0,
1055                                           parse_padding,
1056                                           NULL,
1057                                           compute_padding,
1058                                           NULL,
1059                                           _gtk_css_value_new_from_number (&number));
1060   gtk_css_style_property_register        ("padding-bottom",
1061                                           GTK_TYPE_CSS_NUMBER,
1062                                           GTK_TYPE_CSS_NUMBER,
1063                                           G_TYPE_INT,
1064                                           0,
1065                                           parse_padding,
1066                                           NULL,
1067                                           compute_padding,
1068                                           NULL,
1069                                           _gtk_css_value_new_from_number (&number));
1070   gtk_css_style_property_register        ("padding-right",
1071                                           GTK_TYPE_CSS_NUMBER,
1072                                           GTK_TYPE_CSS_NUMBER,
1073                                           G_TYPE_INT,
1074                                           0,
1075                                           parse_padding,
1076                                           NULL,
1077                                           compute_padding,
1078                                           NULL,
1079                                           _gtk_css_value_new_from_number (&number));
1080   /* IMPORTANT: compute_border_width() requires that the border-width
1081    * properties be immeditaly followed by the border-style properties
1082    */
1083   gtk_css_style_property_register        ("border-top-style",
1084                                           GTK_TYPE_BORDER_STYLE,
1085                                           GTK_TYPE_BORDER_STYLE,
1086                                           GTK_TYPE_BORDER_STYLE,
1087                                           0,
1088                                           NULL,
1089                                           NULL,
1090                                           NULL,
1091                                           NULL,
1092                                           _gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
1093   gtk_css_style_property_register        ("border-top-width",
1094                                           GTK_TYPE_CSS_NUMBER,
1095                                           G_TYPE_INT,
1096                                           G_TYPE_INT,
1097                                           0,
1098                                           parse_border_width,
1099                                           NULL,
1100                                           compute_border_width,
1101                                           NULL,
1102                                           _gtk_css_value_new_from_number (&number));
1103   gtk_css_style_property_register        ("border-left-style",
1104                                           GTK_TYPE_BORDER_STYLE,
1105                                           GTK_TYPE_BORDER_STYLE,
1106                                           GTK_TYPE_BORDER_STYLE,
1107                                           0,
1108                                           NULL,
1109                                           NULL,
1110                                           NULL,
1111                                           NULL,
1112                                           _gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
1113   gtk_css_style_property_register        ("border-left-width",
1114                                           GTK_TYPE_CSS_NUMBER,
1115                                           G_TYPE_INT,
1116                                           G_TYPE_INT,
1117                                           0,
1118                                           parse_border_width,
1119                                           NULL,
1120                                           compute_border_width,
1121                                           NULL,
1122                                           _gtk_css_value_new_from_number (&number));
1123   gtk_css_style_property_register        ("border-bottom-style",
1124                                           GTK_TYPE_BORDER_STYLE,
1125                                           GTK_TYPE_BORDER_STYLE,
1126                                           GTK_TYPE_BORDER_STYLE,
1127                                           0,
1128                                           NULL,
1129                                           NULL,
1130                                           NULL,
1131                                           NULL,
1132                                           _gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
1133   gtk_css_style_property_register        ("border-bottom-width",
1134                                           GTK_TYPE_CSS_NUMBER,
1135                                           G_TYPE_INT,
1136                                           G_TYPE_INT,
1137                                           0,
1138                                           parse_border_width,
1139                                           NULL,
1140                                           compute_border_width,
1141                                           NULL,
1142                                           _gtk_css_value_new_from_number (&number));
1143   gtk_css_style_property_register        ("border-right-style",
1144                                           GTK_TYPE_BORDER_STYLE,
1145                                           GTK_TYPE_BORDER_STYLE,
1146                                           GTK_TYPE_BORDER_STYLE,
1147                                           0,
1148                                           NULL,
1149                                           NULL,
1150                                           NULL,
1151                                           NULL,
1152                                           _gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
1153   gtk_css_style_property_register        ("border-right-width",
1154                                           GTK_TYPE_CSS_NUMBER,
1155                                           G_TYPE_INT,
1156                                           G_TYPE_INT,
1157                                           0,
1158                                           parse_border_width,
1159                                           NULL,
1160                                           compute_border_width,
1161                                           NULL,
1162                                           _gtk_css_value_new_from_number (&number));
1163
1164   gtk_css_style_property_register        ("border-top-left-radius",
1165                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1166                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1167                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1168                                           0,
1169                                           border_corner_radius_value_parse,
1170                                           border_corner_radius_value_print,
1171                                           NULL,
1172                                           NULL,
1173                                           _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
1174   gtk_css_style_property_register        ("border-top-right-radius",
1175                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1176                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1177                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1178                                           0,
1179                                           border_corner_radius_value_parse,
1180                                           border_corner_radius_value_print,
1181                                           NULL,
1182                                           NULL,
1183                                           _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
1184   gtk_css_style_property_register        ("border-bottom-right-radius",
1185                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1186                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1187                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1188                                           0,
1189                                           border_corner_radius_value_parse,
1190                                           border_corner_radius_value_print,
1191                                           NULL,
1192                                           NULL,
1193                                           _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
1194   gtk_css_style_property_register        ("border-bottom-left-radius",
1195                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1196                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1197                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
1198                                           0,
1199                                           border_corner_radius_value_parse,
1200                                           border_corner_radius_value_print,
1201                                           NULL,
1202                                           NULL,
1203                                           _gtk_css_value_new_from_border_corner_radius (&no_corner_radius));
1204
1205   gtk_css_style_property_register        ("outline-style",
1206                                           GTK_TYPE_BORDER_STYLE,
1207                                           GTK_TYPE_BORDER_STYLE,
1208                                           GTK_TYPE_BORDER_STYLE,
1209                                           0,
1210                                           NULL,
1211                                           NULL,
1212                                           NULL,
1213                                           NULL,
1214                                           _gtk_css_value_new_from_border_style (GTK_BORDER_STYLE_NONE));
1215   gtk_css_style_property_register        ("outline-width",
1216                                           GTK_TYPE_CSS_NUMBER,
1217                                           G_TYPE_INT,
1218                                           G_TYPE_INT,
1219                                           0,
1220                                           parse_border_width,
1221                                           NULL,
1222                                           compute_border_width,
1223                                           NULL,
1224                                           _gtk_css_value_new_from_number (&number));
1225   gtk_css_style_property_register        ("outline-offset",
1226                                           G_TYPE_INT,
1227                                           G_TYPE_INT,
1228                                           G_TYPE_INT,
1229                                           0,
1230                                           NULL,
1231                                           NULL,
1232                                           NULL,
1233                                           NULL,
1234                                           _gtk_css_value_new_from_int (0));
1235
1236   gtk_css_style_property_register        ("background-clip",
1237                                           GTK_TYPE_CSS_AREA,
1238                                           GTK_TYPE_CSS_AREA,
1239                                           GTK_TYPE_CSS_AREA,
1240                                           0,
1241                                           NULL,
1242                                           NULL,
1243                                           NULL,
1244                                           NULL,
1245                                           _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_BORDER_BOX));
1246   gtk_css_style_property_register        ("background-origin",
1247                                           GTK_TYPE_CSS_AREA,
1248                                           GTK_TYPE_CSS_AREA,
1249                                           GTK_TYPE_CSS_AREA,
1250                                           0,
1251                                           NULL,
1252                                           NULL,
1253                                           NULL,
1254                                           NULL,
1255                                           _gtk_css_value_new_from_enum (GTK_TYPE_CSS_AREA, GTK_CSS_AREA_PADDING_BOX));
1256   gtk_css_style_property_register        ("background-size",
1257                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
1258                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
1259                                           G_TYPE_NONE,
1260                                           0,
1261                                           background_size_parse,
1262                                           background_size_print,
1263                                           background_size_compute,
1264                                           NULL,
1265                                           _gtk_css_value_new_from_background_size (&default_background_size));
1266   gtk_css_style_property_register        ("background-position",
1267                                           GTK_TYPE_CSS_BACKGROUND_POSITION,
1268                                           GTK_TYPE_CSS_BACKGROUND_POSITION,
1269                                           G_TYPE_NONE,
1270                                           0,
1271                                           background_position_parse,
1272                                           background_position_print,
1273                                           background_position_compute,
1274                                           NULL,
1275                                           _gtk_css_value_new_from_background_position (&default_background_position));
1276
1277   gtk_css_style_property_register        ("border-top-color",
1278                                           GTK_TYPE_SYMBOLIC_COLOR,
1279                                           GDK_TYPE_RGBA,
1280                                           GDK_TYPE_RGBA,
1281                                           0,
1282                                           color_parse,
1283                                           NULL,
1284                                           color_compute,
1285                                           NULL,
1286                                           _gtk_css_value_new_take_symbolic_color (
1287                                             gtk_symbolic_color_ref (
1288                                               _gtk_symbolic_color_get_current_color ())));
1289   gtk_css_style_property_register        ("border-right-color",
1290                                           GTK_TYPE_SYMBOLIC_COLOR,
1291                                           GDK_TYPE_RGBA,
1292                                           GDK_TYPE_RGBA,
1293                                           0,
1294                                           color_parse,
1295                                           NULL,
1296                                           color_compute,
1297                                           NULL,
1298                                           _gtk_css_value_new_take_symbolic_color (
1299                                             gtk_symbolic_color_ref (
1300                                               _gtk_symbolic_color_get_current_color ())));
1301   gtk_css_style_property_register        ("border-bottom-color",
1302                                           GTK_TYPE_SYMBOLIC_COLOR,
1303                                           GDK_TYPE_RGBA,
1304                                           GDK_TYPE_RGBA,
1305                                           0,
1306                                           color_parse,
1307                                           NULL,
1308                                           color_compute,
1309                                           NULL,
1310                                           _gtk_css_value_new_take_symbolic_color (
1311                                             gtk_symbolic_color_ref (
1312                                               _gtk_symbolic_color_get_current_color ())));
1313   gtk_css_style_property_register        ("border-left-color",
1314                                           GTK_TYPE_SYMBOLIC_COLOR,
1315                                           GDK_TYPE_RGBA,
1316                                           GDK_TYPE_RGBA,
1317                                           0,
1318                                           color_parse,
1319                                           NULL,
1320                                           color_compute,
1321                                           NULL,
1322                                           _gtk_css_value_new_take_symbolic_color (
1323                                             gtk_symbolic_color_ref (
1324                                               _gtk_symbolic_color_get_current_color ())));
1325   gtk_css_style_property_register        ("outline-color",
1326                                           GTK_TYPE_SYMBOLIC_COLOR,
1327                                           GDK_TYPE_RGBA,
1328                                           GDK_TYPE_RGBA,
1329                                           0,
1330                                           color_parse,
1331                                           NULL,
1332                                           color_compute,
1333                                           NULL,
1334                                           _gtk_css_value_new_take_symbolic_color (
1335                                             gtk_symbolic_color_ref (
1336                                               _gtk_symbolic_color_get_current_color ())));
1337
1338   gtk_css_style_property_register        ("background-repeat",
1339                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1340                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1341                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1342                                           0,
1343                                           background_repeat_value_parse,
1344                                           background_repeat_value_print,
1345                                           NULL,
1346                                           NULL,
1347                                           _gtk_css_value_new_from_enum (GTK_TYPE_CSS_BACKGROUND_REPEAT,
1348                                                                         GTK_CSS_BACKGROUND_REPEAT | 
1349                                                                         (GTK_CSS_BACKGROUND_REPEAT << GTK_CSS_BACKGROUND_REPEAT_SHIFT)));
1350   gtk_css_style_property_register        ("background-image",
1351                                           GTK_TYPE_CSS_IMAGE,
1352                                           GTK_TYPE_CSS_IMAGE,
1353                                           CAIRO_GOBJECT_TYPE_PATTERN,
1354                                           0,
1355                                           css_image_value_parse,
1356                                           css_image_value_print,
1357                                           css_image_value_compute,
1358                                           NULL,
1359                                           _gtk_css_value_new_take_image (NULL));
1360
1361   gtk_css_style_property_register        ("border-image-source",
1362                                           GTK_TYPE_CSS_IMAGE,
1363                                           GTK_TYPE_CSS_IMAGE,
1364                                           CAIRO_GOBJECT_TYPE_PATTERN,
1365                                           0,
1366                                           css_image_value_parse,
1367                                           css_image_value_print,
1368                                           css_image_value_compute,
1369                                           NULL,
1370                                           _gtk_css_value_new_take_image (NULL));
1371   gtk_css_style_property_register        ("border-image-repeat",
1372                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1373                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1374                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1375                                           0,
1376                                           NULL,
1377                                           NULL,
1378                                           NULL,
1379                                           NULL,
1380                                           _gtk_css_value_new_from_border_image_repeat (&border_image_repeat));
1381
1382   /* XXX: The initial value is wrong, it should be 100% */
1383   gtk_css_style_property_register        ("border-image-slice",
1384                                           GTK_TYPE_BORDER,
1385                                           GTK_TYPE_BORDER,
1386                                           GTK_TYPE_BORDER,
1387                                           0,
1388                                           NULL,
1389                                           NULL,
1390                                           NULL,
1391                                           NULL,
1392                                           _gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, &border_of_ones));
1393   gtk_css_style_property_register        ("border-image-width",
1394                                           GTK_TYPE_BORDER,
1395                                           GTK_TYPE_BORDER,
1396                                           GTK_TYPE_BORDER,
1397                                           0,
1398                                           NULL,
1399                                           NULL,
1400                                           NULL,
1401                                           NULL,
1402                                           _gtk_css_value_new_from_boxed (GTK_TYPE_BORDER, NULL));
1403   gtk_css_style_property_register        ("engine",
1404                                           GTK_TYPE_THEMING_ENGINE,
1405                                           GTK_TYPE_THEMING_ENGINE,
1406                                           GTK_TYPE_THEMING_ENGINE,
1407                                           0,
1408                                           NULL,
1409                                           NULL,
1410                                           NULL,
1411                                           NULL,
1412                                           _gtk_css_value_new_from_theming_engine (gtk_theming_engine_load (NULL)));
1413   gtk_css_style_property_register        ("transition",
1414                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1415                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1416                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1417                                           0,
1418                                           NULL,
1419                                           NULL,
1420                                           NULL,
1421                                           NULL,
1422                                           _gtk_css_value_new_from_boxed (GTK_TYPE_ANIMATION_DESCRIPTION, NULL));
1423
1424   /* Private property holding the binding sets */
1425   gtk_css_style_property_register        ("gtk-key-bindings",
1426                                           G_TYPE_PTR_ARRAY,
1427                                           G_TYPE_PTR_ARRAY,
1428                                           G_TYPE_PTR_ARRAY,
1429                                           0,
1430                                           bindings_value_parse,
1431                                           bindings_value_print,
1432                                           NULL,
1433                                           NULL,
1434                                           _gtk_css_value_new_take_binding_sets (NULL));
1435 }
1436