Exemple #1
0
void
gtk_css_computed_values_print (GtkCssComputedValues *values,
                               GString              *string)
{
  guint i;

  g_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
  g_return_if_fail (string != NULL);

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssSection *section = _gtk_css_computed_values_get_section (values, i);
      g_string_append (string, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i))));
      g_string_append (string, ": ");
      _gtk_css_value_print (_gtk_css_computed_values_get_value (values, i), string);
      g_string_append (string, ";");
      if (section)
        {
          g_string_append (string, " /* ");
          _gtk_css_section_print (section, string);
          g_string_append (string, " */");
        }
      g_string_append (string, "\n");
    }
}
Exemple #2
0
void
gtk_css_style_print (GtkCssStyle *style,
                     GString     *string)
{
  guint i;

  g_return_if_fail (GTK_IS_CSS_STYLE (style));
  g_return_if_fail (string != NULL);

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssSection *section = gtk_css_style_get_section (style, i);
      g_string_append (string, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (i))));
      g_string_append (string, ": ");
      _gtk_css_value_print (gtk_css_style_get_value (style, i), string);
      g_string_append (string, ";");
      if (section)
        {
          g_string_append (string, " /* ");
          _gtk_css_section_print (section, string);
          g_string_append (string, " */");
        }
      g_string_append (string, "\n");
    }
}
Exemple #3
0
/**
 * _gtk_css_lookup_resolve:
 * @lookup: the lookup
 * @context: the context the values are resolved for
 * @values: a new #GtkCssStyle to be filled with the new properties
 *
 * Resolves the current lookup into a styleproperties object. This is done
 * by converting from the “winning declaration” to the “computed value”.
 *
 * XXX: This bypasses the notion of “specified value”. If this ever becomes
 * an issue, go fix it.
 **/
void
_gtk_css_lookup_resolve (GtkCssLookup            *lookup,
                         GtkStyleProviderPrivate *provider,
                         GtkCssStaticStyle       *style,
                         GtkCssStyle             *parent_style)
{
  guint i, n;

  gtk_internal_return_if_fail (lookup != NULL);
  gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
  gtk_internal_return_if_fail (GTK_IS_CSS_STATIC_STYLE (style));
  gtk_internal_return_if_fail (parent_style == NULL || GTK_IS_CSS_STYLE (parent_style));

  n = _gtk_css_style_property_get_n_properties ();

  for (i = 0; i < n; i++)
    {
      if (lookup->values[i].value ||
          _gtk_bitmask_get (lookup->missing, i))
        gtk_css_static_style_compute_value (GTK_CSS_STATIC_STYLE (style),
                                            provider,
                                            parent_style,
                                            i,
                                            lookup->values[i].value,
                                            lookup->values[i].section);
      /* else not a relevant property */
    }
}
Exemple #4
0
static void
transition_info_add (TransitionInfo    infos[GTK_CSS_PROPERTY_N_PROPERTIES],
                     GtkStyleProperty *property,
                     guint             index)
{
    if (property == NULL)
    {
        guint i;

        for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
        {
            GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (i);

            transition_info_add (infos, GTK_STYLE_PROPERTY (prop), index);
        }
    }
    else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
    {
        GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
        guint i;

        for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
        {
            GtkCssStyleProperty *prop = _gtk_css_shorthand_property_get_subproperty (shorthand, i);

            transition_info_add (infos, GTK_STYLE_PROPERTY (prop), index);
        }
    }
    else if (GTK_IS_CSS_STYLE_PROPERTY (property))
    {
        guint id;

        if (!_gtk_css_style_property_is_animated (GTK_CSS_STYLE_PROPERTY (property)))
            return;

        id = _gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (property));
        g_assert (id < GTK_CSS_PROPERTY_N_PROPERTIES);
        infos[id].index = index;
        infos[id].pending = TRUE;
    }
    else
    {
        g_assert_not_reached ();
    }
}
Exemple #5
0
/*
 * gtk_css_style_print:
 * @style: a #GtkCssStyle
 * @string: the #GString to print to
 * @indent: level of indentation to use
 * @skip_initial: %TRUE to skip properties that have their initial value
 *
 * Print the @style to @string, in CSS format. Every property is printed
 * on a line by itself, indented by @indent spaces. If @skip_initial is
 * %TRUE, properties are only printed if their value in @style is different
 * from the initial value of the property.
 *
 * Returns: %TRUE is any properties have been printed
 */
gboolean
gtk_css_style_print (GtkCssStyle *style,
                     GString     *string,
                     guint        indent,
                     gboolean     skip_initial)
{
    guint i;
    gboolean retval = FALSE;

    g_return_val_if_fail (GTK_IS_CSS_STYLE (style), FALSE);
    g_return_val_if_fail (string != NULL, FALSE);

    for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
        GtkCssSection *section;
        GtkCssStyleProperty *prop;
        GtkCssValue *value;
        const char *name;

        section = gtk_css_style_get_section (style, i);
        if (!section && skip_initial)
            continue;

        prop = _gtk_css_style_property_lookup_by_id (i);
        name = _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop));
        value = gtk_css_style_get_value (style, i);

        g_string_append_printf (string, "%*s%s: ", indent, "", name);
        _gtk_css_value_print (value, string);
        g_string_append_c (string, ';');

        if (section)
        {
            g_string_append (string, " /* ");
            _gtk_css_section_print (section, string);
            g_string_append (string, " */");
        }

        g_string_append_c (string, '\n');

        retval = TRUE;
    }

    return retval;
}
Exemple #6
0
/**
 * _gtk_css_style_property_get_mask_affecting:
 * @flags: the flags that are affected
 *
 * Computes a bitmask for all properties that have at least one of @flags
 * set.
 *
 * Returns: (transfer full): A #GtkBitmask with the bit set for every
 *          property that has at least one of @flags set.
 */
GtkBitmask *
_gtk_css_style_property_get_mask_affecting (GtkCssAffects affects)
{
  GtkBitmask *result;
  guint i;

  result = _gtk_bitmask_new ();

  for (i = 0; i < _gtk_css_style_property_get_n_properties (); i++)
    {
      GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (i);

      if (_gtk_css_style_property_get_affects (prop) & affects)
        result = _gtk_bitmask_set (result, i, TRUE);
    }

  return result;
}
Exemple #7
0
void
_gtk_css_computed_values_set_value (GtkCssComputedValues *values,
                                    guint                 id,
                                    GtkCssValue          *value,
                                    GtkCssDependencies    dependencies,
                                    GtkCssSection        *section)
{
    gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));

    if (values->values == NULL)
        values->values = g_ptr_array_new_full (_gtk_css_style_property_get_n_properties (),
                                               (GDestroyNotify)_gtk_css_value_unref);
    if (id >= values->values->len)
        g_ptr_array_set_size (values->values, id + 1);

    if (g_ptr_array_index (values->values, id))
        _gtk_css_value_unref (g_ptr_array_index (values->values, id));
    g_ptr_array_index (values->values, id) = _gtk_css_value_ref (value);

    if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT))
        values->depends_on_parent = _gtk_bitmask_set (values->depends_on_parent, id, TRUE);
    if (dependencies & (GTK_CSS_EQUALS_PARENT))
        values->equals_parent = _gtk_bitmask_set (values->equals_parent, id, TRUE);
    if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR))
        values->depends_on_color = _gtk_bitmask_set (values->depends_on_color, id, TRUE);
    if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE))
        values->depends_on_font_size = _gtk_bitmask_set (values->depends_on_font_size, id, TRUE);

    if (values->sections && values->sections->len > id && g_ptr_array_index (values->sections, id))
    {
        gtk_css_section_unref (g_ptr_array_index (values->sections, id));
        g_ptr_array_index (values->sections, id) = NULL;
    }

    if (section)
    {
        if (values->sections == NULL)
            values->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
        if (values->sections->len <= id)
            g_ptr_array_set_size (values->sections, id + 1);

        g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
    }
}
Exemple #8
0
static void
gtk_css_path_node_invalidate (GtkCssNode *node)
{
  GtkCssPathNode *path_node = GTK_CSS_PATH_NODE (node);

  if (path_node->context)
    {
      GtkBitmask *changes;

      changes = _gtk_bitmask_new ();
      changes = _gtk_bitmask_invert_range (changes,
                                           0,
                                           _gtk_css_style_property_get_n_properties ());

      gtk_style_context_validate (path_node->context, changes);

      _gtk_bitmask_free (changes);
    }
}
Exemple #9
0
GtkCssLookup *
_gtk_css_lookup_new (const GtkBitmask *relevant)
{
  GtkCssLookup *lookup;
  guint n = _gtk_css_style_property_get_n_properties ();

  lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);

  if (relevant)
    {
      lookup->missing = _gtk_bitmask_copy (relevant);
    }
  else
    {
      lookup->missing = _gtk_bitmask_new ();
      lookup->missing = _gtk_bitmask_invert_range (lookup->missing, 0, n);
    }

  return lookup;
}
Exemple #10
0
GtkBitmask *
gtk_css_style_get_difference (GtkCssStyle *style,
                              GtkCssStyle *other)
{
  GtkBitmask *result;
  guint i, len;

  if (style == other)
    return _gtk_bitmask_new ();

  result = _gtk_bitmask_new ();
  len = _gtk_css_style_property_get_n_properties ();
  for (i = 0; i < len; i++)
    {
      if (!_gtk_css_value_equal (gtk_css_style_get_value (style, i),
                                 gtk_css_style_get_value (other, i)))
        result = _gtk_bitmask_set (result, i, TRUE);
    }

  return result;
}
Exemple #11
0
GtkBitmask *
gtk_css_style_add_difference (GtkBitmask  *accumulated,
                              GtkCssStyle *style,
                              GtkCssStyle *other)
{
    gint len, i;

    if (style == other)
        return accumulated;

    len = _gtk_css_style_property_get_n_properties ();
    for (i = 0; i < len; i++)
    {
        if (_gtk_bitmask_get (accumulated, i))
            continue;

        if (!_gtk_css_value_equal (gtk_css_style_get_value (style, i),
                                   gtk_css_style_get_value (other, i)))
            accumulated = _gtk_bitmask_set (accumulated, i, TRUE);
    }

    return accumulated;
}
Exemple #12
0
void
_gtk_css_computed_values_compute_value (GtkCssComputedValues    *values,
                                        GtkStyleProviderPrivate *provider,
					int                      scale,
                                        GtkCssComputedValues    *parent_values,
                                        guint                    id,
                                        GtkCssValue             *specified,
                                        GtkCssSection           *section)
{
  GtkCssDependencies dependencies;
  GtkCssValue *value;

  gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
  gtk_internal_return_if_fail (GTK_IS_STYLE_PROVIDER_PRIVATE (provider));
  gtk_internal_return_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values));

  /* http://www.w3.org/TR/css3-cascade/#cascade
   * Then, for every element, the value for each property can be found
   * by following this pseudo-algorithm:
   * 1) Identify all declarations that apply to the element
   */
  if (specified == NULL)
    {
      GtkCssStyleProperty *prop = _gtk_css_style_property_lookup_by_id (id);

      if (_gtk_css_style_property_is_inherit (prop))
        specified = _gtk_css_inherit_value_new ();
      else
        specified = _gtk_css_initial_value_new ();
    }
  else
    _gtk_css_value_ref (specified);

  value = _gtk_css_value_compute (specified, id, provider, scale, values, parent_values, &dependencies);

  if (values->values == NULL)
    values->values = g_ptr_array_new_full (_gtk_css_style_property_get_n_properties (),
					   (GDestroyNotify)_gtk_css_value_unref);
  if (id >= values->values->len)
   g_ptr_array_set_size (values->values, id + 1);

  if (g_ptr_array_index (values->values, id))
    _gtk_css_value_unref (g_ptr_array_index (values->values, id));
  g_ptr_array_index (values->values, id) = _gtk_css_value_ref (value);

  if (dependencies & (GTK_CSS_DEPENDS_ON_PARENT | GTK_CSS_EQUALS_PARENT))
    values->depends_on_parent = _gtk_bitmask_set (values->depends_on_parent, id, TRUE);
  if (dependencies & (GTK_CSS_EQUALS_PARENT))
    values->equals_parent = _gtk_bitmask_set (values->equals_parent, id, TRUE);
  if (dependencies & (GTK_CSS_DEPENDS_ON_COLOR))
    values->depends_on_color = _gtk_bitmask_set (values->depends_on_color, id, TRUE);
  if (dependencies & (GTK_CSS_DEPENDS_ON_FONT_SIZE))
    values->depends_on_font_size = _gtk_bitmask_set (values->depends_on_font_size, id, TRUE);

  if (values->sections && values->sections->len > id && g_ptr_array_index (values->sections, id))
    {
      gtk_css_section_unref (g_ptr_array_index (values->sections, id));
      g_ptr_array_index (values->sections, id) = NULL;
    }

  if (section)
    {
      if (values->sections == NULL)
        values->sections = g_ptr_array_new_with_free_func (maybe_unref_section);
      if (values->sections->len <= id)
        g_ptr_array_set_size (values->sections, id + 1);

      g_ptr_array_index (values->sections, id) = gtk_css_section_ref (section);
    }

  _gtk_css_value_unref (value);
  _gtk_css_value_unref (specified);
}