gtkcssshorthandpropertyimpl.c 48.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * Copyright © 2011 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26
 *
 * Authors: Benjamin Otte <otte@gnome.org>
 */

#include "config.h"

#include "gtkcssshorthandpropertyprivate.h"

#include <cairo-gobject.h>
#include <math.h>

27
#include "gtkcssarrayvalueprivate.h"
28
#include "gtkcssbgsizevalueprivate.h"
29
#include "gtkcssbordervalueprivate.h"
30
#include "gtkcsscolorvalueprivate.h"
31
#include "gtkcsscornervalueprivate.h"
32
#include "gtkcsseasevalueprivate.h"
33
#include "gtkcssenumvalueprivate.h"
34
#include "gtkcssimageprivate.h"
35
#include "gtkcssimagevalueprivate.h"
36
#include "gtkcssnumbervalueprivate.h"
37
#include "gtkcsspositionvalueprivate.h"
38
#include "gtkcssrepeatvalueprivate.h"
39
#include "gtkcssstringvalueprivate.h"
40
#include "gtkcssstylefuncsprivate.h"
41
#include "gtkcssvalueprivate.h"
Matthias Clasen's avatar
Matthias Clasen committed
42
#include "deprecated/gtkstylepropertiesprivate.h"
43
#include "gtktypebuiltins.h"
44 45 46 47 48 49 50 51

/* this is in case round() is not provided by the compiler, 
 * such as in the case of C89 compilers, like MSVC
 */
#include "fallback-c89.c"

/*** PARSING ***/

52 53 54 55
static gboolean
value_is_done_parsing (GtkCssParser *parser)
{
  return _gtk_css_parser_is_eof (parser) ||
56
         _gtk_css_parser_begins_with (parser, ',') ||
57 58 59 60
         _gtk_css_parser_begins_with (parser, ';') ||
         _gtk_css_parser_begins_with (parser, '}');
}

61
static gboolean
62 63 64 65
parse_four_numbers (GtkCssShorthandProperty  *shorthand,
                    GtkCssValue             **values,
                    GtkCssParser             *parser,
                    GtkCssNumberParseFlags    flags)
66 67 68 69 70
{
  guint i;

  for (i = 0; i < 4; i++)
    {
71
      if (!gtk_css_number_value_can_parse (parser))
72 73
        break;

74 75
      values[i] = _gtk_css_number_value_parse (parser, flags);
      if (values[i] == NULL)
76 77 78 79 80 81 82 83 84 85 86
        return FALSE;
    }

  if (i == 0)
    {
      _gtk_css_parser_error (parser, "Expected a length");
      return FALSE;
    }

  for (; i < 4; i++)
    {
87
      values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
88 89 90 91 92
    }

  return TRUE;
}

93
static gboolean
94 95
parse_margin (GtkCssShorthandProperty  *shorthand,
              GtkCssValue             **values,
96
              GtkCssParser             *parser)
97 98 99 100 101 102 103 104 105
{
  return parse_four_numbers (shorthand,
                             values,
                             parser,
                             GTK_CSS_NUMBER_AS_PIXELS
                             | GTK_CSS_PARSE_LENGTH);
}

static gboolean
106 107
parse_padding (GtkCssShorthandProperty  *shorthand,
               GtkCssValue             **values,
108
               GtkCssParser             *parser)
109 110 111 112 113 114 115 116 117 118
{
  return parse_four_numbers (shorthand,
                             values,
                             parser,
                             GTK_CSS_POSITIVE_ONLY
                             | GTK_CSS_NUMBER_AS_PIXELS
                             | GTK_CSS_PARSE_LENGTH);
}

static gboolean
119 120
parse_border_width (GtkCssShorthandProperty  *shorthand,
                    GtkCssValue             **values,
121
                    GtkCssParser             *parser)
122 123 124 125 126 127 128 129 130
{
  return parse_four_numbers (shorthand,
                             values,
                             parser,
                             GTK_CSS_POSITIVE_ONLY
                             | GTK_CSS_NUMBER_AS_PIXELS
                             | GTK_CSS_PARSE_LENGTH);
}

131
static gboolean 
132 133
parse_border_radius (GtkCssShorthandProperty  *shorthand,
                     GtkCssValue             **values,
134
                     GtkCssParser             *parser)
135
{
136
  GtkCssValue *x[4] = { NULL, }, *y[4] = { NULL, };
137 138
  guint i;

139
  for (i = 0; i < 4; i++)
140
    {
141
      if (!gtk_css_number_value_can_parse (parser))
142
        break;
143 144 145 146 147 148 149
      x[i] = _gtk_css_number_value_parse (parser,
                                          GTK_CSS_POSITIVE_ONLY
                                          | GTK_CSS_PARSE_PERCENT
                                          | GTK_CSS_NUMBER_AS_PIXELS
                                          | GTK_CSS_PARSE_LENGTH);
      if (x[i] == NULL)
        goto fail;
150 151 152 153 154
    }

  if (i == 0)
    {
      _gtk_css_parser_error (parser, "Expected a number");
155
      goto fail;
156 157 158
    }

  /* The magic (i - 1) >> 1 below makes it take the correct value
Matthias Clasen's avatar
Matthias Clasen committed
159 160
   * according to spec. Feel free to check the 4 cases
   */
161 162
  for (; i < 4; i++)
    x[i] = _gtk_css_value_ref (x[(i - 1) >> 1]);
163 164 165

  if (_gtk_css_parser_try (parser, "/", TRUE))
    {
166
      for (i = 0; i < 4; i++)
167
        {
168
          if (!gtk_css_number_value_can_parse (parser))
169
            break;
170 171 172 173 174 175 176
          y[i] = _gtk_css_number_value_parse (parser,
                                              GTK_CSS_POSITIVE_ONLY
                                              | GTK_CSS_PARSE_PERCENT
                                              | GTK_CSS_NUMBER_AS_PIXELS
                                              | GTK_CSS_PARSE_LENGTH);
          if (y[i] == NULL)
            goto fail;
177 178 179 180 181
        }

      if (i == 0)
        {
          _gtk_css_parser_error (parser, "Expected a number");
182
          goto fail;
183 184
        }

185 186
      for (; i < 4; i++)
        y[i] = _gtk_css_value_ref (y[(i - 1) >> 1]);
187 188 189
    }
  else
    {
190 191
      for (i = 0; i < 4; i++)
        y[i] = _gtk_css_value_ref (x[i]);
192 193
    }

194
  for (i = 0; i < 4; i++)
195
    {
196
      values[i] = _gtk_css_corner_value_new (x[i], y[i]);
197 198 199
    }

  return TRUE;
200 201 202 203 204 205 206 207 208 209

fail:
  for (i = 0; i < 4; i++)
    {
      if (x[i])
        _gtk_css_value_unref (x[i]);
      if (y[i])
        _gtk_css_value_unref (y[i]);
    }
  return FALSE;
210 211
}

212
static gboolean 
213 214
parse_border_color (GtkCssShorthandProperty  *shorthand,
                    GtkCssValue             **values,
215
                    GtkCssParser             *parser)
216 217 218 219 220
{
  guint i;

  for (i = 0; i < 4; i++)
    {
221
      values[i] = _gtk_css_color_value_parse (parser);
222
      if (values[i] == NULL)
223
        return FALSE;
224

225
      if (value_is_done_parsing (parser))
226 227 228 229 230
        break;
    }

  for (i++; i < 4; i++)
    {
231
      values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
232 233 234 235 236
    }

  return TRUE;
}

237
static gboolean
238 239
parse_border_style (GtkCssShorthandProperty  *shorthand,
                    GtkCssValue             **values,
240
                    GtkCssParser             *parser)
241 242 243 244 245
{
  guint i;

  for (i = 0; i < 4; i++)
    {
246 247
      values[i] = _gtk_css_border_style_value_try_parse (parser);
      if (values[i] == NULL)
248 249 250 251 252 253 254 255 256
        break;
    }

  if (i == 0)
    {
      _gtk_css_parser_error (parser, "Expected a border style");
      return FALSE;
    }

257 258
  for (; i < 4; i++)
    values[i] = _gtk_css_value_ref (values[(i - 1) >> 1]);
259 260 261 262

  return TRUE;
}

263
static gboolean
264 265
parse_border_image (GtkCssShorthandProperty  *shorthand,
                    GtkCssValue             **values,
266
                    GtkCssParser             *parser)
267
{
268
  do
269
    {
270 271 272 273 274
      if (values[0] == NULL &&
          (_gtk_css_parser_has_prefix (parser, "none") ||
           _gtk_css_image_can_parse (parser)))
        {
          GtkCssImage *image;
275

276 277 278 279
          if (_gtk_css_parser_try (parser, "none", TRUE))
            image = NULL;
          else
            {
280
              image = _gtk_css_image_new_parse (parser);
281 282 283
              if (image == NULL)
                return FALSE;
            }
284

285 286 287 288 289 290 291 292 293
          values[0] = _gtk_css_image_value_new (image);
        }
      else if (values[3] == NULL &&
               (values[3] = _gtk_css_border_repeat_value_try_parse (parser)))
        {
          /* please move along */
        }
      else if (values[1] == NULL)
        {
294 295 296 297 298 299 300
          values[1] = _gtk_css_border_value_parse (parser,
                                                   GTK_CSS_PARSE_PERCENT
                                                   | GTK_CSS_PARSE_NUMBER
                                                   | GTK_CSS_POSITIVE_ONLY,
                                                   FALSE,
                                                   TRUE);
          if (values[1] == NULL)
301
            return FALSE;
302

303 304
          if (_gtk_css_parser_try (parser, "/", TRUE))
            {
305 306 307 308 309 310 311 312
              values[2] = _gtk_css_border_value_parse (parser,
                                                       GTK_CSS_PARSE_PERCENT
                                                       | GTK_CSS_PARSE_LENGTH
                                                       | GTK_CSS_PARSE_NUMBER
                                                       | GTK_CSS_POSITIVE_ONLY,
                                                       TRUE,
                                                       FALSE);
              if (values[2] == NULL)
313 314 315 316 317 318 319
                return FALSE;
            }
        }
      else
        {
          /* We parsed everything and there's still stuff left?
           * Pretend we didn't notice and let the normal code produce
Matthias Clasen's avatar
Matthias Clasen committed
320 321
           * a 'junk at end of value' error
           */
322 323 324 325
          break;
        }
    }
  while (!value_is_done_parsing (parser));
326

327
  return TRUE;
328 329
}

330
static gboolean
331 332
parse_border_side (GtkCssShorthandProperty  *shorthand,
                   GtkCssValue             **values,
333
                   GtkCssParser             *parser)
334 335 336
{
  do
  {
337
    if (values[0] == NULL &&
338
        gtk_css_number_value_can_parse (parser))
339
      {
340 341 342 343 344
        values[0] = _gtk_css_number_value_parse (parser,
                                                 GTK_CSS_POSITIVE_ONLY
                                                 | GTK_CSS_NUMBER_AS_PIXELS
                                                 | GTK_CSS_PARSE_LENGTH);
        if (values[0] == NULL)
345
          return FALSE;
346
      }
347
    else if (values[1] == NULL &&
348
             (values[1] = _gtk_css_border_style_value_try_parse (parser)))
349
      {
350
        /* Nothing to do */
351
      }
352
    else if (values[2] == NULL)
353
      {
354
        values[2] = _gtk_css_color_value_parse (parser);
355
        if (values[2] == NULL)
356 357
          return FALSE;
      }
358 359 360 361
    else
      {
        /* We parsed and there's still stuff left?
         * Pretend we didn't notice and let the normal code produce
Matthias Clasen's avatar
Matthias Clasen committed
362 363
         * a 'junk at end of value' error
         */
364 365
        break;
      }
366 367 368 369 370 371
  }
  while (!value_is_done_parsing (parser));

  return TRUE;
}

372
static gboolean
373 374
parse_border (GtkCssShorthandProperty  *shorthand,
              GtkCssValue             **values,
375
              GtkCssParser             *parser)
376 377 378
{
  do
  {
379
    if (values[0] == NULL &&
380
        gtk_css_number_value_can_parse (parser))
381
      {
382 383 384 385 386
        values[0] = _gtk_css_number_value_parse (parser,
                                                 GTK_CSS_POSITIVE_ONLY
                                                 | GTK_CSS_NUMBER_AS_PIXELS
                                                 | GTK_CSS_PARSE_LENGTH);
        if (values[0] == NULL)
387
          return FALSE;
388 389 390
        values[1] = _gtk_css_value_ref (values[0]);
        values[2] = _gtk_css_value_ref (values[0]);
        values[3] = _gtk_css_value_ref (values[0]);
391
      }
392
    else if (values[4] == NULL &&
393
             (values[4] = _gtk_css_border_style_value_try_parse (parser)))
394
      {
395 396 397
        values[5] = _gtk_css_value_ref (values[4]);
        values[6] = _gtk_css_value_ref (values[4]);
        values[7] = _gtk_css_value_ref (values[4]);
398 399 400
      }
    else if (!G_IS_VALUE (&values[8]))
      {
401
        values[8] = _gtk_css_color_value_parse (parser);
402
        if (values[8] == NULL)
403 404
          return FALSE;

405 406 407
        values[9] = _gtk_css_value_ref (values[8]);
        values[10] = _gtk_css_value_ref (values[8]);
        values[11] = _gtk_css_value_ref (values[8]);
408 409 410 411 412
      }
    else
      {
        /* We parsed everything and there's still stuff left?
         * Pretend we didn't notice and let the normal code produce
Matthias Clasen's avatar
Matthias Clasen committed
413 414
         * a 'junk at end of value' error
         */
415 416 417 418 419 420
        break;
      }
  }
  while (!value_is_done_parsing (parser));

  /* Note that border-image values are not set: according to the spec
Matthias Clasen's avatar
Matthias Clasen committed
421 422
   * they just need to be reset when using the border shorthand
   */
423 424 425 426

  return TRUE;
}

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
static gboolean
parse_font_with_pango (GtkCssShorthandProperty  *shorthand,
                       GtkCssValue             **values,
                       GtkCssParser             *parser)
{
  PangoFontDescription *desc;
  guint mask;
  char *str;

  str = _gtk_css_parser_read_value (parser);
  if (str == NULL)
    return FALSE;

  desc = pango_font_description_from_string (str);
  g_free (str);

  mask = pango_font_description_get_set_fields (desc);

  if (mask & PANGO_FONT_MASK_FAMILY)
    {
      values[0] = _gtk_css_array_value_new (_gtk_css_string_value_new (pango_font_description_get_family (desc)));
    }
  if (mask & PANGO_FONT_MASK_STYLE)
    {
      values[1] = _gtk_css_font_style_value_new (pango_font_description_get_style (desc));
    }
  if (mask & PANGO_FONT_MASK_VARIANT)
    {
      values[2] = _gtk_css_font_variant_value_new (pango_font_description_get_variant (desc));
    }
  if (mask & PANGO_FONT_MASK_WEIGHT)
    {
      values[3] = _gtk_css_font_weight_value_new (pango_font_description_get_weight (desc));
    }
  if (mask & PANGO_FONT_MASK_STRETCH)
    {
      values[4] = _gtk_css_font_stretch_value_new (pango_font_description_get_stretch (desc));
    }
  if (mask & PANGO_FONT_MASK_SIZE)
    {
      values[5] = _gtk_css_number_value_new ((double) pango_font_description_get_size (desc) / PANGO_SCALE, GTK_CSS_PX);
    }

  pango_font_description_free (desc);

  return TRUE;
}

475
static gboolean
476 477
parse_font (GtkCssShorthandProperty  *shorthand,
            GtkCssValue             **values,
478
            GtkCssParser             *parser)
479
{
480
  gboolean parsed_one;
481

482 483 484
  do
    {
      parsed_one = FALSE;
485

486 487 488 489 490
      if (values[1] == NULL)
        {
          values[1] = _gtk_css_font_style_value_try_parse (parser);
          parsed_one = parsed_one || values[1] != NULL;
        }
491

492 493 494 495 496
      if (values[2] == NULL)
        {
          values[2] = _gtk_css_font_variant_value_try_parse (parser);
          parsed_one = parsed_one || values[2] != NULL;
        }
497

498 499 500 501 502 503 504 505
      if (values[3] == NULL)
        {
          values[3] = _gtk_css_font_weight_value_try_parse (parser);
          parsed_one = parsed_one || values[3] != NULL;
        }

      if (values[4] == NULL)
        {
Matthias Clasen's avatar
Matthias Clasen committed
506
          values[4] = _gtk_css_font_stretch_value_try_parse (parser);
507 508
          parsed_one = parsed_one || values[4] != NULL;
        }
509
    }
510
  while (parsed_one && !value_is_done_parsing (parser));
511

512
  values[5] = gtk_css_font_size_value_parse (parser);
513 514 515 516 517 518 519 520 521 522 523 524 525

  if (values[1] == NULL && values[2] == NULL && values[3] == NULL &&
      values[4] == NULL && values[5] == NULL)
    {
      if (parse_font_with_pango (shorthand, values, parser))
        {
          _gtk_css_parser_error_full (parser,
                                      GTK_CSS_PROVIDER_ERROR_DEPRECATED,
                                      "Using Pango syntax for the font: style property is deprecated; please use CSS syntax");
          return TRUE;
        }
    }

526
  values[0] = gtk_css_font_family_value_parse (parser);
527

528
  return values[0] != NULL && values[5] != NULL;
529 530
}

531
static gboolean
532 533 534
parse_one_background (GtkCssShorthandProperty  *shorthand,
                      GtkCssValue             **values,
                      GtkCssParser             *parser)
535
{
536
  GtkCssValue *value = NULL;
537

538 539 540
  do
    {
      /* the image part */
541
      if (values[0] == NULL &&
542 543 544 545 546 547 548 549 550
          (_gtk_css_parser_has_prefix (parser, "none") ||
           _gtk_css_image_can_parse (parser)))
        {
          GtkCssImage *image;

          if (_gtk_css_parser_try (parser, "none", TRUE))
            image = NULL;
          else
            {
551
              image = _gtk_css_image_new_parse (parser);
552 553 554 555
              if (image == NULL)
                return FALSE;
            }

556 557 558
          values[0] = _gtk_css_image_value_new (image);
        }
      else if (values[1] == NULL &&
Matthias Clasen's avatar
Matthias Clasen committed
559
               (value = _gtk_css_position_value_try_parse (parser)))
560 561 562 563 564 565 566 567 568 569
        {
          values[1] = value;
          value = NULL;

          if (_gtk_css_parser_try (parser, "/", TRUE) &&
              (value = _gtk_css_bg_size_value_parse (parser)))
            {
              values[2] = value;
              value = NULL;
            }
570
        }
571
      else if (values[3] == NULL &&
572
               (value = _gtk_css_background_repeat_value_try_parse (parser)))
573
        {
574
          values[3] = value;
575
          value = NULL;
576
        }
577
      else if ((values[4] == NULL || values[5] == NULL) &&
578
               (value = _gtk_css_area_value_try_parse (parser)))
579
        {
580
          values[4] = value;
581

582
          if (values[5] == NULL)
583
            {
584 585
              values[5] = values[4];
              values[4] = NULL;
586
            }
587
          value = NULL;
588
        }
589
      else if (values[6] == NULL)
590
        {
591
          value = _gtk_css_color_value_parse (parser);
592
          if (value == NULL)
593 594 595 596
            values[6] = _gtk_css_value_ref (_gtk_css_style_property_get_initial_value 
                                            (_gtk_css_shorthand_property_get_subproperty (shorthand, 6)));
          else
            values[6] = value;
597

598 599
          value = NULL;
        }
600 601 602 603
      else
        {
          /* We parsed everything and there's still stuff left?
           * Pretend we didn't notice and let the normal code produce
Matthias Clasen's avatar
Matthias Clasen committed
604 605
           * a 'junk at end of value' error
           */
606 607 608 609 610
          break;
        }
    }
  while (!value_is_done_parsing (parser));

611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
  if (values[5] != NULL && values[4] == NULL)
    values[4] = _gtk_css_value_ref (values[5]);

  return TRUE;
}

static gboolean
parse_background (GtkCssShorthandProperty  *shorthand,
                  GtkCssValue             **values,
                  GtkCssParser             *parser)
{
  GtkCssValue *step_values[7];
  GPtrArray *arrays[6];
  guint i;

  for (i = 0; i < 6; i++)
    {
      arrays[i] = g_ptr_array_new ();
      step_values[i] = NULL;
    }
  
  step_values[6] = NULL;

  do {
    if (!parse_one_background (shorthand, step_values, parser))
      {
        for (i = 0; i < 6; i++)
          {
            g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
            g_ptr_array_unref (arrays[i]);
          }
642
        return FALSE;
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
      }

      for (i = 0; i < 6; i++)
        {
          if (step_values[i] == NULL)
            {
              GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
                                         _gtk_css_shorthand_property_get_subproperty (shorthand, i));
              step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
            }

          g_ptr_array_add (arrays[i], step_values[i]);
          step_values[i] = NULL;
        }
  } while (_gtk_css_parser_try (parser, ",", TRUE));

  for (i = 0; i < 6; i++)
    {
      values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
      g_ptr_array_unref (arrays[i]);
    }

  values[6] = step_values[6];

667 668 669
  return TRUE;
}

670 671 672
static gboolean
parse_one_transition (GtkCssShorthandProperty  *shorthand,
                      GtkCssValue             **values,
673
                      GtkCssParser             *parser)
674 675 676 677 678
{
  do
    {
      /* the image part */
      if (values[2] == NULL &&
679
          gtk_css_number_value_can_parse (parser) && !_gtk_css_parser_begins_with (parser, '-'))
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
        {
          GtkCssValue *number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME);

          if (number == NULL)
            return FALSE;

          if (values[1] == NULL)
            values[1] = number;
          else
            values[2] = number;
        }
      else if (values[3] == NULL &&
               _gtk_css_ease_value_can_parse (parser))
        {
          values[3] = _gtk_css_ease_value_parse (parser);

          if (values[3] == NULL)
            return FALSE;
        }
      else if (values[0] == NULL)
        {
          values[0] = _gtk_css_ident_value_try_parse (parser);
          if (values[0] == NULL)
            {
              _gtk_css_parser_error (parser, "Unknown value for property");
              return FALSE;
            }

        }
      else
        {
          /* We parsed everything and there's still stuff left?
           * Pretend we didn't notice and let the normal code produce
Matthias Clasen's avatar
Matthias Clasen committed
713 714
           * a 'junk at end of value' error
           */
715 716 717 718 719 720 721 722 723 724 725
          break;
        }
    }
  while (!value_is_done_parsing (parser));

  return TRUE;
}

static gboolean
parse_transition (GtkCssShorthandProperty  *shorthand,
                  GtkCssValue             **values,
726
                  GtkCssParser             *parser)
727 728 729 730 731 732 733 734 735 736 737 738
{
  GtkCssValue *step_values[4];
  GPtrArray *arrays[4];
  guint i;

  for (i = 0; i < 4; i++)
    {
      arrays[i] = g_ptr_array_new ();
      step_values[i] = NULL;
    }

  do {
739
    if (!parse_one_transition (shorthand, step_values, parser))
740 741 742 743 744 745
      {
        for (i = 0; i < 4; i++)
          {
            g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
            g_ptr_array_unref (arrays[i]);
          }
746
        return FALSE;
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
      }

      for (i = 0; i < 4; i++)
        {
          if (step_values[i] == NULL)
            {
              GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
                                         _gtk_css_shorthand_property_get_subproperty (shorthand, i));
              step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
            }

          g_ptr_array_add (arrays[i], step_values[i]);
          step_values[i] = NULL;
        }
  } while (_gtk_css_parser_try (parser, ",", TRUE));

  for (i = 0; i < 4; i++)
    {
      values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
      g_ptr_array_unref (arrays[i]);
    }

  return TRUE;
}

772 773 774 775 776 777 778 779 780 781 782 783
static gboolean
parse_one_animation (GtkCssShorthandProperty  *shorthand,
                     GtkCssValue             **values,
                     GtkCssParser             *parser)
{
  do
    {
      if (values[1] == NULL && _gtk_css_parser_try (parser, "infinite", TRUE))
        {
          values[1] = _gtk_css_number_value_new (HUGE_VAL, GTK_CSS_NUMBER);
        }
      else if ((values[1] == NULL || values[3] == NULL) &&
784
               gtk_css_number_value_can_parse (parser))
785 786 787 788 789 790 791
        {
          GtkCssValue *value;
          
          value = _gtk_css_number_value_parse (parser,
                                               GTK_CSS_POSITIVE_ONLY
                                               | (values[1] == NULL ? GTK_CSS_PARSE_NUMBER : 0)
                                               | (values[3] == NULL ? GTK_CSS_PARSE_TIME : 0));
792 793 794
          if (value == NULL)
            return FALSE;

795
          if (gtk_css_number_value_get_dimension (value) == GTK_CSS_DIMENSION_NUMBER)
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
            values[1] = value;
          else if (values[2] == NULL)
            values[2] = value;
          else
            values[3] = value;
        }
      else if (values[4] == NULL &&
               _gtk_css_ease_value_can_parse (parser))
        {
          values[4] = _gtk_css_ease_value_parse (parser);

          if (values[4] == NULL)
            return FALSE;
        }
      else if (values[5] == NULL &&
               (values[5] = _gtk_css_direction_value_try_parse (parser)))
        {
          /* nothing to do */
        }
      else if (values[6] == NULL &&
               (values[6] = _gtk_css_fill_mode_value_try_parse (parser)))
        {
          /* nothing to do */
        }
      else if (values[0] == NULL &&
               (values[0] = _gtk_css_ident_value_try_parse (parser)))
        {
          /* nothing to do */
          /* keep in mind though that this needs to come last as fill modes, directions
           * etc are valid idents */
        }
      else
        {
          /* We parsed everything and there's still stuff left?
           * Pretend we didn't notice and let the normal code produce
           * a 'junk at end of value' error */
          break;
        }
    }
  while (!value_is_done_parsing (parser));

  return TRUE;
}

static gboolean
parse_animation (GtkCssShorthandProperty  *shorthand,
                 GtkCssValue             **values,
                 GtkCssParser             *parser)
{
  GtkCssValue *step_values[7];
846
  GPtrArray *arrays[7];
847 848
  guint i;

849
  for (i = 0; i < 7; i++)
850 851 852 853 854 855 856 857
    {
      arrays[i] = g_ptr_array_new ();
      step_values[i] = NULL;
    }
  
  do {
    if (!parse_one_animation (shorthand, step_values, parser))
      {
858
        for (i = 0; i < 7; i++)
859 860 861 862
          {
            g_ptr_array_set_free_func (arrays[i], (GDestroyNotify) _gtk_css_value_unref);
            g_ptr_array_unref (arrays[i]);
          }
863
        return FALSE;
864 865
      }

866
      for (i = 0; i < 7; i++)
867 868 869 870 871 872 873 874 875 876 877 878 879
        {
          if (step_values[i] == NULL)
            {
              GtkCssValue *initial = _gtk_css_style_property_get_initial_value (
                                         _gtk_css_shorthand_property_get_subproperty (shorthand, i));
              step_values[i] = _gtk_css_value_ref (_gtk_css_array_value_get_nth (initial, 0));
            }

          g_ptr_array_add (arrays[i], step_values[i]);
          step_values[i] = NULL;
        }
  } while (_gtk_css_parser_try (parser, ",", TRUE));

880
  for (i = 0; i < 7; i++)
881 882 883 884 885 886 887 888
    {
      values[i] = _gtk_css_array_value_new_from_array ((GtkCssValue **) arrays[i]->pdata, arrays[i]->len);
      g_ptr_array_unref (arrays[i]);
    }

  return TRUE;
}

889 890 891 892 893 894 895 896 897 898 899 900 901
static gboolean
parse_text_decoration (GtkCssShorthandProperty  *shorthand,
                       GtkCssValue             **values,
                       GtkCssParser             *parser)
{
  do
  {
    if (values[0] == NULL &&
        (values[0] = _gtk_css_text_decoration_line_value_try_parse (parser)))
      {
        if (values[0] == NULL)
          return FALSE;
      }
902 903
    else if (values[1] == NULL &&
        (values[1] = _gtk_css_text_decoration_style_value_try_parse (parser)))
904 905 906 907
      {
        if (values[1] == NULL)
          return FALSE;
      }
908 909 910 911 912 913
    else if (values[2] == NULL)
      {
        values[2] = _gtk_css_color_value_parse (parser);
        if (values[2] == NULL)
          return FALSE;
      }
914 915 916 917 918 919 920 921 922 923 924 925 926
    else
      {
        /* We parsed and there's still stuff left?
         * Pretend we didn't notice and let the normal code produce
         * a 'junk at end of value' error */
        break;
      }
  }
  while (!value_is_done_parsing (parser));

  return TRUE;
}

927 928 929 930 931 932 933 934 935
static gboolean
parse_all (GtkCssShorthandProperty  *shorthand,
           GtkCssValue             **values,
           GtkCssParser             *parser)
{
  _gtk_css_parser_error (parser, "The 'all' property can only be set to 'initial', 'inherit' or 'unset'");
  return FALSE;
}

936 937
/*** PACKING ***/

938
static void
939
unpack_border (GtkCssShorthandProperty *shorthand,
940 941 942
               GtkStyleProperties      *props,
               GtkStateFlags            state,
               const GValue            *value)
943
{
944
  GValue v = G_VALUE_INIT;
945 946
  GtkBorder *border = g_value_get_boxed (value);

947 948 949 950 951 952 953 954 955 956 957 958
  g_value_init (&v, G_TYPE_INT);

  g_value_set_int (&v, border->top);
  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 0)), props, state, &v);
  g_value_set_int (&v, border->right);
  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 1)), props, state, &v);
  g_value_set_int (&v, border->bottom);
  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 2)), props, state, &v);
  g_value_set_int (&v, border->left);
  _gtk_style_property_assign (GTK_STYLE_PROPERTY (_gtk_css_shorthand_property_get_subproperty (shorthand, 3)), props, state, &v);

  g_value_unset (&v);
959 960
}

961
static void
962
pack_border (GtkCssShorthandProperty *shorthand,
963
             GValue                  *value,
964 965
             GtkStyleQueryFunc        query_func,
             gpointer                 query_data)
966
{
967
  GtkCssStyleProperty *prop;
968
  GtkBorder border;
969
  GValue v;
970 971

  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
972 973 974 975
  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
  border.top = g_value_get_int (&v);
  g_value_unset (&v);

976
  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1);
977 978 979 980
  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
  border.right = g_value_get_int (&v);
  g_value_unset (&v);

981
  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2);
982 983 984 985
  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
  border.bottom = g_value_get_int (&v);
  g_value_unset (&v);

986
  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3);
987 988 989
  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop), &v, query_func, query_data);
  border.left = g_value_get_int (&v);
  g_value_unset (&v);
990

991 992
  g_value_init (value, GTK_TYPE_BORDER);
  g_value_set_boxed (value, &border);
993 994
}

995
static void
996
unpack_border_radius (GtkCssShorthandProperty *shorthand,
997 998 999
                      GtkStyleProperties      *props,
                      GtkStateFlags            state,
                      const GValue            *value)
1000
{
1001
  GtkCssValue *css_value;
1002
  guint i;
1003
  
1004 1005
  css_value = _gtk_css_corner_value_new (_gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX),
                                         _gtk_css_number_value_new (g_value_get_int (value), GTK_CSS_PX));
1006

1007
  for (i = 0; i < 4; i++)
1008 1009 1010 1011
    _gtk_style_properties_set_property_by_property (props,
                                                    _gtk_css_shorthand_property_get_subproperty (shorthand, i),
                                                    state,
                                                    css_value);
1012

1013
  _gtk_css_value_unref (css_value);
1014 1015
}

1016
static void
1017
pack_border_radius (GtkCssShorthandProperty *shorthand,
1018
                    GValue                  *value,
1019 1020
                    GtkStyleQueryFunc        query_func,
                    gpointer                 query_data)
1021
{
1022
  GtkCssStyleProperty *prop;
1023
  GtkCssValue *v;
1024
  int i = 0;
1025

1026 1027 1028
  prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius"));
  v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data);
  if (v)
1029
    i = _gtk_css_corner_value_get_x (v, 100);
1030

1031 1032
  g_value_init (value, G_TYPE_INT);
  g_value_set_int (value, i);
1033 1034
}

1035
static void
1036
unpack_font_description (GtkCssShorthandProperty *shorthand,
1037 1038 1039
                         GtkStyleProperties      *props,
                         GtkStateFlags            state,
                         const GValue            *value)
1040
{
1041
  GtkStyleProperty *prop;
1042 1043
  PangoFontDescription *description;
  PangoFontMask mask;
1044
  GValue v = G_VALUE_INIT;
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
  
  /* For backwards compat, we only unpack values that are indeed set.
   * For strict CSS conformance we need to unpack all of them.
   * Note that we do set all of them in the parse function, so it
   * will not have effects when parsing CSS files. It will though
   * for custom style providers.
   */

  description = g_value_get_boxed (value);

  if (description)
    mask = pango_font_description_get_set_fields (description);
  else
    mask = 0;

  if (mask & PANGO_FONT_MASK_FAMILY)
    {
      GPtrArray *strv = g_ptr_array_new ();

      g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
      g_ptr_array_add (strv, NULL);
1066 1067 1068 1069 1070 1071
      g_value_init (&v, G_TYPE_STRV);
      g_value_take_boxed (&v, g_ptr_array_free (strv, FALSE));

      prop = _gtk_style_property_lookup ("font-family");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
1072 1073 1074 1075
    }

  if (mask & PANGO_FONT_MASK_STYLE)
    {
1076 1077 1078 1079 1080 1081
      g_value_init (&v, PANGO_TYPE_STYLE);
      g_value_set_enum (&v, pango_font_description_get_style (description));

      prop = _gtk_style_property_lookup ("font-style");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
1082 1083 1084 1085
    }

  if (mask & PANGO_FONT_MASK_VARIANT)
    {
1086 1087 1088 1089 1090 1091
      g_value_init (&v, PANGO_TYPE_VARIANT);
      g_value_set_enum (&v, pango_font_description_get_variant (description));

      prop = _gtk_style_property_lookup ("font-variant");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
1092 1093 1094 1095
    }

  if (mask & PANGO_FONT_MASK_WEIGHT)
    {
1096 1097 1098 1099 1100 1101
      g_value_init (&v, PANGO_TYPE_WEIGHT);
      g_value_set_enum (&v, pango_font_description_get_weight (description));

      prop = _gtk_style_property_lookup ("font-weight");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
1102 1103
    }

1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
  if (mask & PANGO_FONT_MASK_STRETCH)
    {
      g_value_init (&v, PANGO_TYPE_STRETCH);
      g_value_set_enum (&v, pango_font_description_get_stretch (description));

      prop = _gtk_style_property_lookup ("font-stretch");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
    }

1114 1115
  if (mask & PANGO_FONT_MASK_SIZE)
    {
1116
      double size;
1117

1118 1119 1120
      g_value_init (&v, G_TYPE_DOUBLE);
      size = pango_font_description_get_size (description) / PANGO_SCALE;
      if (!pango_font_description_get_size_is_absolute (description))
1121
        size = size * gdk_screen_get_resolution (gdk_screen_get_default ()) / 72.0;
1122
      g_value_set_double (&v, size);
1123 1124 1125 1126
      prop = _gtk_style_property_lookup ("font-size");
      _gtk_style_property_assign (prop, props, state, &v);
      g_value_unset (&v);
    }
1127 1128
}

1129
static void
1130
pack_font_description (GtkCssShorthandProperty *shorthand,
1131
                       GValue                  *value,
1132 1133
                       GtkStyleQueryFunc        query_func,
                       gpointer                 query_data)
1134 1135
{
  PangoFontDescription *description;
1136
  GtkCssValue *v;
1137
  double dpi;
1138 1139 1140

  description = pango_font_description_new ();

1141 1142 1143 1144
  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data);
  if (v)
    {
      /* xxx: Can we set all the families here somehow? */
1145
      pango_font_description_set_family (description, _gtk_css_string_value_get (_gtk_css_array_value_get_nth (v, 0)));
1146 1147
    }

1148 1149
  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("-gtk-dpi"))), query_data);
  dpi = _gtk_css_number_value_get (v, 96);
1150 1151
  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data);
  if (v)
1152
    pango_font_description_set_size (description, round (_gtk_css_number_value_get (v, 100) * PANGO_SCALE * 72 / dpi));
1153 1154 1155

  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data);
  if (v)
1156
    pango_font_description_set_style (description, _gtk_css_font_style_value_get (v));
1157 1158 1159

  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data);
  if (v)
1160
    pango_font_description_set_variant (description, _gtk_css_font_variant_value_get (v));
1161 1162 1163

  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data);
  if (v)
1164
    pango_font_description_set_weight (description, _gtk_css_font_weight_value_get (v));
1165

1166 1167 1168 1169
  v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-stretch"))), query_data);
  if (v)
    pango_font_description_set_stretch (description, _gtk_css_font_stretch_value_get (v));

1170 1171
  g_value_init (value, PANGO_TYPE_FONT_DESCRIPTION);
  g_value_take_boxed (value, description);
1172 1173
}

1174
static void
1175
unpack_to_everything (GtkCssShorthandProperty *shorthand,
1176 1177 1178
                      GtkStyleProperties      *props,
                      GtkStateFlags            state,
                      const GValue            *value)
1179
{
1180 1181
  GtkCssStyleProperty *prop;
  guint i, n;
1182
  
1183
  n = _gtk_css_shorthand_property_get_n_subproperties (shorthand);
1184

1185 1186 1187
  for (i = 0; i < n; i++)
    {
      prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);
1188
      _gtk_style_property_assign (GTK_STYLE_PROPERTY (prop), props, state, value);
1189
    }
1190 1191
}

1192
static void
1193
pack_first_element (GtkCssShorthandProperty *shorthand,
1194
                    GValue                  *value,
1195 1196
                    GtkStyleQueryFunc        query_func,
                    gpointer                 query_data)
1197
{
1198 1199 1200 1201 1202 1203
  GtkCssStyleProperty *prop;

  /* NB: This is a fallback for properties that originally were
   * not used as shorthand. We just pick the first subproperty
   * as a representative.
   * Lesson learned: Don't query the shorthand, query the 
1204
   * real properties instead. */
1205 1206 1207 1208 1209
  prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
  _gtk_style_property_query (GTK_STYLE_PROPERTY (prop),
                             value,
                             query_func,
                             query_data);
1210 1211
}

1212
static void
1213 1214 1215 1216
_gtk_css_shorthand_property_register (const char                        *name,
                                      GType                              value_type,
                                      const char                       **subproperties,
                                      GtkCssShorthandPropertyParseFunc   parse_func,
1217 1218
                                      GtkCssShorthandPropertyAssignFunc  assign_func,
                                      GtkCssShorthandPropertyQueryFunc   query_func)
1219
{
1220
  GtkCssShorthandProperty *node;
1221 1222

  node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
1223 1224
                       "name", name,
                       "value-type", value_type,
1225
                       "subproperties", subproperties,
1226 1227
                       NULL);

1228 1229 1230
  node->parse = parse_func;
  node->assign = assign_func;
  node->query = query_func;
1231 1232
}

1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
/* NB: return value is transfer: container */
static const char **
get_all_subproperties (void)
{
  const char **properties;
  guint i, n;

  n = _gtk_css_style_property_get_n_properties ();
  properties = g_new (const char *, n + 1);
  properties[n] = NULL;

  for (i = 0; i < n; i++)
    {
      properties[i] = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i)));
    }

  return properties;
}

1252 1253 1254
void
_gtk_css_shorthand_property_init_properties (void)
{
1255
  /* The order is important here, be careful when changing it */
1256
  const char *font_subproperties[] = { "font-family", "font-style", "font-variant", "font-weight", "font-stretch", "font-size", NULL };
1257 1258 1259 1260 1261 1262
  const char *margin_subproperties[] = { "margin-top", "margin-right", "margin-bottom", "margin-left", NULL };
  const char *padding_subproperties[] = { "padding-top", "padding-right", "padding-bottom", "padding-left", NULL };
  const char *border_width_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width", NULL };
  const char *border_radius_subproperties[] = { "border-top-left-radius", "border-top-right-radius",
                                                "border-bottom-right-radius", "border-bottom-left-radius", NULL };
  const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
1263
  const char *border_style_subproperties[] = { "border-top-style", "border-right-style", "border-bottom-style", "border-left-style", NULL };
1264
  const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
1265 1266 1267 1268
  const char *border_top_subproperties[] = { "border-top-width", "border-top-style", "border-top-color", NULL };
  const char *border_right_subproperties[] = { "border-right-width", "border-right-style", "border-right-color", NULL };
  const char *border_bottom_subproperties[] = { "border-bottom-width", "border-bottom-style", "border-bottom-color", NULL };
  const char *border_left_subproperties[] = { "border-left-width", "border-left-style", "border-left-color", NULL };
1269 1270 1271 1272
  const char *border_subproperties[] = { "border-top-width", "border-right-width", "border-bottom-width", "border-left-width",
                                         "border-top-style", "border-right-style", "border-bottom-style", "border-left-style",
                                         "border-top-color", "border-right-color", "border-bottom-color", "border-left-color",
                                         "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
1273
  const char *outline_subproperties[] = { "outline-width", "outline-style", "outline-color", NULL };
1274 1275
  const char *outline_radius_subproperties[] = { "outline-top-left-radius", "outline-top-right-radius",
                                                 "outline-bottom-right-radius", "outline-bottom-left-radius", NULL };
1276
  const char *background_subproperties[] = { "background-image", "background-position", "background-size", "background-repeat", "background-clip", "background-origin",
1277
                                             "background-color", NULL };
1278
  const char *transition_subproperties[] = { "transition-property", "transition-duration", "transition-delay", "transition-timing-function", NULL };
1279 1280
  const char *animation_subproperties[] = { "animation-name", "animation-iteration-count", "animation-duration", "animation-delay", 
                                            "animation-timing-function", "animation-direction", "animation-fill-mode", NULL };
1281
  const char *text_decoration_subproperties[] = { "text-decoration-line", "text-decoration-style", "text-decoration-color", NULL };
1282

1283 1284
  const char **all_subproperties;

1285 1286
  _gtk_css_shorthand_property_register   ("font",
                                          PANGO_TYPE_FONT_DESCRIPTION,
1287
                                          font_subproperties,
1288
                                          parse_font,
1289
                                          unpack_font_description,
1290
                                          pack_font_description);
1291 1292
  _gtk_css_shorthand_property_register   ("margin",
                                          GTK_TYPE_BORDER,
1293
                                          margin_subproperties,
1294
                                          parse_margin,
1295
                                          unpack_border,
1296
                                          pack_border);
1297 1298
  _gtk_css_shorthand_property_register   ("padding",
                                          GTK_TYPE_BORDER,
1299
                                          padding_subproperties,
1300
                                          parse_padding,
1301
                                          unpack_border,
1302
                                          pack_border);
1303 1304
  _gtk_css_shorthand_property_register   ("border-width",
                                          GTK_TYPE_BORDER,
1305
                                          border_width_subproperties,
1306
                                          parse_border_width,
1307
                                          unpack_border,
1308
                                          pack_border);
1309 1310
  _gtk_css_shorthand_property_register   ("border-radius",
                                          G_TYPE_INT,
1311
                                          border_radius_subproperties,
1312
                                          parse_border_radius,
1313
                                          unpack_border_radius,
1314
                                          pack_border_radius);
1315 1316
  _gtk_css_shorthand_property_register   ("border-color",
                                          GDK_TYPE_RGBA,
1317
                                          border_color_subproperties,
1318
                                          parse_border_color,
1319
                                          unpack_to_everything,
1320
                                          pack_first_element);
1321 1322 1323 1324
  _gtk_css_shorthand_property_register   ("border-style",
                                          GTK_TYPE_BORDER_STYLE,
                                          border_style_subproperties,
                                          parse_border_style,
1325
                                          unpack_to_everything,
1326
                                          pack_first_element);
1327
  _gtk_css_shorthand_property_register   ("border-image",
1328
                                          G_TYPE_NONE,
1329
                                          border_image_subproperties,
1330
                                          parse_border_image,
1331 1332
                                          NULL,
                                          NULL);
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
  _gtk_css_shorthand_property_register   ("border-top",
                                          G_TYPE_NONE,
                                          border_top_subproperties,
                                          parse_border_side,
                                          NULL,
                                          NULL);
  _gtk_css_shorthand_property_register   ("border-right",
                                          G_TYPE_NONE,
                                          border_right_subproperties,
                                          parse_border_side,
                                          NULL,
                                          NULL);
  _gtk_css_shorthand_property_register   ("border-bottom",
                                          G_TYPE_NONE,
                                          border_bottom_subproperties,
                                          parse_border_side,
                                          NULL,
                                          NULL);
  _gtk_css_shorthand_property_register   ("border-left",
                                          G_TYPE_NONE,
                                          border_left_subproperties,
                                          parse_border_side,
                                          NULL,
                                          NULL);
1357 1358 1359 1360 1361 1362
  _gtk_css_shorthand_property_register   ("border",
                                          G_TYPE_NONE,
                                          border_subproperties,
                                          parse_border,
                                          NULL,
                                          NULL);
1363
  _gtk_css_shorthand_property_register   ("-gtk-outline-radius",
1364 1365 1366 1367 1368
                                          G_TYPE_INT,
                                          outline_radius_subproperties,
                                          parse_border_radius,
                                          unpack_border_radius,
                                          pack_border_radius);
1369
  _gtk_style_property_add_alias ("-gtk-outline-radius", "outline-radius");
1370 1371 1372 1373 1374 1375
  _gtk_css_shorthand_property_register   ("outline",
                                          G_TYPE_NONE,
                                          outline_subproperties,
                                          parse_border_side,
                                          NULL,
                                          NULL);
1376 1377 1378 1379 1380 1381
  _gtk_css_shorthand_property_register   ("background",
                                          G_TYPE_NONE,
                                          background_subproperties,
                                          parse_background,
                                          NULL,
                                          NULL);
1382 1383 1384 1385 1386 1387
  _gtk_css_shorthand_property_register   ("transition",
                                          G_TYPE_NONE,
                                          transition_subproperties,
                                          parse_transition,
                                          NULL,
                                          NULL);
1388 1389 1390 1391 1392 1393
  _gtk_css_shorthand_property_register   ("animation",
                                          G_TYPE_NONE,
                                          animation_subproperties,
                                          parse_animation,
                                          NULL,
                                          NULL);
1394 1395 1396 1397 1398 1399
  _gtk_css_shorthand_property_register   ("text-decoration",
                                          G_TYPE_NONE,
                                          text_decoration_subproperties,
                                          parse_text_decoration,
                                          NULL,
                                          NULL);
1400 1401 1402 1403 1404 1405 1406 1407 1408

  all_subproperties = get_all_subproperties ();
  _gtk_css_shorthand_property_register   ("all",
                                          G_TYPE_NONE,
                                          all_subproperties,
                                          parse_all,
                                          NULL,
                                          NULL);
  g_free (all_subproperties);
1409
}