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