cssanimatedstyle: Make advancing the style return a new style

This is another step towards making CssStyles immutable.
This commit is contained in:
Benjamin Otte 2014-12-16 04:15:25 +01:00
parent b53d5d0643
commit a3bf910585
3 changed files with 47 additions and 45 deletions

View File

@ -391,6 +391,22 @@ gtk_css_animated_style_create_css_animations (GSList *animation
/* PUBLIC API */ /* PUBLIC API */
static void
gtk_css_animated_style_apply_animations (GtkCssAnimatedStyle *style,
gint64 timestamp)
{
GSList *l;
for (l = style->animations; l; l = l->next)
{
GtkStyleAnimation *animation = l->data;
_gtk_style_animation_set_values (animation,
timestamp,
GTK_CSS_ANIMATED_STYLE (style));
}
}
GtkCssStyle * GtkCssStyle *
gtk_css_animated_style_new (GtkCssStyle *base_style, gtk_css_animated_style_new (GtkCssStyle *base_style,
GtkCssStyle *parent_style, GtkCssStyle *parent_style,
@ -424,58 +440,39 @@ gtk_css_animated_style_new (GtkCssStyle *base_style,
return GTK_CSS_STYLE (result); return GTK_CSS_STYLE (result);
} }
GtkBitmask * GtkCssStyle *
gtk_css_animated_style_advance (GtkCssAnimatedStyle *style, gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
gint64 timestamp) gint64 timestamp)
{ {
GtkBitmask *changed; GtkCssAnimatedStyle *result;
GPtrArray *old_computed_values; GSList *l, *animations;
GSList *list;
guint i;
gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL); gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (source), NULL);
gtk_internal_return_val_if_fail (timestamp >= style->current_time, NULL);
animations = NULL;
style->current_time = timestamp; for (l = source->animations; l; l = l->next)
old_computed_values = style->animated_values;
style->animated_values = NULL;
list = style->animations;
while (list)
{ {
GtkStyleAnimation *animation = list->data; GtkStyleAnimation *animation = l->data;
list = list->next;
_gtk_style_animation_set_values (animation,
timestamp,
GTK_CSS_ANIMATED_STYLE (style));
if (_gtk_style_animation_is_finished (animation, timestamp)) if (_gtk_style_animation_is_finished (animation, timestamp))
{ continue;
style->animations = g_slist_remove (style->animations, animation);
g_object_unref (animation); animations = g_slist_prepend (animations, g_object_ref (animation));
}
} }
animations = g_slist_reverse (animations);
/* figure out changes */ if (animations == NULL)
changed = _gtk_bitmask_new (); return g_object_ref (source->style);
for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++) result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL);
{
GtkCssValue *old_animated, *new_animated;
old_animated = old_computed_values && i < old_computed_values->len ? g_ptr_array_index (old_computed_values, i) : NULL; result->style = g_object_ref (source->style);
new_animated = style->animated_values && i < style->animated_values->len ? g_ptr_array_index (style->animated_values, i) : NULL; result->current_time = timestamp;
result->animations = animations;
if (!_gtk_css_value_equal0 (old_animated, new_animated)) gtk_css_animated_style_apply_animations (result, timestamp);
changed = _gtk_bitmask_set (changed, i, TRUE);
}
if (old_computed_values) return GTK_CSS_STYLE (result);
g_ptr_array_unref (old_computed_values);
return changed;
} }
gboolean gboolean

View File

@ -58,6 +58,8 @@ GtkCssStyle * gtk_css_animated_style_new (GtkCssStyle
GtkStyleProviderPrivate *provider, GtkStyleProviderPrivate *provider,
int scale, int scale,
GtkCssStyle *previous_style); GtkCssStyle *previous_style);
GtkCssStyle * gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source,
gint64 timestamp);
void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style, void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style,
guint id, guint id,
@ -66,8 +68,6 @@ void gtk_css_animated_style_set_animated_value(GtkCssAnimated
GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style, GtkCssValue * gtk_css_animated_style_get_intrinsic_value (GtkCssAnimatedStyle *style,
guint id); guint id);
GtkBitmask * gtk_css_animated_style_advance (GtkCssAnimatedStyle *style,
gint64 timestamp);
gboolean gtk_css_animated_style_is_static (GtkCssAnimatedStyle *style); gboolean gtk_css_animated_style_is_static (GtkCssAnimatedStyle *style);
G_END_DECLS G_END_DECLS

View File

@ -2873,14 +2873,19 @@ _gtk_style_context_validate (GtkStyleContext *context,
if (change & GTK_CSS_CHANGE_ANIMATE && if (change & GTK_CSS_CHANGE_ANIMATE &&
gtk_style_context_is_animating (context)) gtk_style_context_is_animating (context))
{ {
GtkCssStyle *new_values;
GtkBitmask *animation_changes; GtkBitmask *animation_changes;
animation_changes = gtk_css_animated_style_advance (GTK_CSS_ANIMATED_STYLE (info->values), timestamp); new_values = gtk_css_animated_style_new_advance (GTK_CSS_ANIMATED_STYLE (info->values), timestamp);
animation_changes = gtk_css_style_get_difference (new_values, info->values);
style_info_set_values (info, new_values);
g_object_unref (new_values);
changes = _gtk_bitmask_union (changes, animation_changes); changes = _gtk_bitmask_union (changes, animation_changes);
_gtk_bitmask_free (animation_changes); _gtk_bitmask_free (animation_changes);
if (gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (info->values))) if (!GTK_IS_CSS_ANIMATED_STYLE (info->values) ||
gtk_css_animated_style_is_static (GTK_CSS_ANIMATED_STYLE (info->values)))
_gtk_style_context_update_animating (context); _gtk_style_context_update_animating (context);
} }