Ejemplo n.º 1
0
cairo_pattern_t *
_gtk_gradient_resolve_full (GtkGradient             *gradient,
                            GtkStyleProviderPrivate *provider,
                            GtkCssComputedValues    *values,
                            GtkCssComputedValues    *parent_values,
                            GtkCssDependencies      *dependencies)
{
  cairo_pattern_t *pattern;
  guint i;

  g_return_val_if_fail (gradient != NULL, NULL);
  g_return_val_if_fail (GTK_IS_STYLE_PROVIDER (provider), NULL);
  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
  g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);
  g_return_val_if_fail (*dependencies == 0, NULL);

  if (gradient->radius0 == 0 && gradient->radius1 == 0)
    pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
                                           gradient->x1, gradient->y1);
  else
    pattern = cairo_pattern_create_radial (gradient->x0, gradient->y0,
                                           gradient->radius0,
                                           gradient->x1, gradient->y1,
                                           gradient->radius1);

  for (i = 0; i < gradient->stops->len; i++)
    {
      ColorStop *stop;
      GtkCssValue *val;
      GdkRGBA rgba;
      GtkCssDependencies stop_deps;

      stop = &g_array_index (gradient->stops, ColorStop, i);

      /* if color resolving fails, assume transparency */
      val = _gtk_css_color_value_resolve (_gtk_symbolic_color_get_css_value (stop->color),
                                          provider,
                                          _gtk_css_computed_values_get_value (values, GTK_CSS_PROPERTY_COLOR),
                                          GTK_CSS_DEPENDS_ON_COLOR,
                                          &stop_deps,
                                          NULL);
      if (val)
        {
          rgba = *_gtk_css_rgba_value_get_rgba (val);
          *dependencies = _gtk_css_dependencies_union (*dependencies, stop_deps);
          _gtk_css_value_unref (val);
        }
      else
        {
          rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
        }

      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
                                         rgba.red, rgba.green,
                                         rgba.blue, rgba.alpha);
    }

  return pattern;
}
Ejemplo n.º 2
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");
    }
}
Ejemplo n.º 3
0
GtkBitmask *
_gtk_css_computed_values_advance (GtkCssComputedValues *values,
                                  gint64                timestamp)
{
    GtkBitmask *changed;
    GPtrArray *old_computed_values;
    GSList *list;
    guint i;

    gtk_internal_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
    gtk_internal_return_val_if_fail (timestamp >= values->current_time, NULL);

    values->current_time = timestamp;
    old_computed_values = values->animated_values;
    values->animated_values = NULL;

    list = values->animations;
    while (list)
    {
        GtkStyleAnimation *animation = list->data;

        list = list->next;

        _gtk_style_animation_set_values (animation,
                                         timestamp,
                                         GTK_CSS_COMPUTED_VALUES (values));

        if (_gtk_style_animation_is_finished (animation, timestamp))
        {
            values->animations = g_slist_remove (values->animations, animation);
            g_object_unref (animation);
        }
    }

    /* figure out changes */
    changed = _gtk_bitmask_new ();

    for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++)
    {
        GtkCssValue *old_animated, *new_animated;

        old_animated = old_computed_values && i < old_computed_values->len ? g_ptr_array_index (old_computed_values, i) : NULL;
        new_animated = values->animated_values && i < values->animated_values->len ? g_ptr_array_index (values->animated_values, i) : NULL;

        if (!_gtk_css_value_equal0 (old_animated, new_animated))
            changed = _gtk_bitmask_set (changed, i, TRUE);
    }

    if (old_computed_values)
        g_ptr_array_unref (old_computed_values);

    return changed;
}
Ejemplo n.º 4
0
GtkCssSection *
_gtk_css_computed_values_get_section (GtkCssComputedValues *values,
                                      guint                 id)
{
    gtk_internal_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);

    if (values->sections == NULL ||
            id >= values->sections->len)
        return NULL;

    return g_ptr_array_index (values->sections, id);
}
Ejemplo n.º 5
0
GtkCssValue *
_gtk_css_computed_values_get_value (GtkCssComputedValues *values,
                                    guint                 id)
{
    gtk_internal_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);

    if (values->animated_values &&
            id < values->animated_values->len &&
            g_ptr_array_index (values->animated_values, id))
        return g_ptr_array_index (values->animated_values, id);

    return _gtk_css_computed_values_get_intrinsic_value (values, id);
}
Ejemplo n.º 6
0
void
_gtk_css_computed_values_compute_value (GtkCssComputedValues    *values,
                                        GtkStyleProviderPrivate *provider,
                                        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, values, parent_values, &dependencies);

    _gtk_css_computed_values_set_value (values, id, value, dependencies, section);

    _gtk_css_value_unref (value);
    _gtk_css_value_unref (specified);
}
Ejemplo n.º 7
0
char *
gtk_css_computed_values_to_string (GtkCssComputedValues *values)
{
  GString *string;

  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);

  string = g_string_new ("");

  gtk_css_computed_values_print (values, string);

  return g_string_free (string, FALSE);
}
Ejemplo n.º 8
0
void
_gtk_css_computed_values_cancel_animations (GtkCssComputedValues *values)
{
    gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));

    if (values->animated_values)
    {
        g_ptr_array_unref (values->animated_values);
        values->animated_values = NULL;
    }

    g_slist_free_full (values->animations, g_object_unref);
    values->animations = NULL;
}
Ejemplo n.º 9
0
GtkCssImage *
_gtk_css_image_compute (GtkCssImage             *image,
                        guint                    property_id,
                        GtkStyleProviderPrivate *provider,
			int                      scale,
                        GtkCssComputedValues    *values,
                        GtkCssComputedValues    *parent_values,
                        GtkCssDependencies      *dependencies)
{
  GtkCssDependencies unused;
  GtkCssImageClass *klass;

  g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
  g_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), NULL);
  g_return_val_if_fail (parent_values == NULL || GTK_IS_CSS_COMPUTED_VALUES (parent_values), NULL);

  if (dependencies == NULL)
    dependencies = &unused;
  *dependencies = 0;

  klass = GTK_CSS_IMAGE_GET_CLASS (image);

  return klass->compute (image, property_id, provider, scale, values, parent_values, dependencies);
}
Ejemplo n.º 10
0
gboolean
_gtk_css_computed_values_is_static (GtkCssComputedValues *values)
{
    GSList *list;

    gtk_internal_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), TRUE);

    for (list = values->animations; list; list = list->next)
    {
        if (!_gtk_style_animation_is_static (list->data, values->current_time))
            return FALSE;
    }

    return TRUE;
}
Ejemplo n.º 11
0
GtkBitmask *
_gtk_css_computed_values_compute_dependencies (GtkCssComputedValues *values,
        const GtkBitmask     *parent_changes)
{
    GtkBitmask *changes;

    gtk_internal_return_val_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values), _gtk_bitmask_new ());

    changes = _gtk_bitmask_copy (parent_changes);
    changes = _gtk_bitmask_intersect (changes, values->depends_on_parent);
    if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_COLOR))
        changes = _gtk_bitmask_union (changes, values->depends_on_color);
    if (_gtk_bitmask_get (changes, GTK_CSS_PROPERTY_FONT_SIZE))
        changes = _gtk_bitmask_union (changes, values->depends_on_font_size);

    return changes;
}
Ejemplo n.º 12
0
void
_gtk_css_computed_values_set_animated_value (GtkCssComputedValues *values,
        guint                 id,
        GtkCssValue          *value)
{
    gtk_internal_return_if_fail (GTK_IS_CSS_COMPUTED_VALUES (values));
    gtk_internal_return_if_fail (value != NULL);

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

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

}
Ejemplo n.º 13
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);
    }
}
Ejemplo n.º 14
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);
}