예제 #1
0
static GtkCssValue *
gtk_css_style_property_parse_value (GtkStyleProperty *property,
                                    GtkCssParser     *parser)
{
  GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);

  if (_gtk_css_parser_try (parser, "initial", TRUE))
    {
      /* the initial value can be explicitly specified with the
       * ‘initial’ keyword which all properties accept.
       */
      return _gtk_css_initial_value_new ();
    }
  else if (_gtk_css_parser_try (parser, "inherit", TRUE))
    {
      /* All properties accept the ‘inherit’ value which
       * explicitly specifies that the value will be determined
       * by inheritance. The ‘inherit’ value can be used to
       * strengthen inherited values in the cascade, and it can
       * also be used on properties that are not normally inherited.
       */
      return _gtk_css_inherit_value_new ();
    }
  else if (_gtk_css_parser_try (parser, "unset", TRUE))
    {
      /* If the cascaded value of a property is the unset keyword,
       * then if it is an inherited property, this is treated as
       * inherit, and if it is not, this is treated as initial.
       */
      return _gtk_css_unset_value_new ();
    }

  return (* style_property->parse_value) (style_property, parser);
}
예제 #2
0
static GtkCssValue *
gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
                                        GtkCssParser     *parser)
{
  GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
  GtkCssValue **data;
  GtkCssValue *result;
  guint i;

  data = g_new0 (GtkCssValue *, shorthand->subproperties->len);

  if (_gtk_css_parser_try (parser, "initial", TRUE))
    {
      /* the initial value can be explicitly specified with the
       * ‘initial’ keyword which all properties accept.
       */
      for (i = 0; i < shorthand->subproperties->len; i++)
        {
          data[i] = _gtk_css_initial_value_new ();
        }
    }
  else if (_gtk_css_parser_try (parser, "inherit", TRUE))
    {
      /* All properties accept the ‘inherit’ value which
       * explicitly specifies that the value will be determined
       * by inheritance. The ‘inherit’ value can be used to
       * strengthen inherited values in the cascade, and it can
       * also be used on properties that are not normally inherited.
       */
      for (i = 0; i < shorthand->subproperties->len; i++)
        {
          data[i] = _gtk_css_inherit_value_new ();
        }
    }
  else if (_gtk_css_parser_try (parser, "unset", TRUE))
    {
      /* If the cascaded value of a property is the unset keyword,
       * then if it is an inherited property, this is treated as
       * inherit, and if it is not, this is treated as initial.
       */
      for (i = 0; i < shorthand->subproperties->len; i++)
        {
          data[i] = _gtk_css_unset_value_new ();
        }
    }
  else if (!shorthand->parse (shorthand, data, parser))
    {
      for (i = 0; i < shorthand->subproperties->len; i++)
        {
          if (data[i] != NULL)
            _gtk_css_value_unref (data[i]);
        }
      g_free (data);
      return NULL;
    }

  /* All values that aren't set by the parse func are set to their
   * default values here.
   * XXX: Is the default always initial or can it be inherit? */
  for (i = 0; i < shorthand->subproperties->len; i++)
    {
      if (data[i] == NULL)
        data[i] = _gtk_css_initial_value_new ();
    }

  result = _gtk_css_array_value_new_from_array (data, shorthand->subproperties->len);
  g_free (data);
  
  return result;
}