]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssstylepropertyimpl.c
529483b6d7572ed01b65e67adbec6b364c50a910
[~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_margin (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_NUMBER_AS_PIXELS
425                                     | GTK_CSS_PARSE_LENGTH))
426     return FALSE;
427
428   g_value_set_boxed (value, &number);
429   return TRUE;
430 }
431
432 static void
433 compute_margin (GtkCssStyleProperty *property,
434                 GValue              *computed,
435                 GtkStyleContext     *context,
436                 const GValue        *specified)
437 {
438   GtkCssNumber number;
439   
440   _gtk_css_number_compute (&number,
441                            g_value_get_boxed (specified),
442                            context);
443   g_value_set_boxed (computed, &number);
444 }
445
446 static gboolean 
447 parse_border_width (GtkCssStyleProperty *property,
448                     GValue              *value,
449                     GtkCssParser        *parser,
450                     GFile               *base)
451 {
452   GtkCssNumber number;
453
454   if (!_gtk_css_parser_read_number (parser,
455                                     &number, 
456                                     GTK_CSS_POSITIVE_ONLY
457                                     | GTK_CSS_NUMBER_AS_PIXELS
458                                     | GTK_CSS_PARSE_LENGTH))
459     return FALSE;
460
461   g_value_set_boxed (value, &number);
462   return TRUE;
463 }
464
465 static void
466 compute_border_width (GtkCssStyleProperty    *property,
467                       GValue                 *computed,
468                       GtkStyleContext        *context,
469                       const GValue           *specified)
470 {
471   GtkCssStyleProperty *style;
472   GtkBorderStyle border_style;
473   GtkCssNumber number;
474   
475   /* The -1 is magic that is only true because we register the style
476    * properties directly after the width properties.
477    */
478   style = _gtk_css_style_property_lookup_by_id (_gtk_css_style_property_get_id (property) - 1);
479   border_style = g_value_get_enum (_gtk_style_context_peek_property (context, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (style))));
480
481   if (border_style == GTK_BORDER_STYLE_NONE ||
482       border_style == GTK_BORDER_STYLE_HIDDEN)
483     {
484       g_value_set_int (computed, 0);
485       return;
486     }
487
488   _gtk_css_number_compute (&number,
489                            g_value_get_boxed (specified),
490                            context);
491   g_value_set_int (computed, round (number.value));
492 }
493
494 static gboolean
495 background_repeat_value_parse (GtkCssStyleProperty *property,
496                                GValue              *value,
497                                GtkCssParser        *parser,
498                                GFile               *base)
499 {
500   int repeat, vertical;
501
502   if (!_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &repeat))
503     {
504       _gtk_css_parser_error (parser, "Not a valid value");
505       return FALSE;
506     }
507
508   if (repeat <= GTK_CSS_BACKGROUND_REPEAT_MASK)
509     {
510       if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT, &vertical))
511         {
512           if (vertical >= GTK_CSS_BACKGROUND_REPEAT_MASK)
513             {
514               _gtk_css_parser_error (parser, "Not a valid 2nd value");
515               return FALSE;
516             }
517           else
518             repeat |= vertical << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
519         }
520       else
521         repeat |= repeat << GTK_CSS_BACKGROUND_REPEAT_SHIFT;
522     }
523
524   g_value_set_enum (value, repeat);
525   return TRUE;
526 }
527
528 static void
529 background_repeat_value_print (GtkCssStyleProperty *property,
530                                const GValue        *value,
531                                GString             *string)
532 {
533   GEnumClass *enum_class;
534   GEnumValue *enum_value;
535   GtkCssBackgroundRepeat repeat;
536
537   repeat = g_value_get_enum (value);
538   enum_class = g_type_class_ref (GTK_TYPE_CSS_BACKGROUND_REPEAT);
539   enum_value = g_enum_get_value (enum_class, repeat);
540
541   /* only triggers for 'repeat-x' and 'repeat-y' */
542   if (enum_value)
543     g_string_append (string, enum_value->value_nick);
544   else
545     {
546       enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_HORIZONTAL (repeat));
547       g_string_append (string, enum_value->value_nick);
548
549       if (GTK_CSS_BACKGROUND_HORIZONTAL (repeat) != GTK_CSS_BACKGROUND_VERTICAL (repeat))
550         {
551           enum_value = g_enum_get_value (enum_class, GTK_CSS_BACKGROUND_VERTICAL (repeat));
552           g_string_append (string, " ");
553           g_string_append (string, enum_value->value_nick);
554         }
555     }
556
557   g_type_class_unref (enum_class);
558 }
559
560 static gboolean
561 background_size_parse (GtkCssStyleProperty *property,
562                        GValue              *value,
563                        GtkCssParser        *parser,
564                        GFile               *base)
565 {
566   GtkCssBackgroundSize size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE};
567
568   if (_gtk_css_parser_try (parser, "cover", TRUE))
569     size.cover = TRUE;
570   else if (_gtk_css_parser_try (parser, "contain", TRUE))
571     size.contain = TRUE;
572   else
573     {
574       if (_gtk_css_parser_try (parser, "auto", TRUE))
575         _gtk_css_number_init (&size.width, 0, GTK_CSS_PX);
576       else if (!_gtk_css_parser_read_number (parser,
577                                              &size.width,
578                                              GTK_CSS_POSITIVE_ONLY
579                                              | GTK_CSS_PARSE_PERCENT
580                                              | GTK_CSS_PARSE_LENGTH))
581         return FALSE;
582
583       if (_gtk_css_parser_try (parser, "auto", TRUE))
584         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
585       else if (_gtk_css_parser_has_number (parser))
586         {
587           if (!_gtk_css_parser_read_number (parser,
588                                             &size.height,
589                                             GTK_CSS_POSITIVE_ONLY
590                                             | GTK_CSS_PARSE_PERCENT
591                                             | GTK_CSS_PARSE_LENGTH))
592             return FALSE;
593         }
594       else
595         _gtk_css_number_init (&size.height, 0, GTK_CSS_PX);
596     }
597
598   g_value_set_boxed (value, &size);
599   return TRUE;
600 }
601
602 static void
603 background_size_print (GtkCssStyleProperty *property,
604                        const GValue        *value,
605                        GString             *string)
606 {
607   GtkCssBackgroundSize *size = g_value_get_boxed (value);
608
609   if (size->cover)
610     g_string_append (string, "cover");
611   else if (size->contain)
612     g_string_append (string, "contain");
613   else
614     {
615       if (size->width.value == 0)
616         g_string_append (string, "auto");
617       else
618         _gtk_css_number_print (&size->width, string);
619
620       if (size->height.value != 0)
621         {
622           g_string_append (string, " ");
623           _gtk_css_number_print (&size->height, string);
624         }
625     }
626 }
627
628 static void
629 background_size_compute (GtkCssStyleProperty    *property,
630                          GValue                 *computed,
631                          GtkStyleContext        *context,
632                          const GValue           *specified)
633 {
634   GtkCssBackgroundSize *ssize = g_value_get_boxed (specified);
635   GtkCssBackgroundSize csize;
636
637   csize.cover = ssize->cover;
638   csize.contain = ssize->contain;
639   _gtk_css_number_compute (&csize.width,
640                            &ssize->width,
641                            context);
642   _gtk_css_number_compute (&csize.height,
643                            &ssize->height,
644                            context);
645
646   g_value_set_boxed (computed, &csize);
647 }
648
649 /*** REGISTRATION ***/
650
651 static GtkSymbolicColor *
652 gtk_symbolic_color_new_rgba (double red,
653                              double green,
654                              double blue,
655                              double alpha)
656 {
657   GdkRGBA rgba = { red, green, blue, alpha };
658
659   return gtk_symbolic_color_new_literal (&rgba);
660 }
661
662 void
663 _gtk_css_style_property_init_properties (void)
664 {
665   char *default_font_family[] = { "Sans", NULL };
666   GtkCssNumber number;
667   GtkSymbolicColor *symbolic;
668   GtkCssBackgroundSize default_background_size = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), FALSE, FALSE };
669   GtkCssBorderCornerRadius no_corner_radius = { GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX), GTK_CSS_NUMBER_INIT (0, GTK_CSS_PX) };
670   GtkBorder border_of_ones = { 1, 1, 1, 1 };
671   GtkCssBorderImageRepeat border_image_repeat = { GTK_CSS_REPEAT_STYLE_STRETCH, GTK_CSS_REPEAT_STYLE_STRETCH };
672
673   /* Initialize "color" and "font-size" first,
674    * so that when computing values later they are
675    * done first. That way, 'currentColor' and font
676    * sizes in em can be looked up properly */
677   symbolic = gtk_symbolic_color_new_rgba (1, 1, 1, 1);
678   gtk_css_style_property_register        ("color",
679                                           GTK_TYPE_SYMBOLIC_COLOR,
680                                           GDK_TYPE_RGBA,
681                                           GDK_TYPE_RGBA,
682                                           GTK_STYLE_PROPERTY_INHERIT,
683                                           NULL,
684                                           NULL,
685                                           color_compute,
686                                           symbolic);
687   gtk_symbolic_color_unref (symbolic);
688   gtk_css_style_property_register        ("font-size",
689                                           G_TYPE_DOUBLE,
690                                           G_TYPE_DOUBLE,
691                                           G_TYPE_DOUBLE,
692                                           GTK_STYLE_PROPERTY_INHERIT,
693                                           NULL,
694                                           NULL,
695                                           NULL,
696                                           10.0);
697
698   /* properties that aren't referenced when computing values
699    * start here */
700   symbolic = gtk_symbolic_color_new_rgba (0, 0, 0, 0);
701   gtk_css_style_property_register        ("background-color",
702                                           GTK_TYPE_SYMBOLIC_COLOR,
703                                           GDK_TYPE_RGBA,
704                                           GDK_TYPE_RGBA,
705                                           0,
706                                           NULL,
707                                           NULL,
708                                           color_compute,
709                                           symbolic);
710   gtk_symbolic_color_unref (symbolic);
711
712   gtk_css_style_property_register        ("font-family",
713                                           G_TYPE_STRV,
714                                           G_TYPE_STRV,
715                                           G_TYPE_STRV,
716                                           GTK_STYLE_PROPERTY_INHERIT,
717                                           font_family_parse,
718                                           font_family_value_print,
719                                           NULL,
720                                           default_font_family);
721   gtk_css_style_property_register        ("font-style",
722                                           PANGO_TYPE_STYLE,
723                                           PANGO_TYPE_STYLE,
724                                           PANGO_TYPE_STYLE,
725                                           GTK_STYLE_PROPERTY_INHERIT,
726                                           NULL,
727                                           NULL,
728                                           NULL,
729                                           PANGO_STYLE_NORMAL);
730   gtk_css_style_property_register        ("font-variant",
731                                           PANGO_TYPE_VARIANT,
732                                           PANGO_TYPE_VARIANT,
733                                           PANGO_TYPE_VARIANT,
734                                           GTK_STYLE_PROPERTY_INHERIT,
735                                           NULL,
736                                           NULL,
737                                           NULL,
738                                           PANGO_VARIANT_NORMAL);
739   /* xxx: need to parse this properly, ie parse the numbers */
740   gtk_css_style_property_register        ("font-weight",
741                                           PANGO_TYPE_WEIGHT,
742                                           PANGO_TYPE_WEIGHT,
743                                           PANGO_TYPE_WEIGHT,
744                                           GTK_STYLE_PROPERTY_INHERIT,
745                                           NULL,
746                                           NULL,
747                                           NULL,
748                                           PANGO_WEIGHT_NORMAL);
749
750   gtk_css_style_property_register        ("text-shadow",
751                                           GTK_TYPE_SHADOW,
752                                           GTK_TYPE_SHADOW,
753                                           GTK_TYPE_SHADOW,
754                                           GTK_STYLE_PROPERTY_INHERIT,
755                                           NULL,
756                                           NULL,
757                                           NULL,
758                                           NULL);
759
760   gtk_css_style_property_register        ("icon-shadow",
761                                           GTK_TYPE_SHADOW,
762                                           GTK_TYPE_SHADOW,
763                                           GTK_TYPE_SHADOW,
764                                           GTK_STYLE_PROPERTY_INHERIT,
765                                           NULL,
766                                           NULL,
767                                           NULL,
768                                           NULL);
769
770   gtk_css_style_property_register        ("box-shadow",
771                                           GTK_TYPE_SHADOW,
772                                           GTK_TYPE_SHADOW,
773                                           GTK_TYPE_SHADOW,
774                                           0,
775                                           NULL,
776                                           NULL,
777                                           NULL,
778                                           NULL);
779
780   _gtk_css_number_init (&number, 0, GTK_CSS_PX);
781   gtk_css_style_property_register        ("margin-top",
782                                           GTK_TYPE_CSS_NUMBER,
783                                           GTK_TYPE_CSS_NUMBER,
784                                           G_TYPE_INT,
785                                           0,
786                                           parse_margin,
787                                           NULL,
788                                           compute_margin,
789                                           &number);
790   gtk_css_style_property_register        ("margin-left",
791                                           GTK_TYPE_CSS_NUMBER,
792                                           GTK_TYPE_CSS_NUMBER,
793                                           G_TYPE_INT,
794                                           0,
795                                           parse_margin,
796                                           NULL,
797                                           compute_margin,
798                                           &number);
799   gtk_css_style_property_register        ("margin-bottom",
800                                           GTK_TYPE_CSS_NUMBER,
801                                           GTK_TYPE_CSS_NUMBER,
802                                           G_TYPE_INT,
803                                           0,
804                                           parse_margin,
805                                           NULL,
806                                           compute_margin,
807                                           &number);
808   gtk_css_style_property_register        ("margin-right",
809                                           GTK_TYPE_CSS_NUMBER,
810                                           GTK_TYPE_CSS_NUMBER,
811                                           G_TYPE_INT,
812                                           0,
813                                           parse_margin,
814                                           NULL,
815                                           compute_margin,
816                                           &number);
817   gtk_css_style_property_register        ("padding-top",
818                                           G_TYPE_INT,
819                                           G_TYPE_INT,
820                                           G_TYPE_INT,
821                                           0,
822                                           NULL,
823                                           NULL,
824                                           NULL,
825                                           0);
826   gtk_css_style_property_register        ("padding-left",
827                                           G_TYPE_INT,
828                                           G_TYPE_INT,
829                                           G_TYPE_INT,
830                                           0,
831                                           NULL,
832                                           NULL,
833                                           NULL,
834                                           0);
835   gtk_css_style_property_register        ("padding-bottom",
836                                           G_TYPE_INT,
837                                           G_TYPE_INT,
838                                           G_TYPE_INT,
839                                           0,
840                                           NULL,
841                                           NULL,
842                                           NULL,
843                                           0);
844   gtk_css_style_property_register        ("padding-right",
845                                           G_TYPE_INT,
846                                           G_TYPE_INT,
847                                           G_TYPE_INT,
848                                           0,
849                                           NULL,
850                                           NULL,
851                                           NULL,
852                                           0);
853   /* IMPORTANT: compute_border_width() requires that the border-width
854    * properties be immeditaly followed by the border-style properties
855    */
856   gtk_css_style_property_register        ("border-top-style",
857                                           GTK_TYPE_BORDER_STYLE,
858                                           GTK_TYPE_BORDER_STYLE,
859                                           GTK_TYPE_BORDER_STYLE,
860                                           0,
861                                           NULL,
862                                           NULL,
863                                           NULL,
864                                           GTK_BORDER_STYLE_NONE);
865   gtk_css_style_property_register        ("border-top-width",
866                                           GTK_TYPE_CSS_NUMBER,
867                                           G_TYPE_INT,
868                                           G_TYPE_INT,
869                                           0,
870                                           parse_border_width,
871                                           NULL,
872                                           compute_border_width,
873                                           &number);
874   gtk_css_style_property_register        ("border-left-style",
875                                           GTK_TYPE_BORDER_STYLE,
876                                           GTK_TYPE_BORDER_STYLE,
877                                           GTK_TYPE_BORDER_STYLE,
878                                           0,
879                                           NULL,
880                                           NULL,
881                                           NULL,
882                                           GTK_BORDER_STYLE_NONE);
883   gtk_css_style_property_register        ("border-left-width",
884                                           GTK_TYPE_CSS_NUMBER,
885                                           G_TYPE_INT,
886                                           G_TYPE_INT,
887                                           0,
888                                           parse_border_width,
889                                           NULL,
890                                           compute_border_width,
891                                           &number);
892   gtk_css_style_property_register        ("border-bottom-style",
893                                           GTK_TYPE_BORDER_STYLE,
894                                           GTK_TYPE_BORDER_STYLE,
895                                           GTK_TYPE_BORDER_STYLE,
896                                           0,
897                                           NULL,
898                                           NULL,
899                                           NULL,
900                                           GTK_BORDER_STYLE_NONE);
901   gtk_css_style_property_register        ("border-bottom-width",
902                                           GTK_TYPE_CSS_NUMBER,
903                                           G_TYPE_INT,
904                                           G_TYPE_INT,
905                                           0,
906                                           parse_border_width,
907                                           NULL,
908                                           compute_border_width,
909                                           &number);
910   gtk_css_style_property_register        ("border-right-style",
911                                           GTK_TYPE_BORDER_STYLE,
912                                           GTK_TYPE_BORDER_STYLE,
913                                           GTK_TYPE_BORDER_STYLE,
914                                           0,
915                                           NULL,
916                                           NULL,
917                                           NULL,
918                                           GTK_BORDER_STYLE_NONE);
919   gtk_css_style_property_register        ("border-right-width",
920                                           GTK_TYPE_CSS_NUMBER,
921                                           G_TYPE_INT,
922                                           G_TYPE_INT,
923                                           0,
924                                           parse_border_width,
925                                           NULL,
926                                           compute_border_width,
927                                           &number);
928
929   gtk_css_style_property_register        ("border-top-left-radius",
930                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
931                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
932                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
933                                           0,
934                                           border_corner_radius_value_parse,
935                                           border_corner_radius_value_print,
936                                           NULL,
937                                           &no_corner_radius);
938   gtk_css_style_property_register        ("border-top-right-radius",
939                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
940                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
941                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
942                                           0,
943                                           border_corner_radius_value_parse,
944                                           border_corner_radius_value_print,
945                                           NULL,
946                                           &no_corner_radius);
947   gtk_css_style_property_register        ("border-bottom-right-radius",
948                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
949                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
950                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
951                                           0,
952                                           border_corner_radius_value_parse,
953                                           border_corner_radius_value_print,
954                                           NULL,
955                                           &no_corner_radius);
956   gtk_css_style_property_register        ("border-bottom-left-radius",
957                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
958                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
959                                           GTK_TYPE_CSS_BORDER_CORNER_RADIUS,
960                                           0,
961                                           border_corner_radius_value_parse,
962                                           border_corner_radius_value_print,
963                                           NULL,
964                                           &no_corner_radius);
965
966   gtk_css_style_property_register        ("outline-style",
967                                           GTK_TYPE_BORDER_STYLE,
968                                           GTK_TYPE_BORDER_STYLE,
969                                           GTK_TYPE_BORDER_STYLE,
970                                           0,
971                                           NULL,
972                                           NULL,
973                                           NULL,
974                                           GTK_BORDER_STYLE_NONE);
975   gtk_css_style_property_register        ("outline-width",
976                                           GTK_TYPE_CSS_NUMBER,
977                                           G_TYPE_INT,
978                                           G_TYPE_INT,
979                                           0,
980                                           parse_border_width,
981                                           NULL,
982                                           compute_border_width,
983                                           &number);
984   gtk_css_style_property_register        ("outline-offset",
985                                           G_TYPE_INT,
986                                           G_TYPE_INT,
987                                           G_TYPE_INT,
988                                           0,
989                                           NULL,
990                                           NULL,
991                                           NULL,
992                                           0);
993
994   gtk_css_style_property_register        ("background-clip",
995                                           GTK_TYPE_CSS_AREA,
996                                           GTK_TYPE_CSS_AREA,
997                                           GTK_TYPE_CSS_AREA,
998                                           0,
999                                           NULL,
1000                                           NULL,
1001                                           NULL,
1002                                           GTK_CSS_AREA_BORDER_BOX);
1003   gtk_css_style_property_register        ("background-origin",
1004                                           GTK_TYPE_CSS_AREA,
1005                                           GTK_TYPE_CSS_AREA,
1006                                           GTK_TYPE_CSS_AREA,
1007                                           0,
1008                                           NULL,
1009                                           NULL,
1010                                           NULL,
1011                                           GTK_CSS_AREA_PADDING_BOX);
1012   gtk_css_style_property_register        ("background-size",
1013                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
1014                                           GTK_TYPE_CSS_BACKGROUND_SIZE,
1015                                           G_TYPE_NONE,
1016                                           0,
1017                                           background_size_parse,
1018                                           background_size_print,
1019                                           background_size_compute,
1020                                           &default_background_size);
1021
1022   gtk_css_style_property_register        ("border-top-color",
1023                                           GTK_TYPE_SYMBOLIC_COLOR,
1024                                           GDK_TYPE_RGBA,
1025                                           GDK_TYPE_RGBA,
1026                                           0,
1027                                           NULL,
1028                                           NULL,
1029                                           color_compute,
1030                                           _gtk_symbolic_color_get_current_color ());
1031   gtk_css_style_property_register        ("border-right-color",
1032                                           GTK_TYPE_SYMBOLIC_COLOR,
1033                                           GDK_TYPE_RGBA,
1034                                           GDK_TYPE_RGBA,
1035                                           0,
1036                                           NULL,
1037                                           NULL,
1038                                           color_compute,
1039                                           _gtk_symbolic_color_get_current_color ());
1040   gtk_css_style_property_register        ("border-bottom-color",
1041                                           GTK_TYPE_SYMBOLIC_COLOR,
1042                                           GDK_TYPE_RGBA,
1043                                           GDK_TYPE_RGBA,
1044                                           0,
1045                                           NULL,
1046                                           NULL,
1047                                           color_compute,
1048                                           _gtk_symbolic_color_get_current_color ());
1049   gtk_css_style_property_register        ("border-left-color",
1050                                           GTK_TYPE_SYMBOLIC_COLOR,
1051                                           GDK_TYPE_RGBA,
1052                                           GDK_TYPE_RGBA,
1053                                           0,
1054                                           NULL,
1055                                           NULL,
1056                                           color_compute,
1057                                           _gtk_symbolic_color_get_current_color ());
1058   gtk_css_style_property_register        ("outline-color",
1059                                           GTK_TYPE_SYMBOLIC_COLOR,
1060                                           GDK_TYPE_RGBA,
1061                                           GDK_TYPE_RGBA,
1062                                           0,
1063                                           NULL,
1064                                           NULL,
1065                                           color_compute,
1066                                           _gtk_symbolic_color_get_current_color ());
1067
1068   gtk_css_style_property_register        ("background-repeat",
1069                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1070                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1071                                           GTK_TYPE_CSS_BACKGROUND_REPEAT,
1072                                           0,
1073                                           background_repeat_value_parse,
1074                                           background_repeat_value_print,
1075                                           NULL,
1076                                           GTK_CSS_BACKGROUND_REPEAT | (GTK_CSS_BACKGROUND_REPEAT << GTK_CSS_BACKGROUND_REPEAT_SHIFT));
1077   gtk_css_style_property_register        ("background-image",
1078                                           GTK_TYPE_CSS_IMAGE,
1079                                           GTK_TYPE_CSS_IMAGE,
1080                                           CAIRO_GOBJECT_TYPE_PATTERN,
1081                                           0,
1082                                           css_image_value_parse,
1083                                           css_image_value_print,
1084                                           css_image_value_compute,
1085                                           NULL);
1086
1087   gtk_css_style_property_register        ("border-image-source",
1088                                           GTK_TYPE_CSS_IMAGE,
1089                                           GTK_TYPE_CSS_IMAGE,
1090                                           CAIRO_GOBJECT_TYPE_PATTERN,
1091                                           0,
1092                                           css_image_value_parse,
1093                                           css_image_value_print,
1094                                           css_image_value_compute,
1095                                           NULL);
1096   gtk_css_style_property_register        ("border-image-repeat",
1097                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1098                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1099                                           GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1100                                           0,
1101                                           NULL,
1102                                           NULL,
1103                                           NULL,
1104                                           &border_image_repeat);
1105
1106   /* XXX: The initial value is wrong, it should be 100% */
1107   gtk_css_style_property_register        ("border-image-slice",
1108                                           GTK_TYPE_BORDER,
1109                                           GTK_TYPE_BORDER,
1110                                           GTK_TYPE_BORDER,
1111                                           0,
1112                                           NULL,
1113                                           NULL,
1114                                           NULL,
1115                                           &border_of_ones);
1116   gtk_css_style_property_register        ("border-image-width",
1117                                           GTK_TYPE_BORDER,
1118                                           GTK_TYPE_BORDER,
1119                                           GTK_TYPE_BORDER,
1120                                           0,
1121                                           NULL,
1122                                           NULL,
1123                                           NULL,
1124                                           NULL);
1125   gtk_css_style_property_register        ("engine",
1126                                           GTK_TYPE_THEMING_ENGINE,
1127                                           GTK_TYPE_THEMING_ENGINE,
1128                                           GTK_TYPE_THEMING_ENGINE,
1129                                           0,
1130                                           NULL,
1131                                           NULL,
1132                                           NULL,
1133                                           gtk_theming_engine_load (NULL));
1134   gtk_css_style_property_register        ("transition",
1135                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1136                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1137                                           GTK_TYPE_ANIMATION_DESCRIPTION,
1138                                           0,
1139                                           NULL,
1140                                           NULL,
1141                                           NULL,
1142                                           NULL);
1143
1144   /* Private property holding the binding sets */
1145   gtk_css_style_property_register        ("gtk-key-bindings",
1146                                           G_TYPE_PTR_ARRAY,
1147                                           G_TYPE_PTR_ARRAY,
1148                                           G_TYPE_PTR_ARRAY,
1149                                           0,
1150                                           bindings_value_parse,
1151                                           bindings_value_print,
1152                                           NULL,
1153                                           NULL);
1154 }
1155