]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssstylepropertyimpl.c
css: Implement parsing for 'background-size'
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "gtkstylepropertyprivate.h"
23
24 #include <gobject/gvaluecollector.h>
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <cairo-gobject.h>
27 #include <math.h>
28
29 #include "gtkcssparserprivate.h"
30 #include "gtkcssstylefuncsprivate.h"
31 #include "gtkcssstylepropertyprivate.h"
32 #include "gtkcsstypesprivate.h"
33 #include "gtkintl.h"
34 #include "gtkprivatetypebuiltins.h"
35 #include "gtkstylepropertiesprivate.h"
36
37 /* this is in case round() is not provided by the compiler, 
38  * such as in the case of C89 compilers, like MSVC
39  */
40 #include "fallback-c89.c"
41
42 /* the actual parsers we have */
43 #include "gtkanimationdescription.h"
44 #include "gtkbindings.h"
45 #include "gtkcssimageprivate.h"
46 #include "gtkgradient.h"
47 #include "gtkshadowprivate.h"
48 #include "gtksymboliccolorprivate.h"
49 #include "gtkthemingengine.h"
50 #include "gtktypebuiltins.h"
51 #include "gtkwin32themeprivate.h"
52
53 /*** REGISTRATION ***/
54
55 static void
56 gtk_css_style_property_register (const char *                   name,
57                                  GType                          specified_type,
58                                  GType                          computed_type,
59                                  GType                          value_type,
60                                  GtkStylePropertyFlags          flags,
61                                  GtkCssStylePropertyParseFunc   parse_value,
62                                  GtkCssStylePropertyPrintFunc   print_value,
63                                  GtkCssStylePropertyComputeFunc compute_value,
64                                  ...)
65 {
66   GtkCssStyleProperty *node;
67   GValue initial_value = G_VALUE_INIT;
68   char *error = NULL;
69   va_list args;
70
71   va_start (args, compute_value);
72   G_VALUE_COLLECT_INIT (&initial_value, specified_type,
73                         args, 0, &error);
74   if (error)
75     {
76       g_error ("property `%s' initial value is broken: %s", name, error);
77       g_value_unset (&initial_value);
78       return;
79     }
80
81   va_end (args);
82
83   node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
84                        "value-type", value_type,
85                        "computed-type", computed_type,
86                        "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE,
87                        "initial-value", &initial_value,
88                        "name", name,
89                        NULL);
90   
91   if (parse_value)
92     node->parse_value = parse_value;
93   if (print_value)
94     node->print_value = print_value;
95   if (compute_value)
96     node->compute_value = compute_value;
97
98   g_value_unset (&initial_value);
99 }
100
101 /*** HELPERS ***/
102
103 static void
104 string_append_string (GString    *str,
105                       const char *string)
106 {
107   gsize len;
108
109   g_string_append_c (str, '"');
110
111   do {
112     len = strcspn (string, "\"\n\r\f");
113     g_string_append (str, string);
114     string += len;
115     switch (*string)
116       {
117       case '\0':
118         break;
119       case '\n':
120         g_string_append (str, "\\A ");
121         break;
122       case '\r':
123         g_string_append (str, "\\D ");
124         break;
125       case '\f':
126         g_string_append (str, "\\C ");
127         break;
128       case '\"':
129         g_string_append (str, "\\\"");
130         break;
131       default:
132         g_assert_not_reached ();
133         break;
134       }
135   } while (*string);
136
137   g_string_append_c (str, '"');
138 }
139
140 /*** IMPLEMENTATIONS ***/
141
142 static void
143 color_compute (GtkCssStyleProperty    *property,
144                GValue                 *computed,
145                GtkStyleContext        *context,
146                const GValue           *specified)
147 {
148   GtkSymbolicColor *symbolic = g_value_get_boxed (specified);
149   GdkRGBA rgba;
150
151   if (symbolic == _gtk_symbolic_color_get_current_color ())
152     {
153       /* The computed value of the ‘currentColor’ keyword is the computed
154        * value of the ‘color’ property. If the ‘currentColor’ keyword is
155        * set on the ‘color’ property itself, it is treated as ‘color: inherit’. 
156        */
157       if (g_str_equal (_gtk_style_property_get_name (GTK_STYLE_PROPERTY (property)), "color"))
158         {
159           GtkStyleContext *parent = gtk_style_context_get_parent (context);
160
161           if (parent)
162             g_value_copy (_gtk_style_context_peek_property (parent, "color"), computed);
163           else
164             _gtk_css_style_compute_value (computed,
165                                           context,
166                                           _gtk_css_style_property_get_initial_value (property));
167         }
168       else
169         {
170           g_value_copy (_gtk_style_context_peek_property (context, "color"), computed);
171         }
172     }
173   else if (_gtk_style_context_resolve_color (context,
174                                              symbolic,
175                                              &rgba))
176     {
177       g_value_set_boxed (computed, &rgba);
178     }
179   else
180     {
181       color_compute (property,
182                      computed,
183                      context,
184                      _gtk_css_style_property_get_initial_value (property));
185     }
186 }
187
188 static gboolean
189 font_family_parse (GtkCssStyleProperty *property,
190                    GValue              *value,
191                    GtkCssParser        *parser,
192                    GFile               *base)
193 {
194   GPtrArray *names;
195   char *name;
196
197   /* We don't special case generic families. Pango should do
198    * that for us */
199
200   names = g_ptr_array_new ();
201
202   do {
203     name = _gtk_css_parser_try_ident (parser, TRUE);
204     if (name)
205       {
206         GString *string = g_string_new (name);
207         g_free (name);
208         while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
209           {
210             g_string_append_c (string, ' ');
211             g_string_append (string, name);
212             g_free (name);
213           }
214         name = g_string_free (string, FALSE);
215       }
216     else 
217       {
218         name = _gtk_css_parser_read_string (parser);
219         if (name == NULL)
220           {
221             g_ptr_array_free (names, TRUE);
222             return FALSE;
223           }
224       }
225
226     g_ptr_array_add (names, name);
227   } while (_gtk_css_parser_try (parser, ",", TRUE));
228
229   /* NULL-terminate array */
230   g_ptr_array_add (names, NULL);
231   g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
232   return TRUE;
233 }
234
235 static void
236 font_family_value_print (GtkCssStyleProperty *property,
237                          const GValue        *value,
238                          GString             *string)
239 {
240   const char **names = g_value_get_boxed (value);
241
242   if (names == NULL || *names == NULL)
243     {
244       g_string_append (string, "none");
245       return;
246     }
247
248   string_append_string (string, *names);
249   names++;
250   while (*names)
251     {
252       g_string_append (string, ", ");
253       string_append_string (string, *names);
254       names++;
255     }
256 }
257
258 static gboolean 
259 bindings_value_parse (GtkCssStyleProperty *property,
260                       GValue              *value,
261                       GtkCssParser        *parser,
262                       GFile               *base)
263 {
264   GPtrArray *array;
265   GtkBindingSet *binding_set;
266   char *name;
267
268   array = g_ptr_array_new ();
269
270   do {
271       name = _gtk_css_parser_try_ident (parser, TRUE);
272       if (name == NULL)
273         {
274           _gtk_css_parser_error (parser, "Not a valid binding name");
275           g_ptr_array_free (array, TRUE);
276           return FALSE;
277         }
278
279       binding_set = gtk_binding_set_find (name);
280
281       if (!binding_set)
282         {
283           _gtk_css_parser_error (parser, "No binding set named '%s'", name);
284           g_free (name);
285           continue;
286         }
287
288       g_ptr_array_add (array, binding_set);
289       g_free (name);
290     }
291   while (_gtk_css_parser_try (parser, ",", TRUE));
292
293   g_value_take_boxed (value, array);
294
295   return TRUE;
296 }
297
298 static void
299 bindings_value_print (GtkCssStyleProperty *property,
300                       const GValue        *value,
301                       GString             *string)
302 {
303   GPtrArray *array;
304   guint i;
305
306   array = g_value_get_boxed (value);
307
308   for (i = 0; i < array->len; i++)
309     {
310       GtkBindingSet *binding_set = g_ptr_array_index (array, i);
311
312       if (i > 0)
313         g_string_append (string, ", ");
314       g_string_append (string, binding_set->set_name);
315     }
316 }
317
318 static gboolean 
319 border_corner_radius_value_parse (GtkCssStyleProperty *property,
320                                   GValue              *value,
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   g_value_set_boxed (value, &corner);
345   return TRUE;
346 }
347
348 static void
349 border_corner_radius_value_print (GtkCssStyleProperty *property,
350                                   const GValue        *value,
351                                   GString             *string)
352 {
353   GtkCssBorderCornerRadius *corner;
354
355   corner = g_value_get_boxed (value);
356
357   _gtk_css_number_print (&corner->horizontal, string);
358
359   if (!_gtk_css_number_equal (&corner->horizontal, &corner->vertical))
360     {
361       g_string_append_c (string, ' ');
362       _gtk_css_number_print (&corner->vertical, string);
363     }
364 }
365
366 static gboolean 
367 css_image_value_parse (GtkCssStyleProperty *property,
368                        GValue              *value,
369                        GtkCssParser        *parser,
370                        GFile               *base)
371 {
372   GtkCssImage *image;
373
374   if (_gtk_css_parser_try (parser, "none", TRUE))
375     image = NULL;
376   else
377     {
378       image = _gtk_css_image_new_parse (parser, base);
379       if (image == NULL)
380         return FALSE;
381     }
382
383   g_value_take_object (value, image);
384   return TRUE;
385 }
386
387 static void
388 css_image_value_print (GtkCssStyleProperty *property,
389                        const GValue        *value,
390                        GString             *string)
391 {
392   GtkCssImage *image = g_value_get_object (value);
393
394   if (image)
395     _gtk_css_image_print (image, string);
396   else
397     g_string_append (string, "none");
398 }
399
400 static void
401 css_image_value_compute (GtkCssStyleProperty    *property,
402                          GValue                 *computed,
403                          GtkStyleContext        *context,
404                          const GValue           *specified)
405 {
406   GtkCssImage *image = g_value_get_object (specified);
407
408   if (image)
409     image = _gtk_css_image_compute (image, context);
410
411   g_value_take_object (computed, image);
412 }
413
414 static gboolean 
415 parse_border_width (GtkCssStyleProperty *property,
416                     GValue              *value,
417                     GtkCssParser        *parser,
418                     GFile               *base)
419 {
420   GtkCssNumber number;
421
422   if (!_gtk_css_parser_read_number (parser,
423                                     &number, 
424                                     GTK_CSS_POSITIVE_ONLY
425                                     | GTK_CSS_NUMBER_AS_PIXELS
426                                     | GTK_CSS_PARSE_LENGTH))
427     return FALSE;
428
429   g_value_set_boxed (value, &number);
430   return TRUE;
431 }
432
433 static void
434 compute_border_width (GtkCssStyleProperty    *property,
435                       GValue                 *computed,
436                       GtkStyleContext        *context,
437                       const GValue           *specified)
438 {
439   GtkCssStyleProperty *style;
440   GtkBorderStyle border_style;
441   GtkCssNumber number;
442   
443   /* The -1 is magic that is only true because we register the style
444    * properties directly after the width properties.
445    */
446   style = _gtk_css_style_property_lookup_by_id (_gtk_css_style_property_get_id (property) - 1);
447   border_style = g_value_get_enum (_gtk_style_context_peek_property (context, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (style))));
448
449   if (border_style == GTK_BORDER_STYLE_NONE ||
450       border_style == GTK_BORDER_STYLE_HIDDEN)
451     {
452       g_value_set_int (computed, 0);
453       return;
454     }
455
456   _gtk_css_number_compute (&number,
457                            g_value_get_boxed (specified),
458                            context);
459   g_value_set_int (computed, round (number.value));
460 }
461
462 static gboolean
463 background_repeat_value_parse (GtkCssStyleProperty *property,
464                                GValue              *value,
465                                GtkCssParser        *parser,
466                                GFile               *base)
467 {
468   int repeat, vertical;
469
470   if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &repeat))
471     {
472       _gtk_css_parser_error (parser, "Not a valid value");
473       return FALSE;
474     }
475
476   if (repeat <= GTK_CSS_BACKGROUND_REPEAT_MASK)
477     {
478       if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
479         {
480           if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
481             {
482               _gtk_css_parser_error (parser, "Not a valid 2nd value");
483               return FALSE;
484             }
485           else
486             repeat |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
487         }
488       else
489         repeat |= repeat << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
490     }
491
492   g_value_set_enum (value, repeat);
493   return TRUE;
494 }
495
496 static void
497 background_repeat_value_print (GtkCssStyleProperty *property,
498                                const GValue        *value,
499                                GString             *string)
500 {
501   GEnumClass *enum_class;
502   GEnumValue *enum_value;
503   GtkCssBackgroundRepeat repeat;
504
505   repeat = g_value_get_enum (value);
506   enum_class = g_type_class_ref (GTK_TYPE_CSS_BACKGROUND_REPEAT);
507   enum_value = g_enum_get_value (enum_class, repeat);
508
509   /* only triggers for 'repeat-x' and 'repeat-y' */
510   if (enum_value)
511     g_string_append (string, enum_value->value_nick);
512   else
513     {
514       enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_HORIZONTAL (repeat));
515       g_string_append (string, enum_value->value_nick);
516
517       if (GTK_CSS_BACKGROUND_HORIZONTAL (repeat) != GTK_CSS_BACKGROUND_VERTICAL (repeat))
518         {
519           enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_VERTICAL (repeat));
520           g_string_append (string, " ");
521           g_string_append (string, enum_value->value_nick);
522         }
523     }
524
525   g_type_class_unref (enum_class);
526 }
527
528 static gboolean
529 background_size_parse (GtkCssStyleProperty *property,
530                        GValue              *value,
531                        GtkCssParser        *parser,
532                        GFile               *base)
533 {
534   GtkCssBackgroundSize size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE};
535
536   if (_gtk_css_parser_try (parser, "cover", TRUE))
537     size.cover = TRUE;
538   else if (_gtk_css_parser_try (parser, "contain", TRUE))
539     size.contain = TRUE;
540   else
541     {
542       if (_gtk_css_parser_try (parser, "auto", TRUE))
543         _gtk_css_number_init (&size.width, 0, GTK_CSS_PX);
544       else if (!_gtk_css_parser_read_number (parser,
545                                              &size.width,
546                                              GTK_CSS_POSITIVE_ONLY
547                                              | GTK_CSS_PARSE_PERCENT
548                                              | GTK_CSS_PARSE_LENGTH))
549         return FALSE;
550
551       if (_gtk_css_parser_try (parser, "auto", TRUE))
552         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
553       else if (_gtk_css_parser_has_number (parser))
554         {
555           if (!_gtk_css_parser_read_number (parser,
556                                             &size.height,
557                                             GTK_CSS_POSITIVE_ONLY
558                                             | GTK_CSS_PARSE_PERCENT
559                                             | GTK_CSS_PARSE_LENGTH))
560             return FALSE;
561         }
562       else
563         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
564     }
565
566   g_value_set_boxed (value, &size);
567   return TRUE;
568 }
569
570 static void
571 background_size_print (GtkCssStyleProperty *property,
572                        const GValue        *value,
573                        GString             *string)
574 {
575   GtkCssBackgroundSize *size = g_value_get_boxed (value);
576
577   if (size->cover)
578     g_string_append (string, "cover");
579   else if (size->contain)
580     g_string_append (string, "contain");
581   else
582     {
583       if (size->width.value == 0)
584         g_string_append (string, "auto");
585       else
586         _gtk_css_number_print (&size->width, string);
587
588       if (size->height.value != 0)
589         {
590           g_string_append (string, " ");
591           _gtk_css_number_print (&size->height, string);
592         }
593     }
594 }
595
596 static void
597 background_size_compute (GtkCssStyleProperty    *property,
598                          GValue                 *computed,
599                          GtkStyleContext        *context,
600                          const GValue           *specified)
601 {
602   GtkCssBackgroundSize *ssize = g_value_get_boxed (specified);
603   GtkCssBackgroundSize csize;
604
605   csize.cover = ssize->cover;
606   csize.contain = ssize->contain;
607   _gtk_css_number_compute (&csize.width,
608                            &ssize->width,
609                            context);
610   _gtk_css_number_compute (&csize.height,
611                            &ssize->height,
612                            context);
613
614   g_value_set_boxed (computed, &csize);
615 }
616
617 /*** REGISTRATION ***/
618
619 static GtkSymbolicColor *
620 gtk_symbolic_color_new_rgba (double red,
621                              double green,
622                              double blue,
623                              double alpha)
624 {
625   GdkRGBA rgba = { red, green, blue, alpha };
626
627   return gtk_symbolic_color_new_literal (&rgba);
628 }
629
630 void
631 _gtk_css_style_property_init_properties (void)
632 {
633   char *default_font_family[] = { "Sans", NULL };
634   GtkCssNumber number;
635   GtkSymbolicColor *symbolic;
636   GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
637   GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
638   GtkBorder border_of_ones = { 1, 1, 1, 1 };
639   GtkCssBorderImageRepeat border_image_repeat = { GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_STRETCH };
640
641   /* Initialize "color" and "font-size" first,
642    * so that when computing values later they are
643    * done first. That way, 'currentColor' and font
644    * sizes in em can be looked up properly */
645   symbolic = gtk_symbolic_color_new_rgba (1, 1, 1, 1);
646   gtk_css_style_property_register        ("color",
647                                           GTK_TYPE_SYMBOLIC_COLOR,
648                                           GDK_TYPE_RGBA,
649                                           GDK_TYPE_RGBA,
650                                           GTK_STYLE_PROPERTY_INHERIT,
651                                           NULL,
652                                           NULL,
653                                           color_compute,
654                                           symbolic);
655   gtk_symbolic_color_unref (symbolic);
656   gtk_css_style_property_register        ("font-size",
657                                           G_TYPE_DOUBLE,
658                                           G_TYPE_DOUBLE,
659                                           G_TYPE_DOUBLE,
660                                           GTK_STYLE_PROPERTY_INHERIT,
661                                           NULL,
662                                           NULL,
663                                           NULL,
664                                           10.0);
665
666   /* properties that aren't referenced when computing values
667    * start here */
668   symbolic = gtk_symbolic_color_new_rgba (0, 0, 0, 0);
669   gtk_css_style_property_register        ("background-color",
670                                           GTK_TYPE_SYMBOLIC_COLOR,
671                                           GDK_TYPE_RGBA,
672                                           GDK_TYPE_RGBA,
673                                           0,
674                                           NULL,
675                                           NULL,
676                                           color_compute,
677                                           symbolic);
678   gtk_symbolic_color_unref (symbolic);
679
680   gtk_css_style_property_register        ("font-family",
681                                           G_TYPE_STRV,
682                                           G_TYPE_STRV,
683                                           G_TYPE_STRV,
684                                           GTK_STYLE_PROPERTY_INHERIT,
685                                           font_family_parse,
686                                           font_family_value_print,
687                                           NULL,
688                                           default_font_family);
689   gtk_css_style_property_register        ("font-style",
690                                           PANGO_TYPE_STYLE,
691                                           PANGO_TYPE_STYLE,
692                                           PANGO_TYPE_STYLE,
693                                           GTK_STYLE_PROPERTY_INHERIT,
694                                           NULL,
695                                           NULL,
696                                           NULL,
697                                           PANGO_STYLE_NORMAL);
698   gtk_css_style_property_register        ("font-variant",
699                                           PANGO_TYPE_VARIANT,
700                                           PANGO_TYPE_VARIANT,
701                                           PANGO_TYPE_VARIANT,
702                                           GTK_STYLE_PROPERTY_INHERIT,
703                                           NULL,
704                                           NULL,
705                                           NULL,
706                                           PANGO_VARIANT_NORMAL);
707   /* xxx: need to parse this properly, ie parse the numbers */
708   gtk_css_style_property_register        ("font-weight",
709                                           PANGO_TYPE_WEIGHT,
710                                           PANGO_TYPE_WEIGHT,
711                                           PANGO_TYPE_WEIGHT,
712                                           GTK_STYLE_PROPERTY_INHERIT,
713                                           NULL,
714                                           NULL,
715                                           NULL,
716                                           PANGO_WEIGHT_NORMAL);
717
718   gtk_css_style_property_register        ("text-shadow",
719                                           GTK_TYPE_SHADOW,
720                                           GTK_TYPE_SHADOW,
721                                           GTK_TYPE_SHADOW,
722                                           GTK_STYLE_PROPERTY_INHERIT,
723                                           NULL,
724                                           NULL,
725                                           NULL,
726                                           NULL);
727
728   gtk_css_style_property_register        ("icon-shadow",
729                                           GTK_TYPE_SHADOW,
730                                           GTK_TYPE_SHADOW,
731                                           GTK_TYPE_SHADOW,
732                                           GTK_STYLE_PROPERTY_INHERIT,
733                                           NULL,
734                                           NULL,
735                                           NULL,
736                                           NULL);
737
738   gtk_css_style_property_register        ("box-shadow",
739                                           GTK_TYPE_SHADOW,
740                                           GTK_TYPE_SHADOW,
741                                           GTK_TYPE_SHADOW,
742                                           0,
743                                           NULL,
744                                           NULL,
745                                           NULL,
746                                           NULL);
747
748   gtk_css_style_property_register        ("margin-top",
749                                           G_TYPE_INT,
750                                           G_TYPE_INT,
751                                           G_TYPE_INT,
752                                           0,
753                                           NULL,
754                                           NULL,
755                                           NULL,
756                                           0);
757   gtk_css_style_property_register        ("margin-left",
758                                           G_TYPE_INT,
759                                           G_TYPE_INT,
760                                           G_TYPE_INT,
761                                           0,
762                                           NULL,
763                                           NULL,
764                                           NULL,
765                                           0);
766   gtk_css_style_property_register        ("margin-bottom",
767                                           G_TYPE_INT,
768                                           G_TYPE_INT,
769                                           G_TYPE_INT,
770                                           0,
771                                           NULL,
772                                           NULL,
773                                           NULL,
774                                           0);
775   gtk_css_style_property_register        ("margin-right",
776                                           G_TYPE_INT,
777                                           G_TYPE_INT,
778                                           G_TYPE_INT,
779                                           0,
780                                           NULL,
781                                           NULL,
782                                           NULL,
783                                           0);
784   gtk_css_style_property_register        ("padding-top",
785                                           G_TYPE_INT,
786                                           G_TYPE_INT,
787                                           G_TYPE_INT,
788                                           0,
789                                           NULL,
790                                           NULL,
791                                           NULL,
792                                           0);
793   gtk_css_style_property_register        ("padding-left",
794                                           G_TYPE_INT,
795                                           G_TYPE_INT,
796                                           G_TYPE_INT,
797                                           0,
798                                           NULL,
799                                           NULL,
800                                           NULL,
801                                           0);
802   gtk_css_style_property_register        ("padding-bottom",
803                                           G_TYPE_INT,
804                                           G_TYPE_INT,
805                                           G_TYPE_INT,
806                                           0,
807                                           NULL,
808                                           NULL,
809                                           NULL,
810                                           0);
811   gtk_css_style_property_register        ("padding-right",
812                                           G_TYPE_INT,
813                                           G_TYPE_INT,
814                                           G_TYPE_INT,
815                                           0,
816                                           NULL,
817                                           NULL,
818                                           NULL,
819                                           0);
820   _gtk_css_number_init (&number, 0, GTK_CSS_PX);
821   /* IMPORTANT: compute_border_width() requires that the border-width
822    * properties be immeditaly followed by the border-style properties
823    */
824   gtk_css_style_property_register        ("border-top-style",
825                                           GTK_TYPE_BORDER_STYLE,
826                                           GTK_TYPE_BORDER_STYLE,
827                                           GTK_TYPE_BORDER_STYLE,
828                                           0,
829                                           NULL,
830                                           NULL,
831                                           NULL,
832                                           GTK_BORDER_STYLE_NONE);
833   gtk_css_style_property_register        ("border-top-width",
834                                           GTK_TYPE_CSS_NUMBER,
835                                           G_TYPE_INT,
836                                           G_TYPE_INT,
837                                           0,
838                                           parse_border_width,
839                                           NULL,
840                                           compute_border_width,
841                                           &number);
842   gtk_css_style_property_register        ("border-left-style",
843                                           GTK_TYPE_BORDER_STYLE,
844                                           GTK_TYPE_BORDER_STYLE,
845                                           GTK_TYPE_BORDER_STYLE,
846                                           0,
847                                           NULL,
848                                           NULL,
849                                           NULL,
850                                           GTK_BORDER_STYLE_NONE);
851   gtk_css_style_property_register        ("border-left-width",
852                                           GTK_TYPE_CSS_NUMBER,
853                                           G_TYPE_INT,
854                                           G_TYPE_INT,
855                                           0,
856                                           parse_border_width,
857                                           NULL,
858                                           compute_border_width,
859                                           &number);
860   gtk_css_style_property_register        ("border-bottom-style",
861                                           GTK_TYPE_BORDER_STYLE,
862                                           GTK_TYPE_BORDER_STYLE,
863                                           GTK_TYPE_BORDER_STYLE,
864                                           0,
865                                           NULL,
866                                           NULL,
867                                           NULL,
868                                           GTK_BORDER_STYLE_NONE);
869   gtk_css_style_property_register        ("border-bottom-width",
870                                           GTK_TYPE_CSS_NUMBER,
871                                           G_TYPE_INT,
872                                           G_TYPE_INT,
873                                           0,
874                                           parse_border_width,
875                                           NULL,
876                                           compute_border_width,
877                                           &number);
878   gtk_css_style_property_register        ("border-right-style",
879                                           GTK_TYPE_BORDER_STYLE,
880                                           GTK_TYPE_BORDER_STYLE,
881                                           GTK_TYPE_BORDER_STYLE,
882                                           0,
883                                           NULL,
884                                           NULL,
885                                           NULL,
886                                           GTK_BORDER_STYLE_NONE);
887   gtk_css_style_property_register        ("border-right-width",
888                                           GTK_TYPE_CSS_NUMBER,
889                                           G_TYPE_INT,
890                                           G_TYPE_INT,
891                                           0,
892                                           parse_border_width,
893                                           NULL,
894                                           compute_border_width,
895                                           &number);
896
897   gtk_css_style_property_register        ("border-top-left-radius",
898                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
899                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
900                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
901                                           0,
902                                           border_corner_radius_value_parse,
903                                           border_corner_radius_value_print,
904                                           NULL,
905                                           &no_corner_radius);
906   gtk_css_style_property_register        ("border-top-right-radius",
907                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
908                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
909                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
910                                           0,
911                                           border_corner_radius_value_parse,
912                                           border_corner_radius_value_print,
913                                           NULL,
914                                           &no_corner_radius);
915   gtk_css_style_property_register        ("border-bottom-right-radius",
916                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
917                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
918                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
919                                           0,
920                                           border_corner_radius_value_parse,
921                                           border_corner_radius_value_print,
922                                           NULL,
923                                           &no_corner_radius);
924   gtk_css_style_property_register        ("border-bottom-left-radius",
925                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
926                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
927                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
928                                           0,
929                                           border_corner_radius_value_parse,
930                                           border_corner_radius_value_print,
931                                           NULL,
932                                           &no_corner_radius);
933
934   gtk_css_style_property_register        ("outline-style",
935                                           GTK_TYPE_BORDER_STYLE,
936                                           GTK_TYPE_BORDER_STYLE,
937                                           GTK_TYPE_BORDER_STYLE,
938                                           0,
939                                           NULL,
940                                           NULL,
941                                           NULL,
942                                           GTK_BORDER_STYLE_NONE);
943   gtk_css_style_property_register        ("outline-width",
944                                           GTK_TYPE_CSS_NUMBER,
945                                           G_TYPE_INT,
946                                           G_TYPE_INT,
947                                           0,
948                                           parse_border_width,
949                                           NULL,
950                                           compute_border_width,
951                                           &number);
952   gtk_css_style_property_register        ("outline-offset",
953                                           G_TYPE_INT,
954                                           G_TYPE_INT,
955                                           G_TYPE_INT,
956                                           0,
957                                           NULL,
958                                           NULL,
959                                           NULL,
960                                           0);
961
962   gtk_css_style_property_register        ("background-clip",
963                                           GTK_TYPE_CSS_AREA,
964                                           GTK_TYPE_CSS_AREA,
965                                           GTK_TYPE_CSS_AREA,
966                                           0,
967                                           NULL,
968                                           NULL,
969                                           NULL,
970                                           GTK_CSS_AREA_BORDER_BOX);
971   gtk_css_style_property_register        ("background-origin",
972                                           GTK_TYPE_CSS_AREA,
973                                           GTK_TYPE_CSS_AREA,
974                                           GTK_TYPE_CSS_AREA,
975                                           0,
976                                           NULL,
977                                           NULL,
978                                           NULL,
979                                           GTK_CSS_AREA_PADDING_BOX);
980   gtk_css_style_property_register        ("background-size",
981                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
982                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
983                                           G_TYPE_NONE,
984                                           0,
985                                           background_size_parse,
986                                           background_size_print,
987                                           background_size_compute,
988                                           &default_background_size);
989
990   gtk_css_style_property_register        ("border-top-color",
991                                           GTK_TYPE_SYMBOLIC_COLOR,
992                                           GDK_TYPE_RGBA,
993                                           GDK_TYPE_RGBA,
994                                           0,
995                                           NULL,
996                                           NULL,
997                                           color_compute,
998                                           _gtk_symbolic_color_get_current_color ());
999   gtk_css_style_property_register        ("border-right-color",
1000                                           GTK_TYPE_SYMBOLIC_COLOR,
1001                                           GDK_TYPE_RGBA,
1002                                           GDK_TYPE_RGBA,
1003                                           0,
1004                                           NULL,
1005                                           NULL,
1006                                           color_compute,
1007                                           _gtk_symbolic_color_get_current_color ());
1008   gtk_css_style_property_register        ("border-bottom-color",
1009                                           GTK_TYPE_SYMBOLIC_COLOR,
1010                                           GDK_TYPE_RGBA,
1011                                           GDK_TYPE_RGBA,
1012                                           0,
1013                                           NULL,
1014                                           NULL,
1015                                           color_compute,
1016                                           _gtk_symbolic_color_get_current_color ());
1017   gtk_css_style_property_register        ("border-left-color",
1018                                           GTK_TYPE_SYMBOLIC_COLOR,
1019                                           GDK_TYPE_RGBA,
1020                                           GDK_TYPE_RGBA,
1021                                           0,
1022                                           NULL,
1023                                           NULL,
1024                                           color_compute,
1025                                           _gtk_symbolic_color_get_current_color ());
1026   gtk_css_style_property_register        ("outline-color",
1027                                           GTK_TYPE_SYMBOLIC_COLOR,
1028                                           GDK_TYPE_RGBA,
1029                                           GDK_TYPE_RGBA,
1030                                           0,
1031                                           NULL,
1032                                           NULL,
1033                                           color_compute,
1034                                           _gtk_symbolic_color_get_current_color ());
1035
1036   gtk_css_style_property_register        ("background-repeat",
1037                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1038                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1039                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1040                                           0,
1041                                           background_repeat_value_parse,
1042                                           background_repeat_value_print,
1043                                           NULL,
1044                                           GTK_CSS_BACKGROUND_REPEAT | (GTK_CSS_BACKGROUND_REPEAT << GTK_CSS_BACKGROUND_REPEAT_SHIFT));
1045   gtk_css_style_property_register        ("background-image",
1046                                           GTK_TYPE_CSS_IMAGE,
1047                                           GTK_TYPE_CSS_IMAGE,
1048                                           CAIRO_GOBJECT_TYPE_PATTERN,
1049                                           0,
1050                                           css_image_value_parse,
1051                                           css_image_value_print,
1052                                           css_image_value_compute,
1053                                           NULL);
1054
1055   gtk_css_style_property_register        ("border-image-source",
1056                                           GTK_TYPE_CSS_IMAGE,
1057                                           GTK_TYPE_CSS_IMAGE,
1058                                           CAIRO_GOBJECT_TYPE_PATTERN,
1059                                           0,
1060                                           css_image_value_parse,
1061                                           css_image_value_print,
1062                                           css_image_value_compute,
1063                                           NULL);
1064   gtk_css_style_property_register        ("border-image-repeat",
1065                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1066                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1067                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1068                                           0,
1069                                           NULL,
1070                                           NULL,
1071                                           NULL,
1072                                           &border_image_repeat);
1073
1074   /* XXX: The initial value is wrong, it should be 100% */
1075   gtk_css_style_property_register        ("border-image-slice",
1076                                           GTK_TYPE_BORDER,
1077                                           GTK_TYPE_BORDER,
1078                                           GTK_TYPE_BORDER,
1079                                           0,
1080                                           NULL,
1081                                           NULL,
1082                                           NULL,
1083                                           &border_of_ones);
1084   gtk_css_style_property_register        ("border-image-width",
1085                                           GTK_TYPE_BORDER,
1086                                           GTK_TYPE_BORDER,
1087                                           GTK_TYPE_BORDER,
1088                                           0,
1089                                           NULL,
1090                                           NULL,
1091                                           NULL,
1092                                           NULL);
1093   gtk_css_style_property_register        ("engine",
1094                                           GTK_TYPE_THEMING_ENGINE,
1095                                           GTK_TYPE_THEMING_ENGINE,
1096                                           GTK_TYPE_THEMING_ENGINE,
1097                                           0,
1098                                           NULL,
1099                                           NULL,
1100                                           NULL,
1101                                           gtk_theming_engine_load (NULL));
1102   gtk_css_style_property_register        ("transition",
1103                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1104                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1105                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1106                                           0,
1107                                           NULL,
1108                                           NULL,
1109                                           NULL,
1110                                           NULL);
1111
1112   /* Private property holding the binding sets */
1113   gtk_css_style_property_register        ("gtk-key-bindings",
1114                                           G_TYPE_PTR_ARRAY,
1115                                           G_TYPE_PTR_ARRAY,
1116                                           G_TYPE_PTR_ARRAY,
1117                                           0,
1118                                           bindings_value_parse,
1119                                           bindings_value_print,
1120                                           NULL,
1121                                           NULL);
1122 }
1123