From a3bf9105853f553943770501ae2ad13713502a54 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 16 Dec 2014 04:15:25 +0100 Subject: [PATCH] cssanimatedstyle: Make advancing the style return a new style This is another step towards making CssStyles immutable. --- gtk/gtkcssanimatedstyle.c | 79 +++++++++++++++----------------- gtk/gtkcssanimatedstyleprivate.h | 4 +- gtk/gtkstylecontext.c | 9 +++- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c index c36cfe37cc..efdbe12f95 100644 --- a/gtk/gtkcssanimatedstyle.c +++ b/gtk/gtkcssanimatedstyle.c @@ -391,6 +391,22 @@ gtk_css_animated_style_create_css_animations (GSList *animation /* 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 * gtk_css_animated_style_new (GtkCssStyle *base_style, GtkCssStyle *parent_style, @@ -424,58 +440,39 @@ gtk_css_animated_style_new (GtkCssStyle *base_style, return GTK_CSS_STYLE (result); } -GtkBitmask * -gtk_css_animated_style_advance (GtkCssAnimatedStyle *style, - gint64 timestamp) +GtkCssStyle * +gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source, + gint64 timestamp) { - GtkBitmask *changed; - GPtrArray *old_computed_values; - GSList *list; - guint i; + GtkCssAnimatedStyle *result; + GSList *l, *animations; - gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (style), NULL); - gtk_internal_return_val_if_fail (timestamp >= style->current_time, NULL); - - style->current_time = timestamp; - old_computed_values = style->animated_values; - style->animated_values = NULL; - - list = style->animations; - while (list) + gtk_internal_return_val_if_fail (GTK_IS_CSS_ANIMATED_STYLE (source), NULL); + + animations = NULL; + for (l = source->animations; l; l = l->next) { - GtkStyleAnimation *animation = list->data; - - list = list->next; - - _gtk_style_animation_set_values (animation, - timestamp, - GTK_CSS_ANIMATED_STYLE (style)); + GtkStyleAnimation *animation = l->data; if (_gtk_style_animation_is_finished (animation, timestamp)) - { - style->animations = g_slist_remove (style->animations, animation); - g_object_unref (animation); - } + continue; + + animations = g_slist_prepend (animations, g_object_ref (animation)); } + animations = g_slist_reverse (animations); - /* figure out changes */ - changed = _gtk_bitmask_new (); + if (animations == NULL) + return g_object_ref (source->style); - for (i = 0; i < GTK_CSS_PROPERTY_N_PROPERTIES; i++) - { - GtkCssValue *old_animated, *new_animated; + result = g_object_new (GTK_TYPE_CSS_ANIMATED_STYLE, NULL); - old_animated = old_computed_values && i < old_computed_values->len ? g_ptr_array_index (old_computed_values, i) : NULL; - new_animated = style->animated_values && i < style->animated_values->len ? g_ptr_array_index (style->animated_values, i) : NULL; + result->style = g_object_ref (source->style); + result->current_time = timestamp; + result->animations = animations; - if (!_gtk_css_value_equal0 (old_animated, new_animated)) - changed = _gtk_bitmask_set (changed, i, TRUE); - } + gtk_css_animated_style_apply_animations (result, timestamp); - if (old_computed_values) - g_ptr_array_unref (old_computed_values); - - return changed; + return GTK_CSS_STYLE (result); } gboolean diff --git a/gtk/gtkcssanimatedstyleprivate.h b/gtk/gtkcssanimatedstyleprivate.h index c61ebe8026..3bd49d7b6a 100644 --- a/gtk/gtkcssanimatedstyleprivate.h +++ b/gtk/gtkcssanimatedstyleprivate.h @@ -58,6 +58,8 @@ GtkCssStyle * gtk_css_animated_style_new (GtkCssStyle GtkStyleProviderPrivate *provider, int scale, GtkCssStyle *previous_style); +GtkCssStyle * gtk_css_animated_style_new_advance (GtkCssAnimatedStyle *source, + gint64 timestamp); void gtk_css_animated_style_set_animated_value(GtkCssAnimatedStyle *style, 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, guint id); -GtkBitmask * gtk_css_animated_style_advance (GtkCssAnimatedStyle *style, - gint64 timestamp); gboolean gtk_css_animated_style_is_static (GtkCssAnimatedStyle *style); G_END_DECLS diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c index 14aaecacfc..fb227d4b09 100644 --- a/gtk/gtkstylecontext.c +++ b/gtk/gtkstylecontext.c @@ -2873,14 +2873,19 @@ _gtk_style_context_validate (GtkStyleContext *context, if (change & GTK_CSS_CHANGE_ANIMATE && gtk_style_context_is_animating (context)) { + GtkCssStyle *new_values; 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); _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); }